-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* limits adn usage for cinder * remove debug fmt * add metrics to README * remove commented lines
- Loading branch information
1 parent
b1af2c1
commit 533e022
Showing
9 changed files
with
288 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package exporters | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gophercloud/gophercloud" | ||
"github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets" | ||
"github.com/gophercloud/gophercloud/openstack/dns/v2/zones" | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
type DesignateExporter struct { | ||
BaseOpenStackExporter | ||
} | ||
|
||
var zone_status = []string{ | ||
"pending", | ||
"active", | ||
"deleted", | ||
"error", | ||
} | ||
|
||
var recordset_status = []string{ | ||
"pending", | ||
"active", | ||
"deleted", | ||
"error", | ||
} | ||
|
||
func mapZoneStatus(zoneStatus string) int { | ||
for idx, status := range zone_status { | ||
if status == strings.ToLower(zoneStatus) { | ||
return idx | ||
} | ||
} | ||
return -1 | ||
} | ||
|
||
func mapRecordsetStatus(recordsetStatus string) int { | ||
for idx, status := range recordset_status { | ||
if status == strings.ToLower(recordsetStatus) { | ||
return idx | ||
} | ||
} | ||
return -1 | ||
} | ||
|
||
var defaultDesignateMetrics = []Metric{ | ||
{Name: "zones", Fn: ListZonesAndRecordsets}, | ||
{Name: "zone_status", Labels: []string{"id", "name", "status", "tenant_id", "type"}, Fn: nil}, | ||
{Name: "recordsets", Fn: nil}, | ||
{Name: "recordsets_status", Labels: []string{"id", "name", "status", "zone_id", "zone_name", "type"}, Fn: nil}, | ||
} | ||
|
||
func NewDesignateExporter(client *gophercloud.ServiceClient, prefix string, disabledMetrics []string) (*DesignateExporter, error) { | ||
exporter := DesignateExporter{ | ||
BaseOpenStackExporter{ | ||
Name: "designate", | ||
Prefix: prefix, | ||
Client: client, | ||
DisabledMetrics: disabledMetrics, | ||
}, | ||
} | ||
for _, metric := range defaultDesignateMetrics { | ||
exporter.AddMetric(metric.Name, metric.Fn, metric.Labels, nil) | ||
} | ||
|
||
return &exporter, nil | ||
} | ||
|
||
func ListZonesAndRecordsets(exporter *BaseOpenStackExporter, ch chan<- prometheus.Metric) error { | ||
allPagesZones, err := zones.List(exporter.Client, zones.ListOpts{}).AllPages() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
allZones, err := zones.ExtractZones(allPagesZones) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ch <- prometheus.MustNewConstMetric(exporter.Metrics["zones"].Metric, | ||
prometheus.GaugeValue, float64(len(allZones))) | ||
|
||
// Collect recordsets for zone and write metrics for zones and recordsets | ||
for _, zone := range allZones { | ||
|
||
allPagesRecordsets, err := recordsets.ListByZone(exporter.Client, zone.ID, recordsets.ListOpts{}).AllPages() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
allRecordsets, err := recordsets.ExtractRecordSets(allPagesRecordsets) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ch <- prometheus.MustNewConstMetric(exporter.Metrics["recordsets"].Metric, | ||
prometheus.GaugeValue, float64(len(allRecordsets))) | ||
|
||
for _, recordset := range allRecordsets { | ||
ch <- prometheus.MustNewConstMetric(exporter.Metrics["recordsets_status"].Metric, | ||
prometheus.GaugeValue, float64(mapRecordsetStatus(recordset.Status)), recordset.ID, recordset.Name, | ||
recordset.Status, recordset.ZoneID, recordset.ZoneName, recordset.Type) | ||
} | ||
|
||
ch <- prometheus.MustNewConstMetric(exporter.Metrics["zone_status"].Metric, | ||
prometheus.GaugeValue, float64(mapZoneStatus(zone.Status)), zone.ID, zone.Name, | ||
zone.Status, zone.ProjectID, zone.Type) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package exporters | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type DesignateTestSuite struct { | ||
BaseOpenStackTestSuite | ||
} | ||
|
||
var designateExpectedUp = ` | ||
# HELP openstack_designate_recordsets recordsets | ||
# TYPE openstack_designate_recordsets gauge | ||
openstack_designate_recordsets 1 | ||
# HELP openstack_designate_recordsets_status recordsets_status | ||
# TYPE openstack_designate_recordsets_status gauge | ||
openstack_designate_recordsets_status{id="f7b10e9b-0cae-4a91-b162-562bc6096648",name="example.org.",status="PENDING",type="A",zone_id="2150b1bf-dee2-4221-9d85-11f7886fb15f",zone_name="example.com."} 0 | ||
# HELP openstack_designate_up up | ||
# TYPE openstack_designate_up gauge | ||
openstack_designate_up 1 | ||
# HELP openstack_designate_zone_status zone_status | ||
# TYPE openstack_designate_zone_status gauge | ||
openstack_designate_zone_status{id="a86dba58-0043-4cc6-a1bb-69d5e86f3ca3",name="example.org.",status="ACTIVE",tenant_id="4335d1f0-f793-11e2-b778-0800200c9a66",type="PRIMARY"} 1 | ||
# HELP openstack_designate_zones zones | ||
# TYPE openstack_designate_zones gauge | ||
openstack_designate_zones 1 | ||
` | ||
|
||
var designateExpectedDown = ` | ||
# HELP openstack_designate_up up | ||
# TYPE openstack_designate_up gauge | ||
openstack_designate_up 0 | ||
` | ||
|
||
func (suite *DesignateTestSuite) TestDesignateExporter() { | ||
err := testutil.CollectAndCompare(*suite.Exporter, strings.NewReader(designateExpectedUp)) | ||
assert.NoError(suite.T(), err) | ||
} | ||
|
||
func (suite *DesignateTestSuite) TestDesignateExporterWithEndpointDown() { | ||
suite.teardownFixtures() | ||
defer suite.installFixtures() | ||
|
||
err := testutil.CollectAndCompare(*suite.Exporter, strings.NewReader(designateExpectedDown)) | ||
assert.NoError(suite.T(), err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"recordsets": [ | ||
{ | ||
"description": "This is an example record set.", | ||
"links": { | ||
"self": "https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets/f7b10e9b-0cae-4a91-b162-562bc6096648" | ||
}, | ||
"updated_at": null, | ||
"records": [ | ||
"10.1.0.2" | ||
], | ||
"ttl": 3600, | ||
"id": "f7b10e9b-0cae-4a91-b162-562bc6096648", | ||
"name": "example.org.", | ||
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", | ||
"zone_id": "2150b1bf-dee2-4221-9d85-11f7886fb15f", | ||
"zone_name": "example.com.", | ||
"created_at": "2014-10-24T19:59:44.000000", | ||
"version": 1, | ||
"type": "A", | ||
"status": "PENDING", | ||
"action": "CREATE" | ||
} | ||
], | ||
"links": { | ||
"self": "http:https://127.0.0.1:9001/v2/zones/2150b1bf-dee2-4221-9d85-11f7886fb15f/recordsets?limit=1" | ||
}, | ||
"metadata": { | ||
"total_count": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"zones": [ | ||
{ | ||
"id": "a86dba58-0043-4cc6-a1bb-69d5e86f3ca3", | ||
"pool_id": "572ba08c-d929-4c70-8e42-03824bb24ca2", | ||
"project_id": "4335d1f0-f793-11e2-b778-0800200c9a66", | ||
"name": "example.org.", | ||
"email": "[email protected]", | ||
"ttl": 7200, | ||
"serial": 1404757531, | ||
"status": "ACTIVE", | ||
"action": "CREATE", | ||
"description": "This is an example zone.", | ||
"masters": [], | ||
"type": "PRIMARY", | ||
"transferred_at": null, | ||
"version": 1, | ||
"created_at": "2014-07-07T18:25:31.275934", | ||
"updated_at": null, | ||
"attributes": { | ||
"tier": "gold", "ha": "true" | ||
}, | ||
"links": { | ||
"self": "https://127.0.0.1:9001/v2/zones/a86dba58-0043-4cc6-a1bb-69d5e86f3ca3" | ||
} | ||
} | ||
], | ||
"links": { | ||
"self": "http:https://127.0.0.1:9001/v2/zones?limit=1" | ||
}, | ||
"metadata": { | ||
"total_count": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters