|
| 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 | +} |
0 commit comments