-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathprovide_via_textfile.cpp
More file actions
39 lines (30 loc) · 1.03 KB
/
provide_via_textfile.cpp
File metadata and controls
39 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* prometheus-cpp-lite — header-only C++ library for exposing Prometheus metrics
* https://github.com/biaks/prometheus-cpp-lite
*
* Copyright (c) 2026 Yan Kryukov ianiskr@gmail.com
* Licensed under the MIT License
*
* =============================================================================
* provide_via_textfile.cpp — File export example
*
* Demonstrates shortest way to save metrics to a .prom file via file_saver_t,
* suitable for node_exporter textfile collector
*
*/
#include <prometheus/counter.h>
#include <prometheus/file_saver.h>
#include <chrono>
#include <cstdlib>
using namespace prometheus;
int main() {
registry_t registry;
counter_metric_t metric (registry, "metric1_name", "description1");
file_saver_t filesaver (registry, std::chrono::seconds(5), "./metrics.prom");
// now our metrics will be save every 5 seconds to ./metrics.prom local file
for (;; ) {
std::this_thread::sleep_for(std::chrono::seconds(1));
const int random_value = std::rand();
metric += random_value % 10;
}
}