Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/inputs/openstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 47 additions & 13 deletions plugins/inputs/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}{}
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions plugins/inputs/openstack/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down