Skip to content

Commit d298ce7

Browse files
committed
Tweak types of metrics for backwards compatibility
1 parent 4775c86 commit d298ce7

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

cmd/p4metrics/p4metrics.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ func (p4m *P4MonitorMetrics) parseLicense() {
581581
p4m.metrics = append(p4m.metrics,
582582
metricStruct{name: "p4_license_IP",
583583
help: "P4D Licensed IP",
584-
mtype: "gauge",
584+
mtype: "", // Should be a gauge but for backwards compatibility we leave as untyped
585585
value: "1",
586586
labels: []labelStruct{{name: "licenseIP", value: licenseIP}}})
587587
}
@@ -1019,7 +1019,7 @@ func (p4m *P4MonitorMetrics) monitorProcesses() {
10191019
for cmd, count := range cmdCounts {
10201020
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_monitor_by_cmd",
10211021
help: "P4 running processes by cmd in monitor table",
1022-
mtype: "gauge",
1022+
mtype: "counter",
10231023
value: fmt.Sprintf("%d", count),
10241024
labels: []labelStruct{{name: "cmd", value: cmd}}})
10251025
}
@@ -1028,7 +1028,7 @@ func (p4m *P4MonitorMetrics) monitorProcesses() {
10281028
for user, count := range userCounts {
10291029
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_monitor_by_user",
10301030
help: "P4 running processes by user in monitor table",
1031-
mtype: "gauge",
1031+
mtype: "counter",
10321032
value: fmt.Sprintf("%d", count),
10331033
labels: []labelStruct{{name: "user", value: user}}})
10341034
}
@@ -1058,8 +1058,10 @@ func (p4m *P4MonitorMetrics) monitorProcesses() {
10581058
if err != nil {
10591059
p4m.logger.Errorf("Error running 'ps ax': %v, err:%q", err, errbuf.String())
10601060
} else {
1061-
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_process_count",
1062-
help: "P4 ps running processes",
1061+
// Old monitor_metrics.sh has p4_process_count but as a counter - should be a gauge!
1062+
// So new name
1063+
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_processes_count",
1064+
help: "P4 count of running processes (via ps)",
10631065
mtype: "gauge",
10641066
value: fmt.Sprintf("%d", pcount)})
10651067
}
@@ -1205,14 +1207,14 @@ func (p4m *P4MonitorMetrics) monitorReplicas() {
12051207
if s.journal != "" {
12061208
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_replica_curr_jnl",
12071209
help: "Current journal for server",
1208-
mtype: "gauge",
1210+
mtype: "counter",
12091211
value: s.journal,
12101212
labels: []labelStruct{{name: "servername", value: s.name}}})
12111213
}
12121214
if s.offset != "" {
12131215
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_replica_curr_pos",
12141216
help: "Current offset within for server",
1215-
mtype: "gauge",
1217+
mtype: "counter", // Probably should be a gauge but kept for compatibility
12161218
value: s.offset,
12171219
labels: []labelStruct{{name: "servername", value: s.name}}})
12181220
}
@@ -1292,11 +1294,13 @@ func (p4m *P4MonitorMetrics) monitorPull() {
12921294
if err != nil {
12931295
p4m.logger.Errorf("Error counting pull queue: %v", err)
12941296
} else {
1295-
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_pull_errors",
1297+
// Old monitor_metrics.sh has p4_pull_errors - but incorrectly as a counter
1298+
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_pull_error_count",
12961299
help: "Count of p4 pull transfers in failed state",
12971300
mtype: "gauge",
12981301
value: fmt.Sprintf("%d", failedCount)})
1299-
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_pull_queue",
1302+
// Old monitor_metrics.sh has p4_pull_queue - but incorrectly as a counter
1303+
p4m.metrics = append(p4m.metrics, metricStruct{name: "p4_pull_queue_count",
13001304
help: "Count of p4 pull files (not in failed state)",
13011305
mtype: "gauge",
13021306
value: fmt.Sprintf("%d", otherCount)})
@@ -1466,9 +1470,13 @@ func (p4m *P4MonitorMetrics) monitorRealTime() {
14661470
continue
14671471
}
14681472
name := "p4_" + strings.ReplaceAll(fields[0], ".", "_")
1473+
mtype := "gauge"
1474+
if fields[0] == "rtv.db.io.records" || fields[0] == "rtv.svr.sessions.total" {
1475+
mtype = "counter" // For backwards compatibility with monitor_metrics.sh and historical data
1476+
}
14691477
p4m.metrics = append(p4m.metrics, metricStruct{name: name,
14701478
help: fmt.Sprintf("P4 realtime metric %s", fields[0]),
1471-
mtype: "gauge",
1479+
mtype: mtype,
14721480
value: fields[3]})
14731481
}
14741482
p4m.writeMetricsFile()

0 commit comments

Comments
 (0)