Skip to content

Commit 404c0d5

Browse files
committed
New metrics for ha peer
Signed-off-by: Örnfeldt Philip (66140321) <[email protected]>
1 parent 2e5b08f commit 404c0d5

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

pkg/probe/system_ha_peer.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,16 @@ import (
2323
)
2424

2525
func probeSystemHaPeer(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
26-
Priority := prometheus.NewDesc(
27-
"fortigate_ha_peer",
26+
Info := prometheus.NewDesc(
27+
"fortigate_ha_peer_info",
28+
"Information about the ha peer.",
29+
[]string{"serial", "vcluster", "hostname", "priority"}, nil,
30+
)
31+
32+
Primary := prometheus.NewDesc(
33+
"fortigate_ha_peer_primary",
2834
"True when the peer device is the HA primary.",
29-
[]string{"serial", "vcluster", "hostname", "master", "primary", "priority"}, nil,
35+
[]string{"vcluster", "hostname"}, nil,
3036
)
3137

3238
type SystemHaPeer struct {
@@ -50,15 +56,14 @@ func probeSystemHaPeer(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Met
5056
m := []prometheus.Metric{}
5157
for _, r := range res.Result {
5258
if meta.VersionMajor >= 7 && meta.VersionMinor >= 4 {
59+
m = append(m, prometheus.MustNewConstMetric(Info, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatFloat(r.Priority, 'f', -1, 64)))
5360
if r.Primary {
54-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "true", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
55-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 0, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "false", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
61+
m = append(m, prometheus.MustNewConstMetric(Primary, prometheus.GaugeValue, 1, strconv.FormatInt(r.Vcluster, 10), r.Hostname))
5662
} else {
57-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 0, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "true", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
58-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, 1, r.Serial, strconv.FormatInt(r.Vcluster, 10), r.Hostname, strconv.FormatBool(r.Master), "false", strconv.FormatFloat(r.Priority, 'f', -1, 64)))
63+
m = append(m, prometheus.MustNewConstMetric(Primary, prometheus.GaugeValue, 0, strconv.FormatInt(r.Vcluster, 10), r.Hostname))
5964
}
6065
} else {
61-
m = append(m, prometheus.MustNewConstMetric(Priority, prometheus.GaugeValue, -1, "None", "0", "None", "false", "Unsupported", "false"))
66+
m = append(m, prometheus.MustNewConstMetric(Info, prometheus.GaugeValue, -1, "None", "0", "None", "false"))
6267
break
6368
}
6469
}

pkg/probe/system_ha_peer_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func TestSystemHaPeerOld(t *testing.T) {
3434
}
3535

3636
em := `
37-
# HELP fortigate_ha_peer True when the peer device is the HA primary.
38-
# TYPE fortigate_ha_peer gauge
39-
fortigate_ha_peer{hostname="None",master="false",primary="Unsupported",priority="false",serial="None",vcluster="0"} -1
37+
# HELP fortigate_ha_peer_info Information about the ha peer.
38+
# TYPE fortigate_ha_peer_info gauge
39+
fortigate_ha_peer_info{hostname="None",priority="false",serial="None",vcluster="0"} -1
4040
`
4141

4242
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
@@ -57,12 +57,14 @@ func TestSystemHaPeerAfter74(t *testing.T) {
5757
}
5858

5959
em := `
60-
# HELP fortigate_ha_peer True when the peer device is the HA primary.
61-
# TYPE fortigate_ha_peer gauge
62-
fortigate_ha_peer{hostname="member-name-1",master="false",primary="false",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 0
63-
fortigate_ha_peer{hostname="member-name-1",master="false",primary="true",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 1
64-
fortigate_ha_peer{hostname="member-name-2",master="false",primary="false",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 1
65-
fortigate_ha_peer{hostname="member-name-2",master="false",primary="true",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 0
60+
# HELP fortigate_ha_peer_info Information about the ha peer.
61+
# TYPE fortigate_ha_peer_info gauge
62+
fortigate_ha_peer_info{hostname="member-name-1",priority="200",serial="FGT61E4QXXXXXXXX1",vcluster="0"} 1
63+
fortigate_ha_peer_info{hostname="member-name-2",priority="100",serial="FGT61E4QXXXXXXXX2",vcluster="0"} 1
64+
# HELP fortigate_ha_peer_primary True when the peer device is the HA primary.
65+
# TYPE fortigate_ha_peer_primary gauge
66+
fortigate_ha_peer_primary{hostname="member-name-1",vcluster="0"} 1
67+
fortigate_ha_peer_primary{hostname="member-name-2",vcluster="0"} 0
6668
`
6769

6870
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {

0 commit comments

Comments
 (0)