Repository navigation
Conversation
Power monitoring requires curl to retrieve information, which requires libcurl-devel on almalinux 10
|
Hello @AlexPG1 - thanks for this. I am starting to review now. I fixed a few CI issues for you - we now need curl development packages in the CI environment. The CI failure now looks genuine, in You are producing average values for const prmon::parameter_list params = {
{"utime_total", "s", "Total user CPU time from /proc/stat"},
{"stime_total", "s", "Total system CPU time from /proc/stat"},
{"ntime_total", "s", "Total nice CPU time from /proc/stat"},
};The third string value should rather be an empty string, |
|
Re the CodeFactor issues: fix the blank line on; the method complexity is a false positive for me, so ignore it. |
graeme-a-stewart
left a comment
There was a problem hiding this comment.
@AlexPG1 - great start here, this mostly sound in terms of logic when everything works, but the robustness needs work - see comments inline.
Just again to underline that curlmon is a bad name, powermon would be better.
I do suggest that we bite the bullet and allow the endpoints to be configurable, from the environment (which makes the robustness checks all the more important). As this monitor is a bit special (relying on non-standard infrastructure) we need to document how it works (new file in doc, and a link from the README).
Also needed - tests of the monitor! The idea here would be to precook some inputs as if they came from the curl call, and use that to check the monitor behaves correctly (for expected and unexpected inputs). See the PRECOOKED_SOURCES.md file for how this works for a few of the current monitors...
|
Thanks @AlexPG1 - can you check the build failures? FYI, I think it would now be totally acceptable to move to C++14 (I'd even consider 17...). I have invited you as a developer to the project, so that the CI will run automatically in the future. |
|
Thank you @graeme-a-stewart for all the corrections and the permissions to keep testing automatically! Now powermon reads this PROMETHEUS_LOCAL_URL variable. It first checks whether this variable exists, then extracts directories or urls, then checks if either of those yield the proper metrics. This way, we would be able to read for instance HEP's proposal at CERN just by them defining the environment variable for /var/cache/node_exporter/ipmi.prom. I also updated precook_test.py to generate values for machmon and powermon. I will now start looking through the tests to make a similar one / update existing ones for both of these collectors! |
graeme-a-stewart
left a comment
There was a problem hiding this comment.
Hello @AlexPG1 - great, much improved. I did a review with Claude and it found a few other issues that need fixed.
| }; | ||
|
|
||
| // Execute curl, check filesize | ||
| CURLcode curl_response = curl_easy_perform(curl); |
There was a problem hiding this comment.
This is a resource leak! There's no curl_easy_cleanup called here. Unless we can hold the curl connection between calls, there should be a curl_easy_cleanup() immediately.
| rc = curl_easy_setopt(curl, option, value); | ||
| if (rc != CURLE_OK) { | ||
| error("curl_easy_setopt failed: " + std::string(curl_easy_strerror(rc))); | ||
| curl_easy_cleanup(curl); |
There was a problem hiding this comment.
Remove this cleanup line. If you fail one of the calls in the L150:162 block below then you automatically call curl_easy_cleanup at L163. Then you have a double "free".
|
|
||
| // Execute curl, check filesize | ||
| CURLcode curl_response = curl_easy_perform(curl); | ||
| if (curl_response == CURLE_FILESIZE_EXCEEDED || curl_response == CURLE_WRITE_ERROR) { |
There was a problem hiding this comment.
I'd be a bit stricter here:
- Set the
CURLOPT_FAILONERRORoption above - Consider anything which is not
CURLE_OKas an error
| // Collect Prometheus-style text from, in order of priority: | ||
| // 1. exporter URLs (PROMETHEUS_LOCAL_URL or default) | ||
| // 2. directories from PROMETHEUS_LOCAL_URL | ||
| // 3. default directory <read_path>/power |
There was a problem hiding this comment.
It looks like option (3) is not actually implemented, right? read_path is not used (compiler issued a warning). Isn't this needed, or am I not seeing the logic correctly?
| double hwmon = 0.0; | ||
| try { | ||
| if (!hwmon_lines.empty()) { | ||
| double val = parse_metric_line(hwmon_lines.back(), "node_hwmon_power_average_watt"); |
There was a problem hiding this comment.
Aren't you missing parsing node_hwmon_power_watt here? This is accepted by collect_lines().
| const std::string stat_path = read_path + "/proc/stat"; | ||
| std::ifstream proc_stat{stat_path}; | ||
| if (!proc_stat) { | ||
| throw std::runtime_error("Cannot open " + stat_path); |
There was a problem hiding this comment.
Please don't throw unless your monitor is also catching - you would abort prmon in this case! Just print a warning and skip this iteration.
|
|
||
| // First line: "cpu user nice system idle ..." | ||
| if (!(proc_stat >> cpu_label >> user >> nice >> system)) { | ||
| throw std::runtime_error("Unexpected format in " + stat_path); |
| #define MONITOR_NAME "machmon" | ||
|
|
||
| // Constructor; uses RAII pattern to be valid after construction | ||
| machmon::machmon() : mach_stats{} { |
There was a problem hiding this comment.
For these machine level stats, you should take baseline measurements at initialisation, as is done with netmon. That ensures you subtract the baselines that have been determined as early as possible,
| initialised = true; | ||
| } | ||
|
|
||
| const long clk = sysconf(_SC_CLK_TCK); |
There was a problem hiding this comment.
Minor point - sysconf(_SC_CLK_TCK) could be read during initialisation and stored, rather than read each time.
|
Hi @graeme-a-stewart, I fixed the issues you pointed out! I also added two new tests ( Thanks in advance, |
This contribution aims to include two additional collectors onto prmon. Machmon extracts the full machine cpu times and curlmon reads power consumption metrics if exposed into ports 9100 or 9290 as done by prometheus exporters. These two together would allow an estimation of power consumption due to the monitored process over time. See this presentation for more information.