https://github.com/vkcom/statshouse-cpp
StatsHouse client library for C++
https://github.com/vkcom/statshouse-cpp
Last synced: 8 months ago
JSON representation
StatsHouse client library for C++
- Host: GitHub
- URL: https://github.com/vkcom/statshouse-cpp
- Owner: VKCOM
- License: mpl-2.0
- Created: 2022-11-22T13:10:04.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-10-04T10:41:20.000Z (over 1 year ago)
- Last Synced: 2025-01-29T19:45:50.076Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 113 KB
- Stars: 5
- Watchers: 12
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# statshouse-cpp
StatsHouse client library for C++
```cpp
#include "statshouse.hpp"
#include
using namespace statshouse;
Registry r{{
logger: puts // debug output
}};
int main() {
// Enable debug output
r.set_metrics_logging_enabled(true);
// Write "counter" metric
auto c = r.metric("demo_counter_metric")
.tag("1", "foo")
.tag("2", "bar")
.event_count_metric_ref();
c.write_count(100); // there were 100 events (e.g. requests)
// Write "value" metric
auto v = r.metric("demo_value_metric")
.tag("1", "foo")
.tag("2", "bar")
.event_metric_ref();
for (auto i = 0; i < 100; ++i) { // there were 100 events
v.write_value(i+1); // each with value "i+1" (e.g. request duration)
}
// Write "waterlevel" metric
auto w = r.metric("demo_waterlevel_metric")
.tag("1", "foo")
.tag("2", "bar")
.waterlevel_metric_ref();
w.set(1024*1024); // current (e.g. memory usage) value is 1MB
w.add(1024*1024); // value goes up by 1MB (current reported value is 2MB)
// Write "uniques" metric
auto u = r.metric("demo_uniques_metric")
.tag("1", "foo")
.tag("2", "bar")
.unique_metric_ref();
for (auto i=0; i < 10; ++i) {
for (auto j=0; j < 10; ++j) { // there were 10 unique values among 100 events
u.write_unique(i+1); // (e.g. user ID)
}
}
// Keep writing some to use "incremental flush"
for (;;) {
std::this_thread::sleep_for(std::chrono::seconds{1});
w.add(1024); // increase waterlevel by 1KB
}
}
```