Skip to content

Commit fbeb3ca

Browse files
authored
[OMON-350] Add DbFiller utility (#201)
1 parent a4e4c9e commit fbeb3ca

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ set(EXAMPLES
181181
examples/5-Benchmark.cxx
182182
examples/6-Increment.cxx
183183
examples/7-InternalBenchamrk.cxx
184+
examples/8-DbFiller.cxx
184185
examples/10-Buffering.cxx
185186
)
186187

@@ -195,6 +196,7 @@ foreach (example ${EXAMPLES})
195196
endforeach()
196197

197198
set_target_properties(5-Benchmark PROPERTIES OUTPUT_NAME "o2-monitoring-benchmark")
199+
set_target_properties(8-DbFiller PROPERTIES OUTPUT_NAME "o2-monitoring-dbfiller")
198200

199201
####################################
200202
# Tests
@@ -238,7 +240,7 @@ endforeach()
238240
####################################
239241

240242
# Install library
241-
install(TARGETS Monitoring 5-Benchmark
243+
install(TARGETS Monitoring 5-Benchmark 8-DbFiller
242244
EXPORT MonitoringTargets
243245
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
244246
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}

examples/8-DbFiller.cxx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
///
2+
/// \file 8-DbFiller.cxx
3+
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
4+
///
5+
6+
#include "Monitoring/MonitoringFactory.h"
7+
#include <boost/program_options.hpp>
8+
#include <random>
9+
10+
using o2::monitoring::Metric;
11+
using namespace o2::monitoring;
12+
13+
int main(int argc, char* argv[])
14+
{
15+
std::srand(std::time(nullptr));
16+
17+
std::random_device rd;
18+
std::mt19937 mt(rd());
19+
20+
std::uniform_real_distribution<double> doubleDist(1.0, 100.0);
21+
std::uniform_int_distribution<> intDist(1, 100);
22+
23+
boost::program_options::options_description desc("Allowed options");
24+
desc.add_options()
25+
("url", boost::program_options::value<std::string>()->required(), "URL to monitoring backend (or list of comma seperated URLs)")
26+
("measurements", boost::program_options::value<int>()->default_value(1), "Number of different measurements")
27+
("flps", boost::program_options::value<int>()->default_value(1), "Number of FLPs")
28+
("since", boost::program_options::value<int>()->default_value(60), "Start filling since (s)")
29+
("interval", boost::program_options::value<int>()->default_value(1), "Interval between metrics (s)");
30+
31+
boost::program_options::variables_map vm;
32+
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
33+
boost::program_options::notify(vm);
34+
35+
auto monitoring = MonitoringFactory::Get(vm["url"].as<std::string>());
36+
monitoring->addGlobalTag(tags::Key::Subsystem, tags::Value::QC);
37+
38+
auto now = Metric::getCurrentTimestamp();
39+
auto interval = std::chrono::seconds(vm["interval"].as<int>());
40+
auto since = now - std::chrono::seconds(vm["since"].as<int>());
41+
42+
for (;;) {
43+
since = since + interval;
44+
for (int i = 1; i <= vm["measurements"].as<int>(); i++) {
45+
for (int k = 1; k <= vm["flps"].as<int>(); k++) {
46+
auto metric = Metric{"metric" + std::to_string(i), Metric::DefaultVerbosity, since}
47+
.addValue(doubleDist(mt), "double")
48+
.addValue(intDist(mt), "int")
49+
.addValue(std::rand() % 2, "onOff")
50+
.addTag(tags::Key::FLP, k);
51+
monitoring->send(std::move(metric));
52+
std::this_thread::sleep_for(std::chrono::microseconds(1));
53+
}
54+
}
55+
if (since > now) break;
56+
}
57+
}

include/Monitoring/Metric.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Metric
5959

6060
/// Constructor that does not require any value to be specified, .addValue needs to be used
6161
/// \param name metric name
62-
Metric(const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity);
62+
Metric(const std::string& name, Verbosity verbosity = Metric::DefaultVerbosity, const std::chrono::time_point<std::chrono::system_clock>& timestamp = Metric::getCurrentTimestamp());
6363

6464
/// Adds additional int value to metric
6565
/// \param value

src/Metric.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Metric&& Metric::addValue(const std::variant<int, std::string, double, uint64_t>
8787
return std::move(*this);
8888
}
8989

90-
Metric::Metric(const std::string& name, Verbosity verbosity) : mName(name), mTimestamp(Metric::getCurrentTimestamp()), mVerbosity(verbosity)
90+
Metric::Metric(const std::string& name, Verbosity verbosity, const std::chrono::time_point<std::chrono::system_clock>& timestamp) : mName(name), mTimestamp(timestamp), mVerbosity(verbosity)
9191
{
9292
overwriteVerbosity();
9393
}

0 commit comments

Comments
 (0)