Skip to content

Commit 986e6bf

Browse files
committed
fix: pass node label value to OverlayBD_Alive metric render
1 parent 9ed3049 commit 986e6bf

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/exporter_handler.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#pragma once
1818

19+
#include <unistd.h>
20+
1921
#include <photon/common/conststr.h>
2022
#include <photon/common/estring.h>
2123
#include <photon/common/metric-meter/metrics.h>
@@ -50,8 +52,18 @@ struct ExposeRender : public photon::net::http::HTTPHandler {
5052
EXPOSE_PHOTON_METRICLIST(count, Metric::AddCounter);
5153
EXPOSE_PHOTON_METRICLIST(cache, Metric::ValueCounter);
5254

55+
std::string node_name;
56+
5357
template <typename... Args>
54-
ExposeRender(Args&&... args) {}
58+
ExposeRender(Args&&... args) {
59+
char hostname[256];
60+
if (gethostname(hostname, sizeof(hostname)) == 0) {
61+
hostname[sizeof(hostname) - 1] = '\0';
62+
node_name = hostname;
63+
} else {
64+
node_name = "unknown";
65+
}
66+
}
5567

5668
std::string render() {
5769
EXPOSE_TEMPLATE(alive, OverlayBD_Alive : gauge{node});
@@ -65,7 +77,7 @@ struct ExposeRender : public photon::net::http::HTTPHandler {
6577
ret.append("\n")
6678
.append(alive.type_str())
6779
.append("\n")
68-
.append(alive.render(1))
80+
.append(alive.render(1, node_name.c_str()))
6981
.append("\n\n");
7082
LOOP_APPEND_METRIC(ret, throughput);
7183
LOOP_APPEND_METRIC(ret, qps);

0 commit comments

Comments
 (0)