mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-13 02:36:54 +02:00
Fix path typo: 3rdpatry
This commit is contained in:
parent
47e05d5a23
commit
dcb4bc5ef4
8 changed files with 32 additions and 22 deletions
|
@ -25,7 +25,7 @@ add_subdirectory("./core")
|
||||||
|
|
||||||
add_subdirectory("./simpleapi")
|
add_subdirectory("./simpleapi")
|
||||||
|
|
||||||
add_subdirectory("./3rdpatry/http-client-lite")
|
add_subdirectory("./3rdparty/http-client-lite")
|
||||||
|
|
||||||
if(PROMETHEUS_BUILD_EXAMPLES)
|
if(PROMETHEUS_BUILD_EXAMPLES)
|
||||||
add_subdirectory("./examples")
|
add_subdirectory("./examples")
|
||||||
|
|
|
@ -6,59 +6,69 @@ It is a tool for quickly adding metrics (and profiling) functionality to C++ pro
|
||||||
|
|
||||||
1. Written in pure C++,
|
1. Written in pure C++,
|
||||||
2. Header-only,
|
2. Header-only,
|
||||||
2. Cross-platform,
|
3. Cross-platform,
|
||||||
3. Compiles with C ++ 11, C ++ 14, C ++ 17 standards,
|
4. Compiles with C ++ 11, C ++ 14, C ++ 17 standards,
|
||||||
4. Has no third-party dependencies,
|
5. Has no third-party dependencies,
|
||||||
5. Several APIs for use in your projects,
|
6. Several APIs for use in your projects,
|
||||||
6. Saving metrics to a file (and then works with node_exporter) or sending via http (uses built-in header-only http-client-lite library),
|
7. Saving metrics to a file (and then works with node_exporter) or sending via http (uses built-in header-only http-client-lite library),
|
||||||
7. Possiblity to use different types for storing metrics data (default is uint32_t, but you can use double or uint64_t types if you want),
|
8. Possiblity to use different types for storing metrics data (default is uint32_t, but you can use double or uint64_t types if you want),
|
||||||
8. Five types of metrics are supported: counter, gauge, summary, histogram and benchmark,
|
9. Five types of metrics are supported: counter, gauge, summary, histogram and benchmark,
|
||||||
10. Has detailed examples of use (see examples folder)
|
10. Has detailed examples of use (see examples folder)
|
||||||
|
|
||||||
## How it differs from the [jupp0r/prometheus-cpp](https://github.com/jupp0r/prometheus-cpp) project:
|
## How it differs from the [jupp0r/prometheus-cpp](https://github.com/jupp0r/prometheus-cpp) project:
|
||||||
|
|
||||||
1. I need a simple header only wariant library without dependencies to write metrics to a .prom file,
|
1. I need a simple header only wariant library without dependencies to write metrics to a .prom file,
|
||||||
2. I need the fastest possible work using integer values of counters (original project use only floating pointer values),
|
2. I need the fastest possible work using integer values of counters (original project use only floating pointer values),
|
||||||
3. The origianl project have problems on compilers that do not know how to do LTO optimization,
|
3. The origianl project have problems on compilers that do not know how to do LTO optimization,
|
||||||
4. I did not like the python style of the original project and the large amount of extra code in it and I wanted to make it lighter and more c++ classic.
|
4. I did not like the python style of the original project and the large amount of extra code in it and I wanted to make it lighter and more c++ classic.
|
||||||
|
|
||||||
## How to use it:
|
## How to use it:
|
||||||
|
|
||||||
The library has two API:
|
The library has two API:
|
||||||
|
|
||||||
1. Complex API for those who want to control everything,
|
1. Complex API for those who want to control everything,
|
||||||
2. Simple API for those who want to quickly add metrics to their C ++ (and it is actually just a wrapper around the complex API).
|
2. Simple API for those who want to quickly add metrics to their C ++ (and it is actually just a wrapper around the complex API).
|
||||||
|
|
||||||
|
|
||||||
### Let's start with a simple API because it's simple:
|
### Let's start with a simple API because it's simple:
|
||||||
|
|
||||||
To add it to your C++ project add these lines to your CMakeLists.txt file:
|
To add it to your C++ project add these lines to your CMakeLists.txt file:
|
||||||
|
|
||||||
```
|
```
|
||||||
add_subdirectory("prometheus-cpp-lite/core")
|
add_subdirectory("prometheus-cpp-lite/core")
|
||||||
add_subdirectory("prometheus-cpp-lite/3rdpatry/http-client-lite")
|
add_subdirectory("prometheus-cpp-lite/3rdparty/http-client-lite")
|
||||||
add_subdirectory("prometheus-cpp-lite/simpleapi")
|
add_subdirectory("prometheus-cpp-lite/simpleapi")
|
||||||
target_link_libraries(your_target prometheus-cpp-simpleapi)
|
target_link_libraries(your_target prometheus-cpp-simpleapi)
|
||||||
```
|
```
|
||||||
|
|
||||||
The simplest way to create a metric would be like this:
|
The simplest way to create a metric would be like this:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
prometheus::simpleapi::METRIC_metric_t metric1 { "metric1", "first simple metric without any tag" };
|
prometheus::simpleapi::METRIC_metric_t metric1 { "metric1", "first simple metric without any tag" };
|
||||||
prometheus::simpleapi::METRIC_metric_t metric2 { "metric2", "second simple metric without any tag" };
|
prometheus::simpleapi::METRIC_metric_t metric2 { "metric2", "second simple metric without any tag" };
|
||||||
```
|
```
|
||||||
where ```METRIC``` can be ```counter```, ```gauge```, ```summary```, ```histogram``` or ```benchmark```.
|
|
||||||
|
where `METRIC` can be `counter`, `gauge`, `summary`, `histogram` or `benchmark`.
|
||||||
|
|
||||||
If you want to access an existing metric again elsewhere in the code, you can do this:
|
If you want to access an existing metric again elsewhere in the code, you can do this:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
prometheus::simpleapi::METRIC_metric_t metric2_yet_another_link { "metric2", "" };
|
prometheus::simpleapi::METRIC_metric_t metric2_yet_another_link { "metric2", "" };
|
||||||
```
|
```
|
||||||
|
|
||||||
this works because when adding a metric, it checks whether there is already a metric with the same name and, if there is one, a link to it is returned.
|
this works because when adding a metric, it checks whether there is already a metric with the same name and, if there is one, a link to it is returned.
|
||||||
|
|
||||||
You can create a family of metrics (metrics with tags) as follows:
|
You can create a family of metrics (metrics with tags) as follows:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
prometheus::simpleapi::METRIC_family_t family { "metric_family", "metric family" };
|
prometheus::simpleapi::METRIC_family_t family { "metric_family", "metric family" };
|
||||||
prometheus::simpleapi::METRIC_metric_t metric1 { family.Add({{"name", "metric1"}}) };
|
prometheus::simpleapi::METRIC_metric_t metric1 { family.Add({{"name", "metric1"}}) };
|
||||||
prometheus::simpleapi::METRIC_metric_t metric2 { family.Add({{"name", "metric2"}}) };
|
prometheus::simpleapi::METRIC_metric_t metric2 { family.Add({{"name", "metric2"}}) };
|
||||||
```
|
```
|
||||||
where METRIC can be ```counter```, ```gauge```, ```summary```, ```histogram``` or ```benchmark```.
|
|
||||||
|
where METRIC can be `counter`, `gauge`, `summary`, `histogram` or `benchmark`.
|
||||||
|
|
||||||
Next, you can do the following things with metrics:
|
Next, you can do the following things with metrics:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
metric++; // for increment it (only for counter and gauge metrics)
|
metric++; // for increment it (only for counter and gauge metrics)
|
||||||
metric += value; // for add value to metric (only for gauge metric)
|
metric += value; // for add value to metric (only for gauge metric)
|
||||||
|
@ -69,6 +79,7 @@ metric.stop(); // stop calculate time (only for benchmark metric)
|
||||||
```
|
```
|
||||||
|
|
||||||
You can change the settings of save (or send) metrics data as follows:
|
You can change the settings of save (or send) metrics data as follows:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
prometheus::simpleapi::saver.set_delay(period_in_seconds); // change the period of saving (or sending) metrics data in seconds (5 seconds by default)
|
prometheus::simpleapi::saver.set_delay(period_in_seconds); // change the period of saving (or sending) metrics data in seconds (5 seconds by default)
|
||||||
prometheus::simpleapi::saver.set_out_file(filename); // change the name of the output file (metrics.prom by default)
|
prometheus::simpleapi::saver.set_out_file(filename); // change the name of the output file (metrics.prom by default)
|
||||||
|
@ -198,4 +209,3 @@ simple_benchmark_family{benchmark="2"} 1.48e-05
|
||||||
# TYPE simple_benchmark counter
|
# TYPE simple_benchmark counter
|
||||||
simple_benchmark 6.0503248
|
simple_benchmark 6.0503248
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue