diff --git a/examples/common/metrics_foo_library/foo_library.cc b/examples/common/metrics_foo_library/foo_library.cc index fea86e7a..d8002715 100644 --- a/examples/common/metrics_foo_library/foo_library.cc +++ b/examples/common/metrics_foo_library/foo_library.cc @@ -65,6 +65,22 @@ void foo_library::counter_example(const std::string &name) } } +void foo_library::up_down_counter_example(const std::string &name) +{ + std::string counter_name = name + "_counter"; + auto provider = metrics_api::Provider::GetMeterProvider(); + nostd::shared_ptr meter = provider->GetMeter(name, "1.2.0"); + auto double_counter = meter->CreateDoubleUpDownCounter(counter_name); + + for (uint32_t i = 0; i < 20; ++i) + { + double val = (rand() % 700) + 1.1; + double_counter->Add(val); + double_counter->Add(-1*val); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } +} + void foo_library::observable_counter_example(const std::string &name) { std::string counter_name = name + "_observable_counter"; diff --git a/examples/common/metrics_foo_library/foo_library.h b/examples/common/metrics_foo_library/foo_library.h index 217f9167..8a3a18fc 100644 --- a/examples/common/metrics_foo_library/foo_library.h +++ b/examples/common/metrics_foo_library/foo_library.h @@ -9,6 +9,7 @@ class foo_library { public: static void counter_example(const std::string &name); + static void up_down_counter_example(const std::string &name); static void histogram_example(const std::string &name); static void observable_counter_example(const std::string &name); }; diff --git a/examples/metrics_simple/metrics_ostream.cc b/examples/metrics_simple/metrics_ostream.cc index 7248bc91..06975318 100644 --- a/examples/metrics_simple/metrics_ostream.cc +++ b/examples/metrics_simple/metrics_ostream.cc @@ -129,6 +129,10 @@ int main(int argc, char **argv) { foo_library::counter_example(name); } + else if (example_type == "up_down_counter") + { + foo_library::up_down_counter_example(name); + } else if (example_type == "observable_counter") { foo_library::observable_counter_example(name); @@ -140,6 +144,7 @@ int main(int argc, char **argv) else { std::thread counter_example{&foo_library::counter_example, name}; + std::thread up_down_counter_example{&foo_library::counter_example, name}; std::thread observable_counter_example{&foo_library::observable_counter_example, name}; std::thread histogram_example{&foo_library::histogram_example, name};