Skip to content

Commit

Permalink
[feature] added vcstat_version tag to internal_vcstat metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tesifonte Belda committed May 19, 2023
1 parent f6f5684 commit fe1bc4d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
- internal_vcstat
- tags:
- vcenter
- vcstat_version
- fields:
- sessions_created (int)
- gather_time_ns (int)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ vcstat_net_dvs,dcname=MyDC,dvs=DSwitch-E1,moid=dvs-e1,vcenter=vcenter.local num_
vcstat_net_dvp,dcname=MyDC,dvp=DSwitch-E1-DVUplinks-e1,moid=dvportgroup-e1,uplink=true,vcenter=vcenter.local status="green",status_code=0i,num_ports=16i 1653060682000000000
vcstat_datastore,dcname=MyDC,dsname=DS_Departement1,moid=datastore-725,type=VMFS,vcenter=vcenter.local accessible=true,capacity=2198754820096i,freespace=730054262784i,uncommitted=20511i,maintenance_mode="normal"
vcstat_vm,clustername=MyCluster-01,dcname=MyDC,esxhostname=myesxi01.local,moid=vm-4524,vcenter.local,vmname=vmserver01 status="green",status_code=0i,consolidation_needed=false,max_cpu_usage=11972i,num_eth_cards=1i,num_vdisks=2i,connection_state_code=0i,max_mem_usage=8589934592i,num_vcpus=4i,power_state_code=0i,template=false,connection_state="connected",memory_size=8589934592i,power_state="poweredOn" 1653060683000000000
internal_vcstat,vcenter=vcenter.local sessions_created=1i,gather_time_ns=1764839000i,notresponding_esxcli_hosts=0i 1653060683000000000
internal_vcstat,vcenter=vcenter.local,vcstat_version=0.1.10 sessions_created=1i,gather_time_ns=1764839000i,notresponding_esxcli_hosts=0i 1653060683000000000
```

# Metrics
Expand Down
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func main() {
os.Exit(1)
}

// Tell vcstat shim the configured polling interval
// Set vcstat shim with the configured polling interval and version
vcCfg, ok := shim.Input.(*vcstat.VCstatConfig)
if !ok {
fmt.Fprintf(os.Stderr, "Error getting shim input as VCstatConfig\n")
Expand All @@ -63,6 +63,8 @@ func main() {
fmt.Fprintf(os.Stderr, "Error setting vcstat shim polling interval: %s\n", err)
os.Exit(1)
}
vcCfg.SetVersion(Version)
vcCfg.StartSelfMetrics()

// run a single plugin until stdin closes or we receive a termination signal
if err = shim.Run(*pollInterval); err != nil {
Expand Down
32 changes: 23 additions & 9 deletions plugins/inputs/vcstat/vcstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type VCstatConfig struct {
NetDVPInstances bool `toml:"net_dvp_instances"`
VMInstances bool `toml:"vm_instances"`

version string
pollInterval time.Duration
ctx context.Context
cancel context.CancelFunc
Expand Down Expand Up @@ -188,18 +189,10 @@ func (vcs *VCstatConfig) Init() error {
return fmt.Errorf("Error parsing VMs filters: %w", err)
}

// selfmonitoring
u, err := url.Parse(vcs.VCenter)
_, err = url.Parse(vcs.VCenter)
if err != nil {
return fmt.Errorf("Error parsing URL for vcenter: %w", err)
}
tags := map[string]string{
"alias": vcs.InternalAlias,
"vcenter": u.Hostname(),
}
vcs.GatherTime = selfstat.Register("vcstat", "gather_time_ns", tags)
vcs.NotRespondingHosts = selfstat.Register("vcstat", "notresponding_esxcli_hosts", tags)
vcs.SessionsCreated = selfstat.Register("vcstat", "sessions_created", tags)

return err
}
Expand All @@ -222,6 +215,27 @@ func (vcs *VCstatConfig) SetPollInterval(pollInterval time.Duration) error {
return nil
}

// SetVersion let telegraf shim know this version
func (vcs *VCstatConfig) SetVersion(version string) {
vcs.version = version
}

// StartSelfMetrics initialices selfmonitoring
func (vcs *VCstatConfig) StartSelfMetrics() {
u, err := url.Parse(vcs.VCenter)
if err != nil {
return
}
tags := map[string]string{
"alias": vcs.InternalAlias,
"vcenter": u.Hostname(),
"vcstat_version": vcs.version,
}
vcs.GatherTime = selfstat.Register("vcstat", "gather_time_ns", tags)
vcs.NotRespondingHosts = selfstat.Register("vcstat", "notresponding_esxcli_hosts", tags)
vcs.SessionsCreated = selfstat.Register("vcstat", "sessions_created", tags)
}

// SampleConfig returns a set of default configuration to be used as a boilerplate when setting up
// Telegraf.
func (vcs *VCstatConfig) SampleConfig() string {
Expand Down

0 comments on commit fe1bc4d

Please sign in to comment.