From ae09ffe3feed7f5581f5b4fcc7a660edbbacb959 Mon Sep 17 00:00:00 2001 From: Xavier Villaneau Date: Thu, 16 Jun 2022 13:11:04 -0400 Subject: [PATCH] Add `hostname` label to `ceph_crash_reports` --- ceph/crashes.go | 11 +++++++---- ceph/crashes_test.go | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ceph/crashes.go b/ceph/crashes.go index e711ca1..425a3a6 100644 --- a/ceph/crashes.go +++ b/ceph/crashes.go @@ -51,7 +51,7 @@ func NewCrashesCollector(exporter *Exporter) *CrashesCollector { crashReportsDesc: prometheus.NewDesc( fmt.Sprintf("%s_crash_reports", cephNamespace), "Count of crashes reports per daemon, according to `ceph crash ls`", - []string{"entity", "status"}, + []string{"entity", "hostname", "status"}, labels, ), } @@ -60,12 +60,14 @@ func NewCrashesCollector(exporter *Exporter) *CrashesCollector { } type crashEntry struct { - entity string - isNew bool + entity string + hostname string + isNew bool } type cephCrashLs struct { Entity string `json:"entity_name"` + Hostname string `json:"utsname_hostname"` Archived string `json:"archived"` } @@ -92,7 +94,7 @@ func (c *CrashesCollector) getCrashLs() (map[crashEntry]int, error) { } for _, crash := range crashData { - crashes[crashEntry{crash.Entity, len(crash.Archived) == 0}]++ + crashes[crashEntry{crash.Entity, crash.Hostname, len(crash.Archived) == 0}]++ } return crashes, nil @@ -116,6 +118,7 @@ func (c *CrashesCollector) Collect(ch chan<- prometheus.Metric) { prometheus.GaugeValue, float64(count), crash.entity, + crash.hostname, statusNames[crash.isNew], ) } diff --git a/ceph/crashes_test.go b/ceph/crashes_test.go index 626f2bb..286e140 100644 --- a/ceph/crashes_test.go +++ b/ceph/crashes_test.go @@ -86,7 +86,7 @@ func TestCrashesCollector(t *testing.T) { } ]`, reMatch: []*regexp.Regexp{ - regexp.MustCompile(`crash_reports{cluster="ceph",entity="client.admin",status="new"} 1`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="client.admin",hostname="test-ceph-server.company.example",status="new"} 1`), }, }, { @@ -95,6 +95,7 @@ func TestCrashesCollector(t *testing.T) { [ { "entity_name": "client.admin", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-01-25 21:02:46.687015Z", "archived": "2022-06-14 19:44:40.356826", "crash_id": "2022-01-25_21:02:46.687015Z_d6513591-c16b-472f-8d40-5a143b28837d" @@ -102,7 +103,7 @@ func TestCrashesCollector(t *testing.T) { ] `, reMatch: []*regexp.Regexp{ - regexp.MustCompile(`crash_reports{cluster="ceph",entity="client.admin",status="archived"} 1`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="client.admin",hostname="test-ceph-server.company.example",status="archived"} 1`), }, }, { @@ -111,17 +112,19 @@ func TestCrashesCollector(t *testing.T) { [ { "entity_name": "osd.0", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-02-01 21:02:46.687015Z", "crash_id": "2022-02-01_21:02:46.687015Z_0de8b741-b323-4f63-828a-e460294e28b9" }, { "entity_name": "osd.0", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-02-03 04:05:45.419226Z", "crash_id": "2022-02-03_04:05:45.419226Z_11c639af-5eb2-4a29-91aa-20120218891a" } ]`, reMatch: []*regexp.Regexp{ - regexp.MustCompile(`crash_reports{cluster="ceph",entity="osd.0",status="new"} 2`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="osd.0",hostname="test-ceph-server.company.example",status="new"} 2`), }, }, { @@ -130,19 +133,21 @@ func TestCrashesCollector(t *testing.T) { [ { "entity_name": "osd.0", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-02-01 21:02:46.687015Z", "crash_id": "2022-02-01_21:02:46.687015Z_0de8b741-b323-4f63-828a-e460294e28b9" }, { "entity_name": "osd.0", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-02-03 04:05:45.419226Z", "archived": "2022-06-14 19:44:40.356826", "crash_id": "2022-02-03_04:05:45.419226Z_11c639af-5eb2-4a29-91aa-20120218891a" } ]`, reMatch: []*regexp.Regexp{ - regexp.MustCompile(`crash_reports{cluster="ceph",entity="osd.0",status="new"} 1`), - regexp.MustCompile(`crash_reports{cluster="ceph",entity="osd.0",status="archived"} 1`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="osd.0",hostname="test-ceph-server.company.example",status="new"} 1`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="osd.0",hostname="test-ceph-server.company.example",status="archived"} 1`), }, }, { @@ -151,18 +156,20 @@ func TestCrashesCollector(t *testing.T) { [ { "entity_name": "mgr.mgr-node-01", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-02-01 21:02:46.687015Z", "crash_id": "2022-02-01_21:02:46.687015Z_0de8b741-b323-4f63-828a-e460294e28b9" }, { "entity_name": "client.admin", + "utsname_hostname": "test-ceph-server.company.example", "timestamp": "2022-02-03 04:05:45.419226Z", "crash_id": "2022-02-03_04:05:45.419226Z_11c639af-5eb2-4a29-91aa-20120218891a" } ]`, reMatch: []*regexp.Regexp{ - regexp.MustCompile(`crash_reports{cluster="ceph",entity="mgr.mgr-node-01",status="new"} 1`), - regexp.MustCompile(`crash_reports{cluster="ceph",entity="client.admin",status="new"} 1`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="mgr.mgr-node-01",hostname="test-ceph-server.company.example",status="new"} 1`), + regexp.MustCompile(`crash_reports{cluster="ceph",entity="client.admin",hostname="test-ceph-server.company.example",status="new"} 1`), }, }, {