Add `hostname` label to `ceph_crash_reports`

This commit is contained in:
Xavier Villaneau 2022-06-16 13:11:04 -04:00 committed by Xavier Villaneau
parent 2faa6cb82d
commit ae09ffe3fe
2 changed files with 21 additions and 11 deletions

View File

@ -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],
)
}

View File

@ -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`),
},
},
{