From 8082c64556bcb59156bbf272ea004d6f1fee41fa Mon Sep 17 00:00:00 2001 From: Chris Goller Date: Fri, 18 Jan 2019 17:38:00 -0600 Subject: [PATCH] feat(bolt): add metrics for influxdb buckets stored in boltdb --- bolt/metrics.go | 15 ++++++++++++++- bolt/metrics_test.go | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/bolt/metrics.go b/bolt/metrics.go index 4c4702bf29..d05b288f63 100644 --- a/bolt/metrics.go +++ b/bolt/metrics.go @@ -13,6 +13,11 @@ var ( "Number of total organizations on the server", nil, nil) + bucketsDesc = prometheus.NewDesc( + "influxdb_buckets_total", + "Number of total buckets on the server", + nil, nil) + usersDesc = prometheus.NewDesc( "influxdb_users_total", "Number of total users on the server", @@ -42,6 +47,7 @@ var ( // Describe returns all descriptions of the collector. func (c *Client) Describe(ch chan<- *prometheus.Desc) { ch <- orgsDesc + ch <- bucketsDesc ch <- usersDesc ch <- tokensDesc ch <- dashboardsDesc @@ -66,9 +72,10 @@ func (c *Client) Collect(ch chan<- prometheus.Metric) { prometheus.CounterValue, float64(writes), ) - orgs, users, tokens, dashboards := 0, 0, 0, 0 + orgs, buckets, users, tokens, dashboards := 0, 0, 0, 0, 0 _ = c.db.View(func(tx *bolt.Tx) error { orgs = tx.Bucket(organizationBucket).Stats().KeyN + buckets = tx.Bucket(bucketBucket).Stats().KeyN users = tx.Bucket(userBucket).Stats().KeyN tokens = tx.Bucket(authorizationBucket).Stats().KeyN dashboards = tx.Bucket(dashboardBucket).Stats().KeyN @@ -81,6 +88,12 @@ func (c *Client) Collect(ch chan<- prometheus.Metric) { float64(orgs), ) + ch <- prometheus.MustNewConstMetric( + bucketsDesc, + prometheus.CounterValue, + float64(buckets), + ) + ch <- prometheus.MustNewConstMetric( usersDesc, prometheus.CounterValue, diff --git a/bolt/metrics_test.go b/bolt/metrics_test.go index 3d146d1ec5..9c3ce99dc3 100644 --- a/bolt/metrics_test.go +++ b/bolt/metrics_test.go @@ -26,6 +26,7 @@ func TestInitialMetrics(t *testing.T) { metrics := map[string]int{ "influxdb_organizations_total": 0, + "influxdb_buckets_total": 0, "influxdb_users_total": 0, "influxdb_tokens_total": 0, "influxdb_dashboards_total": 0, @@ -71,6 +72,7 @@ func TestMetrics_Onboarding(t *testing.T) { metrics := map[string]int{ "influxdb_organizations_total": 1, + "influxdb_buckets_total": 1, "influxdb_users_total": 1, "influxdb_tokens_total": 1, "influxdb_dashboards_total": 1,