Skip to content

Commit 683d407

Browse files
author
John Bochert
committed
feature: added ip address to metrics labels
Signed-off-by: John Bochert <[email protected]>
1 parent c6933e0 commit 683d407

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Changes:
1111
* [FEATURE]
1212
* [ENHANCEMENT]
1313
* [BUGFIX]
14+
* [ENHANCEMENT] Added resolved target IP address as label in blackbox_exporter metrics
1415
* [FEATURE] Support config reload automatically - feature flag `config.enable-auto-reload`, `config.auto-reload-interval`
1516
* [CHANGE] Config is not reloaded if the file content didn't change when using all reload methods
1617

prober/utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
4646
Name: "probe_ip_addr_hash",
4747
Help: "Specifies the hash of IP address. It's useful to detect if the IP address changes.",
4848
})
49+
50+
probeIPAddr := prometheus.NewGaugeVec(prometheus.GaugeOpts{
51+
Name: "probe_ip_addr",
52+
Help: "IP address. It's useful.",
53+
},
54+
[]string{"ip"},
55+
)
56+
4957
registry.MustRegister(probeIPProtocolGauge)
5058
registry.MustRegister(probeDNSLookupTimeSeconds)
5159
registry.MustRegister(probeIPAddrHash)
60+
registry.MustRegister(probeIPAddr)
5261

5362
if IPProtocol == "ip6" || IPProtocol == "" {
5463
IPProtocol = "ip6"
@@ -74,6 +83,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
7483
logger.Debug("Resolved target address", "target", target, "ip", ip.String())
7584
probeIPProtocolGauge.Set(protocolToGauge[IPProtocol])
7685
probeIPAddrHash.Set(ipHash(ip))
86+
probeIPAddr.WithLabelValues(ip.String()).Set(1)
7787
return &net.IPAddr{IP: ip}, lookupTime, nil
7888
}
7989
}
@@ -96,6 +106,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
96106
logger.Debug("Resolved target address", "target", target, "ip", ip.String())
97107
probeIPProtocolGauge.Set(4)
98108
probeIPAddrHash.Set(ipHash(ip.IP))
109+
probeIPAddr.WithLabelValues(ip.IP.String()).Set(1)
99110
return &ip, lookupTime, nil
100111
}
101112

@@ -107,6 +118,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
107118
logger.Debug("Resolved target address", "target", target, "ip", ip.String())
108119
probeIPProtocolGauge.Set(6)
109120
probeIPAddrHash.Set(ipHash(ip.IP))
121+
probeIPAddr.WithLabelValues(ip.IP.String()).Set(1)
110122
return &ip, lookupTime, nil
111123
}
112124

@@ -127,6 +139,7 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
127139
probeIPProtocolGauge.Set(6)
128140
}
129141
probeIPAddrHash.Set(ipHash(fallback.IP))
142+
probeIPAddr.WithLabelValues(fallback.IP.String()).Set(1)
130143
logger.Debug("Resolved target address", "target", target, "ip", fallback.String())
131144
return fallback, lookupTime, nil
132145
}

0 commit comments

Comments
 (0)