From 203df51752403e00cdf7e1cc8d5c0edd726bead0 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 13 Nov 2019 12:48:32 -0800 Subject: [PATCH 1/2] ignore workspace/ folder It's where I usually put temporary identity, etc. files for testing --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a15627933..bbd212f2b 100755 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,4 @@ java/build_win32/ windows/WinUI/obj/ windows/WinUI/bin/ windows/ZeroTierOne/Debug/ +workspace/ From 0c9be4de1437334717ce2cdf1ba2d747762d1027 Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Wed, 15 Jan 2020 16:12:34 -0800 Subject: [PATCH 2/2] add /metrics endpoint for exposing root metrics to Prometheus --- root/root.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/root/root.cpp b/root/root.cpp index 33916faa4..ed5feb53e 100644 --- a/root/root.cpp +++ b/root/root.cpp @@ -966,6 +966,33 @@ int main(int argc,char **argv) res.set_content(o.str(),"text/plain"); }); + apiServ.Get("/metrics",[](const httplib::Request &req, httplib::Response &res) { + std::ostringstream o; + int64_t now = OSUtils::now(); + + char buf[11]; + const char *root_id = s_self.address().toString(buf); + o << "# HELP root_peers_online Number of active peers online" << ZT_EOL_S; + o << "# TYPE root_peers_online gauge" << ZT_EOL_S; + s_peersByIdentity_l.lock(); + o << "root_peers_online{root_id=\"" << root_id << "\"} " << s_peersByIdentity.size() << ZT_EOL_S; + s_peersByIdentity_l.unlock(); + o << "# HELP root_input_rate Input rate MiB/s" << ZT_EOL_S; + o << "# TYPE root_input_rate gauge" << ZT_EOL_S; + o << "root_input_rate{root_id=\"" << root_id << "\"} " << std::setprecision(5) << (s_inputRate.perSecond(now)/1048576.0) << ZT_EOL_S; + o << "# HELP root_output_rate Output rate MiB/s" << ZT_EOL_S; + o << "# TYPE root_output_rate gauge" << ZT_EOL_S; + o << "root_output_rate{root_id=\"" << root_id << "\"} " << std::setprecision(5) << (s_outputRate.perSecond(now)/1048576.0) << ZT_EOL_S; + o << "# HELP root_forwarded_rate Forwarded packet rate MiB/s" << ZT_EOL_S; + o << "# TYPE root_forwarded_rate gauge" << ZT_EOL_S; + o << "root_forwarded_rate{root_id=\"" << root_id << "\"} " << std::setprecision(5) << (s_forwardRate.perSecond(now)/1048576.0) << ZT_EOL_S; + o << "# HELP root_discarded_rate Discarded forwards MiB/s" << ZT_EOL_S; + o << "# TYPE root_discarded_rate gauge" << ZT_EOL_S; + o << "root_discarded_rate{root_id=\"" << root_id << "\"} " << std::setprecision(5) << (s_discardedForwardRate.perSecond(now)/1048576.0) << ZT_EOL_S; + + res.set_content(o.str(), "text/plain"); + }); + // Peer list for compatibility with software that monitors regular nodes apiServ.Get("/peer",[](const httplib::Request &req,httplib::Response &res) { char tmp[256];