Skip to content

Commit

Permalink
[enhancement]: add number of VMs field to cluster measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
Tesifonte Belda committed Aug 30, 2022
1 parent f655cc7 commit 89264de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions METRICS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- num_effective_hosts (int)
- num_cpu_cores (int)
- num_cpu_threads (int)
- num_vms (int)
- total_cpu (int) in MHz
- total_memory (int) in bytes
- effective_cpu (int) in MHz
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ Metric timestamp precision will be set according to the polling interval, so it

```plain
vcstat_vcenter,vcenter=vcenter.local name="VMware vCenter Server",num_datacenters=1i,ostype="linux-x64",version="6.5.0" 1653060681000000000
vcstat_datacenter,dcname=MyDC,moid=datacenter-2,vcenter=vcenter.local num_catastores=51i,num_hosts=8i,num_networks=32i,num_clusters=1i 1653060681000000000
vcstat_cluster,clustername=MyCluster-01,dcname=MyDC,moid=domain-c121,vcenter=vcenter.local num_cpu_cores=152i,total_cpu=342248i,total_memory=1648683421696i,effective_cpu=299032i,status="green",status_code=0i,num_hosts=8i,num_effective_hosts=8i,num_cpu_threads=304i,effective_memory=1502236i 1653060681000000000
vcstat_datacenter,dcname=MyDC,moid=datacenter-2,vcenter=vcenter.local num_datastores=51i,num_hosts=8i,num_networks=32i,num_clusters=1i 1653060681000000000
vcstat_cluster,clustername=MyCluster-01,dcname=MyDC,moid=domain-c121,vcenter=vcenter.local num_cpu_cores=152i,total_cpu=342248i,total_memory=1648683421696i,effective_cpu=299032i,status="green",status_code=0i,num_vms=26i,num_hosts=8i,num_effective_hosts=8i,num_cpu_threads=304i,effective_memory=1502236i 1653060681000000000
vcstat_host,dcname=MyDC,clustername=MyCluster-01,esxhostname=myesxi01.local,moid=host-706,vcenter=vcenter.local connection_state_code=0i,memory_size=206110695424i,num_cpus=16i,cpu_freq=2199i,status="green",status_code=0i,reboot_required=false,in_maintenance_mode=false,connection_state="connected" 1653060681000000000
vcstat_host_firewall,dcname=MyDC,clustername=MyCluster-01,esxhostname=myesxi01.local,vcenter=vcenter.local defaultaction="DROP",enabled=true,loaded=true 1653060681000000000
vcstat_host_hba,dcname=MyDC,clustername=MyCluster-01,device=vmhba0,driver=lpfc,esxhostname=myesxi01.local,vcenter=vcenter.local status="link-n/a",status_code=1i 1653060681000000000
Expand Down
34 changes: 22 additions & 12 deletions pkg/vccollector/vccollector_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ func (c *VcCollector) CollectClusterInfo(
acc telegraf.Accumulator,
) error {
var (
clusters []*object.ClusterComputeResource
clMo mo.ClusterComputeResource
resourceSum *(types.ComputeResourceSummary)
clusterStatusCode int16
err error
clusters []*object.ClusterComputeResource
clMo mo.ClusterComputeResource
resourceSum *(types.ComputeResourceSummary)
usageSum *types.ClusterUsageSummary
numVms int32
err error
)

if c.client == nil {
Expand All @@ -51,7 +52,13 @@ func (c *VcCollector) CollectClusterInfo(
if resourceSum = clMo.Summary.GetComputeResourceSummary(); resourceSum == nil {
return fmt.Errorf("Could not get cluster resource summary")
}
clusterStatusCode = entityStatusCode(resourceSum.OverallStatus)

// get number of VMs in the cluster (tip: https://github.com/vmware/govmomi/issues/1247)
numVms = 0
usageSum = clMo.Summary.(*types.ClusterComputeResourceSummary).UsageSummary
if usageSum != nil {
numVms = usageSum.TotalVmCount
}

cltags := getClusterTags(
c.client.Client.URL().Host,
Expand All @@ -61,15 +68,16 @@ func (c *VcCollector) CollectClusterInfo(
)
clfields := getClusterFields(
string(resourceSum.OverallStatus),
clusterStatusCode,
entityStatusCode(resourceSum.OverallStatus),
resourceSum.NumHosts,
resourceSum.NumEffectiveHosts,
resourceSum.NumCpuCores,
resourceSum.NumCpuThreads,
int(resourceSum.TotalCpu),
int(resourceSum.TotalMemory),
int(resourceSum.EffectiveCpu),
int(resourceSum.EffectiveMemory),
int64(resourceSum.TotalCpu),
resourceSum.TotalMemory,
int64(resourceSum.EffectiveCpu),
resourceSum.EffectiveMemory,
numVms,
)
acc.AddFields("vcstat_cluster", clfields, cltags, time.Now())
}
Expand All @@ -92,14 +100,16 @@ func getClusterFields(
clusterstatuscode int16,
numhosts, numeffectivehosts int32,
numcpucores, numcputhreads int16,
totalcpu, totalmemory, effectivecpu, effectivememory int,
totalcpu, totalmemory, effectivecpu, effectivememory int64,
numvms int32,
) map[string]interface{} {
return map[string]interface{}{
"effective_cpu": effectivecpu,
"effective_memory": effectivememory,
"num_cpu_cores": numcpucores,
"num_cpu_threads": numcputhreads,
"num_effective_hosts": numeffectivehosts,
"num_vms": numvms,
"num_hosts": numhosts,
"status": overallstatus,
"status_code": clusterstatuscode,
Expand Down

0 comments on commit 89264de

Please sign in to comment.