-
Notifications
You must be signed in to change notification settings - Fork 18
Prometheus exporter without external dependencies, exporting histograms directly #921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc1716f
Add metrics path API handler
SystemsPurge a33221a
Change metrics endpoint to export histograms of all metrics
SystemsPurge 328f9fa
fix: export histogram prometheus format with cumulative sum rather th…
SystemsPurge 6b11f13
fix: Formatting, Add author, Use stringstream, proper comments and fu…
SystemsPurge 48b1175
Add metrics path API handler
SystemsPurge a0c71ea
Change metrics endpoint to export histograms of all metrics
SystemsPurge f4753f3
fix: export histogram prometheus format with cumulative sum rather th…
SystemsPurge de88199
Merge branch 'draft' into no-extern-deps
SystemsPurge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,9 @@ | |
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include<string> | ||
| #include <jansson.h> | ||
|
|
||
| #include <villas/log.hpp> | ||
|
|
@@ -49,6 +50,7 @@ class Hist { | |
| // Print ASCII style plot of histogram. | ||
| void plot(Logger logger) const; | ||
|
|
||
| void test(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused? |
||
| // Dump histogram data in Matlab format. | ||
| // | ||
| // @return The string containing the dump. The caller is responsible to free() the buffer. | ||
|
|
@@ -60,6 +62,9 @@ class Hist { | |
| // Write the histogram in JSON format to file \p f. | ||
| int dumpJson(FILE *f) const; | ||
|
|
||
| std::string toPrometheusText(std::string metric_name, | ||
| std::string node_name) const; | ||
|
|
||
| // Build a libjansson / JSON object of the histogram. | ||
| json_t *toJson() const; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* The metrics API ressource. | ||
| * | ||
| * Author: Steffen Vogel <post@steffenvogel.de> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put your name here :) |
||
| * Author: Youssef Nakti <naktiyoussef@proton.me> | ||
| * SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <chrono> | ||
|
|
||
| #include <jansson.h> | ||
|
|
||
| #include <villas/api/request.hpp> | ||
| #include <villas/api/response.hpp> | ||
| #include <villas/api/session.hpp> | ||
| #include <villas/node.hpp> | ||
| #include <villas/stats.hpp> | ||
| #include <villas/super_node.hpp> | ||
| #include <villas/utils.hpp> | ||
|
|
||
| namespace villas { | ||
| namespace node { | ||
| namespace api { | ||
|
|
||
| class MetricsRequest : public Request { | ||
| public: | ||
| using Request::Request; | ||
|
|
||
| virtual Response *execute() { | ||
| if (method != Session::Method::GET) | ||
| throw InvalidMethod(this); | ||
|
|
||
| if (body != nullptr) | ||
| throw BadRequest("The metrics endpoint does not accept any body data"); | ||
|
|
||
| std::stringstream res_stream; | ||
| NodeList node_list = session->getSuperNode()->getNodes(); | ||
| for (Node *node : node_list) { | ||
| auto stats = node->getStats(); | ||
| if (!stats) | ||
| continue; | ||
| std::string node_name = node->getNameShort(); | ||
| for (auto &metric : Stats::metrics) { | ||
| std::string metric_name = metric.second.name; | ||
| std::replace(metric_name.begin(), metric_name.end(), '.', '_'); | ||
| res_stream << stats->getHistogram(metric.first) | ||
| .toPrometheusText(metric_name, node->getNameShort()) | ||
| << "\n"; | ||
| } | ||
| } | ||
| auto text_res = res_stream.str(); | ||
| return new Response(session, HTTP_STATUS_OK, "text/plain; charset=UTF-8", | ||
| Buffer(text_res.c_str(), text_res.size())); | ||
| } | ||
| }; | ||
|
|
||
| // Register API request | ||
| static char n[] = "metrics"; | ||
| static char r[] = "/metrics"; | ||
| static char d[] = "Get stats of all nodes in Prometheus metrics format"; | ||
| static RequestPlugin<MetricsRequest, n, r, d> p; | ||
|
|
||
| } // namespace api | ||
| } // namespace node | ||
| } // namespace villas | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually try to group headers into these sections separated by an empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are also missing a space after in
include<string>.@stv0g this grouping is not part of the contributor guidelines, so you shouldn't enforce it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, Its also something which we will fix repo-wide with the new clang-tidy fixes Philipp is working on..
I did not mention the missing space, as it will be fixed by clang-format.