|
3 | 3 | /// \author Adam Wegrzynek <[email protected]> |
4 | 4 | /// |
5 | 5 |
|
6 | | -#include <boost/program_options.hpp> |
7 | 6 | #include "Monitoring/MonitoringFactory.h" |
| 7 | +#include <boost/program_options.hpp> |
| 8 | +#include <random> |
8 | 9 |
|
9 | 10 | using Monitoring = AliceO2::Monitoring::MonitoringFactory; |
10 | 11 |
|
11 | 12 | int main(int argc, char *argv[]) { |
12 | 13 | int sleep = 1000000; |
13 | | - int i = std::numeric_limits<int>::max() - 1; |
14 | | - std::string metric = "myCrazyMetric"; |
15 | | - std::string config = "/home/awegrzyn/hackathon/Monitoring/examples/SampleConfig.ini"; |
| 14 | + std::string stringMetric = "stringMetric"; |
| 15 | + std::string doubleMetric = "doubleMetric"; |
| 16 | + std::string intMetric = "intMetric"; |
| 17 | + |
| 18 | + std::random_device rd; |
| 19 | + std::mt19937 mt(rd()); |
| 20 | + |
| 21 | + std::uniform_real_distribution<double> doubleDist(1.0, 100.0); |
| 22 | + std::uniform_int_distribution<> intDist(1, 100); |
| 23 | + |
| 24 | + double doubleValue = doubleDist(mt); |
| 25 | + std::string stringValue = "sampleString" + std::to_string(intDist(mt)); |
| 26 | + int intValue = intDist(mt); |
16 | 27 |
|
17 | 28 | boost::program_options::options_description desc("Allowed options"); |
18 | 29 | desc.add_options() |
19 | | - ("metric", boost::program_options::value<std::string>(), "Metric name") |
20 | 30 | ("sleep", boost::program_options::value<int>(), "Thread sleep in microseconds") |
21 | | - ("count", boost::program_options::value<int>(), "Number of metrics to be sent") |
22 | | - ("config", boost::program_options::value<std::string>(), "Config file path") |
| 31 | + ("config", boost::program_options::value<std::string>()->required(), "Config file path") |
23 | 32 | ; |
24 | 33 |
|
25 | 34 | boost::program_options::variables_map vm; |
26 | 35 | boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm); |
27 | 36 | boost::program_options::notify(vm); |
28 | 37 |
|
29 | | - if (vm.count("metric")) { |
30 | | - metric = vm["metric"].as<std::string>(); |
31 | | - } |
32 | | - |
33 | 38 | if (vm.count("sleep")) { |
34 | 39 | sleep = vm["sleep"].as<int>(); |
35 | 40 | } |
36 | 41 |
|
37 | | - if (vm.count("count")) { |
38 | | - i = vm["count"].as<int>(); |
39 | | - } |
40 | | - |
41 | | - if (vm.count("config")) { |
42 | | - config = vm["config"].as<std::string>(); |
43 | | - } |
44 | | - |
45 | 42 | try { |
46 | 43 | // configure monitoring (once per process), pass configuration path as parameter |
47 | | - Monitoring::Configure("file://" + config); |
| 44 | + Monitoring::Configure("file://" + vm["config"].as<std::string>()); |
48 | 45 | } catch (std::string &e) { |
49 | | - std::cout << "Run you examples from 'build' (dev) or 'bin' (install) direcotry\n"; |
50 | | - std::cout << e << std::endl; |
| 46 | + std::cout << "Configuration file not found.\n" << e << std::endl; |
| 47 | + std::exit(EXIT_FAILURE); |
51 | 48 | } |
52 | 49 |
|
53 | | - for (; i > 0; i--) { |
54 | | - Monitoring::Get().send(10, metric); |
| 50 | + for (;;) { |
| 51 | + Monitoring::Get().send(stringValue, stringMetric); |
| 52 | + Monitoring::Get().send(doubleValue, doubleMetric); |
| 53 | + Monitoring::Get().send(intValue, intMetric); |
55 | 54 | std::this_thread::sleep_for(std::chrono::microseconds(sleep)); |
56 | 55 | } |
57 | 56 | } |
0 commit comments