diff --git a/plugins/inputs/openstack/README.md b/plugins/inputs/openstack/README.md index 2a970e885..98861b458 100644 --- a/plugins/inputs/openstack/README.md +++ b/plugins/inputs/openstack/README.md @@ -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 diff --git a/plugins/inputs/openstack/openstack.go b/plugins/inputs/openstack/openstack.go index 0eff2c823..d4818f747 100644 --- a/plugins/inputs/openstack/openstack.go +++ b/plugins/inputs/openstack/openstack.go @@ -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() diff --git a/plugins/inputs/openstack/sample.conf b/plugins/inputs/openstack/sample.conf index 1df47df4e..a2b247e8d 100644 --- a/plugins/inputs/openstack/sample.conf +++ b/plugins/inputs/openstack/sample.conf @@ -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