Fix #2248: use hostname and port as instance label of metrics (#2249)

Signed-off-by: caosiyang <csy3228@gmail.com>
This commit is contained in:
caosiyang 2020-05-08 19:08:04 +08:00 committed by GitHub
parent 104cda1a76
commit 7b0998885c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -48,6 +48,7 @@ Please mark all change in change log and use the issue from GitHub
- \#2185 Change id to string format in http module
- \#2186 Update endpoints in http module
- \#2190 Fix memory usage is twice of index size when using GPU searching
- \#2248 Use hostname and port as instance label of metrics
- \#2252 Upgrade mishards to v0.9.0
## Task

View File

@ -15,6 +15,7 @@
#include "metrics/SystemInfo.h"
#include "utils/Log.h"
#include <unistd.h>
#include <string>
#include <utility>
@ -31,14 +32,23 @@ PrometheusMetrics::Init() {
}
// Following should be read from config file.
std::string push_port, push_address;
std::string server_port, push_port, push_address;
CONFIG_CHECK(config.GetServerConfigPort(server_port));
CONFIG_CHECK(config.GetMetricConfigPort(push_port));
CONFIG_CHECK(config.GetMetricConfigAddress(push_address));
const std::string uri = std::string("/metrics");
// const std::size_t num_threads = 2;
auto labels = prometheus::Gateway::GetInstanceLabel("pushgateway");
std::string hostportstr;
char hostname[1024];
if (gethostname(hostname, sizeof(hostname)) == 0) {
hostportstr = std::string(hostname) + ":" + server_port;
} else {
hostportstr = "pushgateway";
}
auto labels = prometheus::Gateway::GetInstanceLabel(hostportstr);
// Init pushgateway
gateway_ = std::make_shared<prometheus::Gateway>(push_address, push_port, "milvus_metrics", labels);