mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
Serve prom metrics from /metrics endpoint
This commit is contained in:
parent
ff37fe58f1
commit
328180d2e5
1 changed files with 13 additions and 2 deletions
|
@ -94,8 +94,7 @@ namespace prometheus {
|
|||
|
||||
std::shared_ptr<Registry> registry_ptr = std::make_shared<Registry>();
|
||||
Registry& registry = *registry_ptr;
|
||||
SaveToFile saver(registry_ptr, std::chrono::seconds(5), std::string("./metrics.prom"));
|
||||
|
||||
SaveToFile saver;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -859,6 +858,10 @@ public:
|
|||
_ports[1] = 0;
|
||||
_ports[2] = 0;
|
||||
|
||||
::prometheus::simpleapi::saver.set_registry(::prometheus::simpleapi::registry_ptr);
|
||||
::prometheus::simpleapi::saver.set_delay(std::chrono::seconds(5));
|
||||
::prometheus::simpleapi::saver.set_out_file(_homePath + ZT_PATH_SEPARATOR + "metrics.prom");
|
||||
|
||||
#if ZT_VAULT_SUPPORT
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
#endif
|
||||
|
@ -1758,6 +1761,14 @@ public:
|
|||
scode = 404;
|
||||
}
|
||||
#endif
|
||||
} else if (ps[0] == "metrics") {
|
||||
std::string statspath = _homePath + ZT_PATH_SEPARATOR + "metrics.prom";
|
||||
if (!OSUtils::readFile(statspath.c_str(), responseBody)) {
|
||||
scode = 500;
|
||||
} else {
|
||||
scode = 200;
|
||||
responseContentType = "text/plain";
|
||||
}
|
||||
} else {
|
||||
scode = 401; // isAuth == false && !sso
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue