Skip to content

Commit

Permalink
Add cinder capacity metrics (#89)
Browse files Browse the repository at this point in the history
Co-authored-by: Jorge Niedbalski <[email protected]>
  • Loading branch information
newrushbolt and niedbalski committed Mar 27, 2020
1 parent f611a68 commit bd991bc
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
27 changes: 27 additions & 0 deletions exporters/cinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/schedulerstats"
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/services"
"github.com/gophercloud/gophercloud/openstack/blockstorage/extensions/volumetenants"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v3/snapshots"
Expand Down Expand Up @@ -53,6 +54,8 @@ var defaultCinderMetrics = []Metric{
{Name: "snapshots", Fn: ListSnapshots},
{Name: "agent_state", Labels: []string{"hostname", "service", "adminState", "zone"}, Fn: ListCinderAgentState},
{Name: "volume_status", Labels: []string{"id", "name", "status", "bootable", "tenant_id", "size", "volume_type"}, Fn: nil},
{Name: "pool_capacity_free_gb", Labels: []string{"name", "volume_backend_name", "vendor_name"}, Fn: ListCinderPoolCapacityFree},
{Name: "pool_capacity_total_gb", Labels: []string{"name", "volume_backend_name", "vendor_name"}, Fn: nil},
}

func NewCinderExporter(client *gophercloud.ServiceClient, prefix string, disabledMetrics []string) (*CinderExporter, error) {
Expand Down Expand Up @@ -146,3 +149,27 @@ func ListCinderAgentState(exporter *BaseOpenStackExporter, ch chan<- prometheus.

return nil
}

func ListCinderPoolCapacityFree(exporter *BaseOpenStackExporter, ch chan<- prometheus.Metric) error {
listOpts := schedulerstats.ListOpts{
Detail: true,
}

allPages, err := schedulerstats.List(exporter.Client, listOpts).AllPages()
if err != nil {
return err
}

allStats, err := schedulerstats.ExtractStoragePools(allPages)
if err != nil {
return err
}

for _, stat := range allStats {
ch <- prometheus.MustNewConstMetric(exporter.Metrics["pool_capacity_free_gb"].Metric, prometheus.GaugeValue,
float64(stat.Capabilities.FreeCapacityGB), stat.Name, stat.Capabilities.VolumeBackendName, stat.Capabilities.VendorName)
ch <- prometheus.MustNewConstMetric(exporter.Metrics["pool_capacity_total_gb"].Metric, prometheus.GaugeValue,
float64(stat.Capabilities.TotalCapacityGB), stat.Name, stat.Capabilities.VolumeBackendName, stat.Capabilities.VendorName)
}
return nil
}
6 changes: 6 additions & 0 deletions exporters/cinder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ var cinderExpectedUp = `
openstack_cinder_agent_state{adminState="enabled",hostname="devstack",service="cinder-backup",zone="nova"} 1
openstack_cinder_agent_state{adminState="enabled",hostname="devstack",service="cinder-scheduler",zone="nova"} 1
openstack_cinder_agent_state{adminState="enabled",hostname="devstack@lvmdriver-1",service="cinder-volume",zone="nova"} 1
# HELP openstack_cinder_pool_capacity_free_gb pool_capacity_free_gb
# TYPE openstack_cinder_pool_capacity_free_gb gauge
openstack_cinder_pool_capacity_free_gb{name="i666testhost@FastPool01",vendor_name="EMC",volume_backend_name="VNX_Pool"} 636.316
# HELP openstack_cinder_pool_capacity_total_gb pool_capacity_total_gb
# TYPE openstack_cinder_pool_capacity_total_gb gauge
openstack_cinder_pool_capacity_total_gb{name="i666testhost@FastPool01",vendor_name="EMC",volume_backend_name="VNX_Pool"} 1692.429
# HELP openstack_cinder_snapshots snapshots
# TYPE openstack_cinder_snapshots gauge
openstack_cinder_snapshots 1
Expand Down
35 changes: 18 additions & 17 deletions exporters/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,24 @@ var fixtures map[string]string = map[string]string{
"/compute/limits?tenant_id=5961c443439d4fcebe42643723755e9d": "nova_os_limits",
"/compute/limits?tenant_id=fdb8424c4e4f4c0ba32c52e2de3bd80e": "nova_os_limits",
"/compute/servers/detail?all_tenants=true": "nova_os_servers",
"/glance/": "glance_api_discovery",
"/glance/v2/images": "glance_images",
"/identity/v3/projects": "identity_projects",
"/neutron/": "neutron_api_discovery",
"/neutron/v2.0/floatingips": "neutron_floating_ips",
"/neutron/v2.0/agents": "neutron_agents",
"/neutron/v2.0/networks": "neutron_networks",
"/neutron/v2.0/security-groups": "neutron_security_groups",
"/neutron/v2.0/subnets": "neutron_subnets",
"/neutron/v2.0/ports": "neutron_ports",
"/neutron/v2.0/network-ip-availabilities": "neutron_network_ip_availabilities",
"/neutron/v2.0/routers": "neutron_routers",
"/neutron/v2.0/lbaas/loadbalancers": "neutron_loadbalancers",
"/volumes": "cinder_api_discovery",
"/volumes/volumes/detail?all_tenants=true": "cinder_volumes",
"/volumes/snapshots": "cinder_snapshots",
"/volumes/os-services": "cinder_os_services",
"/glance/": "glance_api_discovery",
"/glance/v2/images": "glance_images",
"/identity/v3/projects": "identity_projects",
"/neutron/": "neutron_api_discovery",
"/neutron/v2.0/floatingips": "neutron_floating_ips",
"/neutron/v2.0/agents": "neutron_agents",
"/neutron/v2.0/networks": "neutron_networks",
"/neutron/v2.0/security-groups": "neutron_security_groups",
"/neutron/v2.0/subnets": "neutron_subnets",
"/neutron/v2.0/ports": "neutron_ports",
"/neutron/v2.0/network-ip-availabilities": "neutron_network_ip_availabilities",
"/neutron/v2.0/routers": "neutron_routers",
"/neutron/v2.0/lbaas/loadbalancers": "neutron_loadbalancers",
"/volumes": "cinder_api_discovery",
"/volumes/volumes/detail?all_tenants=true": "cinder_volumes",
"/volumes/snapshots": "cinder_snapshots",
"/volumes/os-services": "cinder_os_services",
"/volumes/scheduler-stats/get_pools?detail=true": "cinder_scheduler_stats_pools",
}

func (suite *BaseOpenStackTestSuite) SetupTest() {
Expand Down
29 changes: 29 additions & 0 deletions exporters/fixtures/cinder_scheduler_stats_pools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"pools": [
{
"name": "i666testhost@FastPool01",
"capabilities": {
"pool_name": "FastPool01",
"location_info": "FastPool01|DHC3123523",
"compression_support": "True",
"deduplication_support": "False",
"fast_support": "True",
"thick_provisioning_support": true,
"provisioned_capacity_gb": 33422.797,
"timestamp": "2019-01-11T00:14:26.829133",
"allocated_capacity_gb": 32929,
"volume_backend_name": "VNX_Pool",
"thin_provisioning_support": true,
"free_capacity_gb": 636.316,
"driver_version": "06.00.00",
"total_capacity_gb": 1692.429,
"fast_cache_enabled": "True",
"max_over_subscription_ratio": 1.0,
"vendor_name": "EMC",
"reserved_percentage": 21,
"consistencygroup_support": "True",
"storage_protocol": "FC"
}
}
]
}

0 comments on commit bd991bc

Please sign in to comment.