Skip to content

Commit

Permalink
[OMON-350] Add DbFiller utility (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
awegrzyn authored May 28, 2020
1 parent a4e4c9e commit fbeb3ca
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ set(EXAMPLES
examples/5-Benchmark.cxx
examples/6-Increment.cxx
examples/7-InternalBenchamrk.cxx
examples/8-DbFiller.cxx
examples/10-Buffering.cxx
)

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

set_target_properties(5-Benchmark PROPERTIES OUTPUT_NAME "o2-monitoring-benchmark")
set_target_properties(8-DbFiller PROPERTIES OUTPUT_NAME "o2-monitoring-dbfiller")

####################################
# Tests
Expand Down Expand Up @@ -238,7 +240,7 @@ endforeach()
####################################

# Install library
install(TARGETS Monitoring 5-Benchmark
install(TARGETS Monitoring 5-Benchmark 8-DbFiller
EXPORT MonitoringTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
57 changes: 57 additions & 0 deletions examples/8-DbFiller.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
///
/// \file 8-DbFiller.cxx
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
///

#include "Monitoring/MonitoringFactory.h"
#include <boost/program_options.hpp>
#include <random>

using o2::monitoring::Metric;
using namespace o2::monitoring;

int main(int argc, char* argv[])
{
std::srand(std::time(nullptr));

std::random_device rd;
std::mt19937 mt(rd());

std::uniform_real_distribution<double> doubleDist(1.0, 100.0);
std::uniform_int_distribution<> intDist(1, 100);

boost::program_options::options_description desc("Allowed options");
desc.add_options()
("url", boost::program_options::value<std::string>()->required(), "URL to monitoring backend (or list of comma seperated URLs)")
("measurements", boost::program_options::value<int>()->default_value(1), "Number of different measurements")
("flps", boost::program_options::value<int>()->default_value(1), "Number of FLPs")
("since", boost::program_options::value<int>()->default_value(60), "Start filling since (s)")
("interval", boost::program_options::value<int>()->default_value(1), "Interval between metrics (s)");

boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
boost::program_options::notify(vm);

auto monitoring = MonitoringFactory::Get(vm["url"].as<std::string>());
monitoring->addGlobalTag(tags::Key::Subsystem, tags::Value::QC);

auto now = Metric::getCurrentTimestamp();
auto interval = std::chrono::seconds(vm["interval"].as<int>());
auto since = now - std::chrono::seconds(vm["since"].as<int>());

for (;;) {
since = since + interval;
for (int i = 1; i <= vm["measurements"].as<int>(); i++) {
for (int k = 1; k <= vm["flps"].as<int>(); k++) {
auto metric = Metric{"metric" + std::to_string(i), Metric::DefaultVerbosity, since}
.addValue(doubleDist(mt), "double")
.addValue(intDist(mt), "int")
.addValue(std::rand() % 2, "onOff")
.addTag(tags::Key::FLP, k);
monitoring->send(std::move(metric));
std::this_thread::sleep_for(std::chrono::microseconds(1));
}
}
if (since > now) break;
}
}
2 changes: 1 addition & 1 deletion include/Monitoring/Metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Metric

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

/// Adds additional int value to metric
/// \param value
Expand Down
2 changes: 1 addition & 1 deletion src/Metric.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Metric&& Metric::addValue(const std::variant<int, std::string, double, uint64_t>
return std::move(*this);
}

Metric::Metric(const std::string& name, Verbosity verbosity) : mName(name), mTimestamp(Metric::getCurrentTimestamp()), mVerbosity(verbosity)
Metric::Metric(const std::string& name, Verbosity verbosity, const std::chrono::time_point<std::chrono::system_clock>& timestamp) : mName(name), mTimestamp(timestamp), mVerbosity(verbosity)
{
overwriteVerbosity();
}
Expand Down

0 comments on commit fbeb3ca

Please sign in to comment.