Skip to content

Commit 81a4c5e

Browse files
authored
Unified object instantiation (#20)
* sendTimed and sendTagged removed as chained method exist * remove configuration dependency * Added UriParser (later to be moved to common) * Modified cmake to avoid errors (to be reverted) * Defining new api * Re-enabled tests * Split protocol with into backend and transport * Fixed edit uri * Allow multiple backend init * Fixed end of non-void function
1 parent 8a150f2 commit 81a4c5e

33 files changed

+271
-406
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ include_directories(
132132
${CMAKE_CURRENT_BINARY_DIR}/include
133133
)
134134

135-
configure_file(examples/config-default.ini examples/config-default.ini COPYONLY)
136-
137135
set(LIBRARY_NAME Monitoring)
138136
set(BUCKET_NAME o2_monitoring_bucket)
139137
O2_GENERATE_LIBRARY()
@@ -162,7 +160,6 @@ set(EXAMPLES
162160
examples/3-UserDefinedTimestamp
163161
examples/4-RateDerivedMetric.cxx
164162
examples/5-Benchmark.cxx
165-
examples/6-DedicatedInstance.cxx
166163
examples/7-Latency.cxx
167164
examples/8-Multiple.cxx
168165
)

README.md

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,11 @@ Monitoring::Create("file://../Monitoring/examples/config-default.ini");
147147
Metric can be sent by one of the following ways:
148148
1. By creating and moving metric object:
149149
+ `send(Metric&& metric)`
150-
151-
In addition, two additional methods can be chained:
150+
Two additional methods can be chained:
152151
+ `addTags(std::vector<Tag>&& tags)`
153152
+ `setTimestamp(std::chrono::time_point<std::chrono::system_clock>& timestamp)`
154153

155-
2. By providing metric parameters:
156-
+ `send(T value, std::string name)`
157-
+ `sendTagged(T value, std::string name, std::vector<Tag>&& tags)`
158-
+ `sendTimed(T value, std::string name, std::chrono::time_point<std::chrono::system_clock>& timestamp)`
159-
3. Sending multiple metrics (only InfluxDB and Zabbix are supported, other backends fallback into sending metrics one by one)
154+
2. Sending multiple metrics (only InfluxDB and Zabbix are supported, other backends fallback into sending metrics one by one)
160155
+ `void send(std::string name, std::vector<Metric>&& metrics)`
161156

162157
## Derived metrics
@@ -241,11 +236,6 @@ Monitoring::Configure("file://../examples/config-default.ini");
241236
// 10 is the value
242237
// myMetric is the name of the metric
243238
// then vector of key-value tags
244-
//
245-
// 1. by copying value and name and moving tags
246-
Monitoring::Get().sendTagged(10, "myMetric", {{"tag1", "value1"}, {"tag2", "value2"}});
247-
248-
// 2. by moving value, name and tags
249239
Monitoring::Get().send(Metric{10, "myMetric"}.addTags({{"tag1", "value1"}, {"tag2", "value2"}}))
250240
```
251241

@@ -261,13 +251,6 @@ std::chrono::time_point<std::chrono::system_clock> timestamp = std::chrono::syst
261251
// now send an application specific metric
262252
// 10 is the value timestamp
263253
// myCrazyMetric is the name of the metric
264-
//
265-
// 1. by copying all parameters
266-
Monitoring::Get().sendTimed(10, "myCrazyMetric", timestamp);
267-
std::this_thread::sleep_for(std::chrono::seconds(1));
268-
Monitoring::Get().sendTimed(40, "myCrazyMetric", timestamp);
269-
270-
// 2. by moving
271254
Monitoring::Get().send(Metric{10, "myCrazyMetric"}.setTimestamp(timestamp));
272255
std::this_thread::sleep_for(std::chrono::seconds(1));
273256
Monitoring::Get().send(Metric{40, "myCrazyMetric"}.setTimestamp(timestamp));

cmake/FindConfiguration.cmake

Lines changed: 0 additions & 36 deletions
This file was deleted.

cmake/MonitoringDependencies.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ find_package(Boost COMPONENTS unit_test_framework program_options system filesys
22
find_package(Git QUIET)
33
find_package(APMON)
44
find_package(CURL)
5-
find_package(Configuration REQUIRED)
65

76
set(extra_deps "")
87
set(extra_deps_include "")
@@ -20,14 +19,12 @@ o2_define_bucket(
2019
o2_monitoring_bucket
2120

2221
DEPENDENCIES
23-
${Configuration_LIBRARIES}
2422
${Boost_SYSTEM_LIBRARY}
2523
${Boost_FILESYSTEM_LIBRARY}
2624
${Boost_PROGRAM_OPTIONS_LIBRARY}
2725
${extra_deps}
2826

2927
SYSTEMINCLUDE_DIRECTORIES
3028
${Boost_INCLUDE_DIRS}
31-
${Configuration_INCLUDE_DIRS}
3229
${extra_deps_include}
3330
)

examples/1-Basic.cxx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
/// \author Adam Wegrzynek <[email protected]>
44
///
55

6-
#include "ExampleBoilerplate.cxx"
76
#include "Monitoring/MonitoringFactory.h"
7+
#include "Monitoring/Collector.h"
88

99
using Monitoring = AliceO2::Monitoring::MonitoringFactory;
1010

11-
int main(int argc, char *argv[]) {
12-
13-
// configure monitoring (once per process), pass configuration path as parameter
14-
Monitoring::Configure("file://" + GetConfigFromCmdLine(argc, argv));
15-
11+
int main() {
12+
// Configure monitoring
13+
// Pass string with list of URLs as parameter
14+
auto collector = Monitoring::Get("infologger://");
15+
1616
// now send an application specific metric
1717
// 10 is the value
1818
// myMetric is the name of the metric
1919
//
2020
// 1. by copying values
21-
Monitoring::Get().send(10, "myMetricInt");
22-
Monitoring::Get().send(10.10, "myMetricFloat");
21+
collector->send(10, "myMetricInt");
22+
collector->send(10.10, "myMetricFloat");
2323

2424
// 2. by creating and moving metric object
25-
Monitoring::Get().send({10, "myMetricInt"});
26-
Monitoring::Get().send({10.10, "myMetricFloat"});
25+
collector->send({10, "myMetricInt"});
26+
collector->send({10.10, "myMetricFloat"});
2727
}

examples/2-TaggedMetrics.cxx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,20 @@
33
/// \author Adam Wegrzynek <[email protected]>
44
///
55

6-
#include "ExampleBoilerplate.cxx"
76
#include "Monitoring/MonitoringFactory.h"
87

98
using Monitoring = AliceO2::Monitoring::MonitoringFactory;
109
using AliceO2::Monitoring::Metric;
1110

12-
int main(int argc, char *argv[]) {
11+
int main() {
1312

14-
// configure monitoring (once per process), pass configuration path as parameter
15-
Monitoring::Configure("file://" + GetConfigFromCmdLine(argc, argv));
13+
// Configure monitoring
14+
// Pass string with list of URLs as parameter
15+
auto collector = Monitoring::Get("infologger://");
1616

1717
// now send an application specific metric with additional tags
1818
// 10 is the value
1919
// myMetric is the name of the metric
2020
// then vector of key-value tags
21-
//
22-
// 1. by copying value and name and moving tags
23-
Monitoring::Get().sendTagged(10, "myMetric", {{"tag1", "value1"}, {"tag2", "value2"}});
24-
25-
// 2. by moving value, name and tags
26-
Monitoring::Get().send(Metric{10, "myMetric"}.addTags({{"tag1", "value1"}, {"tag2", "value2"}}));
21+
collector->send(Metric{10, "myMetric"}.addTags({{"tag1", "value1"}, {"tag2", "value2"}}));
2722
}

examples/3-UserDefinedTimestamp.cxx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,23 @@
33
/// \author Adam Wegrzynek <[email protected]>
44
///
55

6-
#include "ExampleBoilerplate.cxx"
76
#include "Monitoring/MonitoringFactory.h"
87

98
using Monitoring = AliceO2::Monitoring::MonitoringFactory;
109
using AliceO2::Monitoring::Metric;
1110

12-
int main(int argc, char *argv[]) {
13-
14-
// configure monitoring (once per process), pass configuration path as parameter
15-
Monitoring::Configure("file://" + GetConfigFromCmdLine(argc, argv));
11+
int main() {
12+
// Configure monitoring
13+
// Pass string with list of URLs as parameter
14+
auto collector = Monitoring::Get("infologger://");
1615

1716
// current timestamp
1817
std::chrono::time_point<std::chrono::system_clock> timestamp = std::chrono::system_clock::now();
1918

2019
// now send an application specific metric
2120
// 10 is the value timestamp
2221
// myCrazyMetric is the name of the metric
23-
//
24-
// 1. by copying all parameters
25-
Monitoring::Get().sendTimed(10, "myCrazyMetric", timestamp);
26-
std::this_thread::sleep_for(std::chrono::seconds(1));
27-
Monitoring::Get().sendTimed(40, "myCrazyMetric", timestamp);
28-
29-
// 2. by moving
30-
Monitoring::Get().send(Metric{10, "myCrazyMetric"}.setTimestamp(timestamp));
22+
collector->send(Metric{10, "myCrazyMetric"}.setTimestamp(timestamp));
3123
std::this_thread::sleep_for(std::chrono::seconds(1));
32-
Monitoring::Get().send(Metric{40, "myCrazyMetric"}.setTimestamp(timestamp));
24+
collector->send(Metric{40, "myCrazyMetric"}.setTimestamp(timestamp));
3325
}

examples/4-RateDerivedMetric.cxx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
/// \author Adam Wegrzynek <[email protected]>
44
///
55

6-
#include "ExampleBoilerplate.cxx"
76
#include "Monitoring/MonitoringFactory.h"
87

98
using Monitoring = AliceO2::Monitoring::MonitoringFactory;
109

11-
int main(int argc, char *argv[]) {
12-
// configure monitoring (once per process), pass configuration path as parameter
13-
Monitoring::Configure("file://" + GetConfigFromCmdLine(argc, argv));
10+
int main() {
11+
// Configure monitoring
12+
// Pass string with list of URLs as parameter
13+
auto collector = Monitoring::Get("infologger://");
1414

1515
// derived metric : rate
16-
Monitoring::Get().addDerivedMetric("myMetric", AliceO2::Monitoring::DerivedMetricMode::RATE);
16+
collector->addDerivedMetric("myMetric", AliceO2::Monitoring::DerivedMetricMode::RATE);
1717

1818
// now send at least two metrics to see the result
1919
for (int i = 0; i < 101; i += 10) {
20-
Monitoring::Get().send(i, "myMetric");
20+
collector->send(i, "myMetric");
2121
std::this_thread::sleep_for(std::chrono::milliseconds(250));
2222
}
2323
}

examples/5-Benchmark.cxx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main(int argc, char *argv[]) {
2222
boost::program_options::options_description desc("Allowed options");
2323
desc.add_options()
2424
("sleep", boost::program_options::value<int>(), "Thread sleep in microseconds")
25-
("config", boost::program_options::value<std::string>()->required(), "Config file path")
25+
("url", boost::program_options::value<std::string>()->required(), "URL to monitoring backend (or list of comma seperated URLs)")
2626
("id", boost::program_options::value<std::string>(), "Instance ID")
2727
("count", boost::program_options::value<int>(), "Number of metric bunches (x3)")
2828
("multiple", boost::program_options::bool_switch()->default_value(false), "Sends multiple metrics per measurement")
@@ -40,12 +40,7 @@ int main(int argc, char *argv[]) {
4040
count = vm["count"].as<int>();
4141
}
4242

43-
try {
44-
Monitoring::Configure("file://" + vm["config"].as<std::string>());
45-
} catch (std::string &e) {
46-
std::cout << "Configuration file not found.\n" << e << std::endl;
47-
std::exit(EXIT_FAILURE);
48-
}
43+
auto collector = Monitoring::Get(vm["url"].as<std::string>());
4944

5045
int add = 0;
5146
if (count != 0) {
@@ -55,14 +50,14 @@ int main(int argc, char *argv[]) {
5550

5651
if (!vm["multiple"].as<bool>()) {
5752
for (int i = 0; i <= count; i += add) {
58-
Monitoring::Get().send({"string" + std::to_string(intDist(mt)), "stringMetric"});
59-
Monitoring::Get().send({doubleDist(mt), "doubleMetric"});
60-
Monitoring::Get().send({intDist(mt), "intMetric"});
53+
collector->send({"string" + std::to_string(intDist(mt)), "stringMetric"});
54+
collector->send({doubleDist(mt), "doubleMetric"});
55+
collector->send({intDist(mt), "intMetric"});
6156
std::this_thread::sleep_for(std::chrono::microseconds(sleep));
6257
}
6358
} else {
6459
for (int i = 0; i <= count; i += add) {
65-
Monitoring::Get().send("benchmarkMeasurement",{
60+
collector->send("benchmarkMeasurement",{
6661
{"string" + std::to_string(intDist(mt)), "stringMetric"},
6762
{doubleDist(mt), "doubleMetric"},
6863
{intDist(mt), "intMetric"}

examples/6-DedicatedInstance.cxx

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)