From fe1bc4d7fda7e27dc16bee7370a2b436971fba6d Mon Sep 17 00:00:00 2001 From: Tesifonte Belda Date: Fri, 19 May 2023 17:23:17 +0200 Subject: [PATCH] [feature] added vcstat_version tag to internal_vcstat metrics --- METRICS.md | 1 + README.md | 2 +- cmd/main.go | 4 +++- plugins/inputs/vcstat/vcstat.go | 32 +++++++++++++++++++++++--------- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/METRICS.md b/METRICS.md index 28365bd..9a09f5f 100644 --- a/METRICS.md +++ b/METRICS.md @@ -190,6 +190,7 @@ - internal_vcstat - tags: - vcenter + - vcstat_version - fields: - sessions_created (int) - gather_time_ns (int) diff --git a/README.md b/README.md index f7bb3e8..fc50534 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/main.go b/cmd/main.go index 48063ed..43e082b 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -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") @@ -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 { diff --git a/plugins/inputs/vcstat/vcstat.go b/plugins/inputs/vcstat/vcstat.go index 13d6845..113a358 100644 --- a/plugins/inputs/vcstat/vcstat.go +++ b/plugins/inputs/vcstat/vcstat.go @@ -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 @@ -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 } @@ -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 {