feat(inputs.openstack): Gather cinder services (#13443)

This commit is contained in:
Joshua Powers 2023-06-16 03:08:54 -06:00 committed by GitHub
parent 62dc1684f0
commit 33be0dc081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 17 deletions

View File

@ -83,8 +83,9 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
password = "password"
## Available services are:
## "agents", "aggregates", "flavors", "hypervisors", "networks", "nova_services",
## "ports", "projects", "servers", "services", "stacks", "storage_pools", "subnets", "volumes"
## "agents", "aggregates", "cinder_services", "flavors", "hypervisors", "networks",
## "nova_services", "ports", "projects", "servers", "services", "stacks", "storage_pools",
## "subnets", "volumes"
# enabled_services = ["services", "projects", "hypervisors", "flavors", "networks", "volumes"]
## Collect Server Diagnostics

View File

@ -23,6 +23,7 @@ import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats"
cinder_services "github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services"
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumetenants"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/aggregates"
@ -201,19 +202,20 @@ func (o *OpenStack) Gather(acc telegraf.Accumulator) error {
// Gather resources. Note service harvesting must come first as the other
// gatherers are dependant on this information.
gatherers := map[string]func(telegraf.Accumulator) error{
"projects": o.gatherProjects,
"hypervisors": o.gatherHypervisors,
"flavors": o.gatherFlavors,
"servers": o.gatherServers,
"volumes": o.gatherVolumes,
"storage_pools": o.gatherStoragePools,
"subnets": o.gatherSubnets,
"ports": o.gatherPorts,
"networks": o.gatherNetworks,
"aggregates": o.gatherAggregates,
"nova_services": o.gatherNovaServices,
"agents": o.gatherAgents,
"stacks": o.gatherStacks,
"projects": o.gatherProjects,
"hypervisors": o.gatherHypervisors,
"flavors": o.gatherFlavors,
"servers": o.gatherServers,
"volumes": o.gatherVolumes,
"storage_pools": o.gatherStoragePools,
"subnets": o.gatherSubnets,
"ports": o.gatherPorts,
"networks": o.gatherNetworks,
"aggregates": o.gatherAggregates,
"nova_services": o.gatherNovaServices,
"cinder_services": o.gatherCinderServices,
"agents": o.gatherAgents,
"stacks": o.gatherStacks,
}
callDuration := map[string]interface{}{}
@ -328,6 +330,38 @@ func (o *OpenStack) gatherNovaServices(acc telegraf.Accumulator) error {
return nil
}
// gatherCinderServices collects and accumulates cinder_services data from the OpenStack API.
func (o *OpenStack) gatherCinderServices(acc telegraf.Accumulator) error {
page, err := cinder_services.List(o.volume, &cinder_services.ListOpts{}).AllPages()
if err != nil {
return fmt.Errorf("unable to list cinder_services: %w", err)
}
cinderServices, err := cinder_services.ExtractServices(page)
if err != nil {
return fmt.Errorf("unable to extract cinder_services: %w", err)
}
for _, cinderService := range cinderServices {
tags := map[string]string{
"name": cinderService.Binary,
"cluster": cinderService.Cluster,
"host_machine": cinderService.Host,
"state": cinderService.State,
"status": strings.ToLower(cinderService.Status),
"zone": cinderService.Zone,
}
fields := map[string]interface{}{
"id": cinderService.ActiveBackendID,
"disabled_reason": cinderService.DisabledReason,
"frozen": cinderService.Frozen,
"replication_status": cinderService.ReplicationStatus,
"updated_at": o.convertTimeFormat(cinderService.UpdatedAt),
}
acc.AddFields("openstack_cinder_service", fields, tags)
}
return nil
}
// gatherSubnets collects and accumulates subnets data from the OpenStack API.
func (o *OpenStack) gatherSubnets(acc telegraf.Accumulator) error {
page, err := subnets.List(o.network, &subnets.ListOpts{}).AllPages()

View File

@ -16,8 +16,9 @@
password = "password"
## Available services are:
## "agents", "aggregates", "flavors", "hypervisors", "networks", "nova_services",
## "ports", "projects", "servers", "services", "stacks", "storage_pools", "subnets", "volumes"
## "agents", "aggregates", "cinder_services", "flavors", "hypervisors", "networks",
## "nova_services", "ports", "projects", "servers", "services", "stacks", "storage_pools",
## "subnets", "volumes"
# enabled_services = ["services", "projects", "hypervisors", "flavors", "networks", "volumes"]
## Collect Server Diagnostics