Skip to content

Commit

Permalink
[feature] Add VM filtering configuration parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Tesifonte Belda committed Feb 6, 2023
1 parent 2188a97 commit c76f5f9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 13 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ Use telegraf v1.14 or above so that execd input is available.
## Use SSL but skip chain & host verification
# insecure_skip_verify = false

## Filter clusters by name, default is no filtering.
## cluster names can be specified as glob patterns.
## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []

## Filter hosts by name, default is no filtering.
## host names can be specified as glob patterns.
## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []

## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []

#### you may enable or disable data collection per instance type ####
## collect cluster measurement (vcstat_cluster)
# cluster_instances = true
Expand Down
13 changes: 9 additions & 4 deletions etc/vcstat.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,21 @@
## Use SSL but skip chain & host verification
# insecure_skip_verify = false

## Filter clusters by name, default is no filtering.
## cluster names can be specified as glob patterns.
## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []

## Filter hosts by name, default is no filtering.
## host names can be specified as glob patterns.
## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []

## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []

#### you may enable or disable data collection per instance type ####
## collect cluster measurement (vcstat_cluster)
# cluster_instances = true
Expand Down
15 changes: 15 additions & 0 deletions internal/vccollector/vccollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type VcCollector struct {
coll *property.Collector
filterClusters filter.Filter
filterHosts filter.Filter
filterVms filter.Filter
dataDuration time.Duration
skipNotRespondigFor time.Duration
queryBulkSize int
Expand All @@ -58,6 +59,9 @@ func New(
if err = vcc.SetFilterHosts(nil, nil); err != nil {
return nil, err
}
if err = vcc.SetFilterVms(nil, nil); err != nil {
return nil, err
}
vcc.TLSCA = clicfg.TLSCA
vcc.InsecureSkipVerify = clicfg.InsecureSkipVerify

Expand Down Expand Up @@ -96,6 +100,17 @@ func (c *VcCollector) SetFilterHosts(include []string, exclude []string) error {
return nil
}

// SetFilterVms sets VMs include and exclude filters
func (c *VcCollector) SetFilterVms(include []string, exclude []string) error {
var err error

c.filterVms, err = filter.NewIncludeExcludeFilter(include, exclude)
if err != nil {
return err
}
return nil
}

// SetQueryChunkSize sets chunk size of slice to use in sSphere property queries
func (c *VcCollector) SetQueryChunkSize(b int) {
c.queryBulkSize = b
Expand Down
3 changes: 3 additions & 0 deletions internal/vccollector/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (c *VcCollector) CollectVmsInfo(
for i, dc := range c.dcs {
// get VM references and split the list into chunks
for _, vm := range c.vms[i] {
if !c.filterVms.Match(vm.Name()) {
continue
}
arefs = append(arefs, vm.Reference())
}
chunks := chunckMoRefSlice(arefs, c.queryBulkSize)
Expand Down
21 changes: 16 additions & 5 deletions plugins/inputs/vcstat/vcstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type VCstatConfig struct {
ClustersInclude []string `toml:"clusters_include"`
HostsExclude []string `toml:"hosts_exclude"`
HostsInclude []string `toml:"hosts_include"`
VmsExclude []string `toml:"vms_exclude"`
VmsInclude []string `toml:"vms_include"`

ClusterInstances bool `toml:"cluster_instances"`
DatastoreInstances bool `toml:"datastore_instances"`
Expand Down Expand Up @@ -76,16 +78,21 @@ var sampleConfig = `
## Use SSL but skip chain & host verification
# insecure_skip_verify = false
## Filter clusters by name, default is no filtering.
## cluster names can be specified as glob patterns.
## Filter clusters by name, default is no filtering
## cluster names can be specified as glob patterns
# clusters_include = []
# clusters_exclude = []
## Filter hosts by name, default is no filtering.
## host names can be specified as glob patterns.
## Filter hosts by name, default is no filtering
## host names can be specified as glob patterns
# hosts_include = []
# hosts_exclude = []
## Filter VMs by name, default is no filtering
## VM names can be specified as glob patterns
# vms_include = []
# vms_exclude = []
#### you may enable or disable data collection per instance type ####
## collect cluster measurement (vcstat_cluster)
# cluster_instances = true
Expand Down Expand Up @@ -164,14 +171,18 @@ func (vcs *VCstatConfig) Init() error {
time.Duration(vcs.pollInterval.Seconds() * float64(vcs.IntSkipNotRespondig)),
)
vcs.vcc.SetQueryChunkSize(vcs.QueryBulkSize)
err = vcs.vcc.SetFilterClusters(vcs.ClustersInclude, vcs.ClustersExclude);
err = vcs.vcc.SetFilterClusters(vcs.ClustersInclude, vcs.ClustersExclude)
if err != nil {
return fmt.Errorf("Error parsing clusters filters: %w", err)
}
err = vcs.vcc.SetFilterHosts(vcs.HostsInclude, vcs.HostsExclude)
if err != nil {
return fmt.Errorf("Error parsing hosts filters: %w", err)
}
err = vcs.vcc.SetFilterVms(vcs.VmsInclude, vcs.VmsExclude)
if err != nil {
return fmt.Errorf("Error parsing VMs filters: %w", err)
}

// selfmonitoring
u, err := url.Parse(vcs.VCenter)
Expand Down

0 comments on commit c76f5f9

Please sign in to comment.