-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMonitoringFactory.cxx
More file actions
96 lines (80 loc) · 2.5 KB
/
MonitoringFactory.cxx
File metadata and controls
96 lines (80 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
///
/// \file MonitoringFactory.cxx
/// \author Adam Wegrzynek <adam.wegrzynek@cern.ch>
///
#include "Monitoring/MonitoringFactory.h"
#include <functional>
#include <stdexcept>
#include <boost/algorithm/string.hpp>
#include "MonLogger.h"
#include "UriParser/UriParser.h"
#include "Backends/InfoLoggerBackend.h"
#include "Backends/Flume.h"
#ifdef _WITH_APPMON
#include "Backends/ApMonBackend.h"
#endif
#ifdef _WITH_INFLUX
#include "Backends/InfluxDB.h"
#endif
namespace o2
{
/// ALICE O2 Monitoring system
namespace monitoring
{
std::unique_ptr<Backend> getInfoLogger(http::url uri) {
return std::make_unique<backends::InfoLoggerBackend>();
}
std::unique_ptr<Backend> getInfluxDb(http::url uri) {
auto const position = uri.protocol.find_last_of('-');
if (position != std::string::npos) {
uri.protocol = uri.protocol.substr(position + 1);
}
if (uri.protocol == "udp") {
return std::make_unique<backends::InfluxDB>(uri.host, uri.port);
}
if (uri.protocol == "http") {
return std::make_unique<backends::InfluxDB>(uri.host, uri.port, uri.search);
}
throw std::runtime_error("InfluxDB transport protocol not supported");
}
std::unique_ptr<Backend> getApMon(http::url uri) {
#ifdef _WITH_APPMON
return std::make_unique<backends::ApMonBackend>(uri.path);
#else
throw std::runtime_error("ApMon backend is not enabled");
#endif
}
std::unique_ptr<Backend> getFlume(http::url uri) {
return std::make_unique<backends::Flume>(uri.host, uri.port);
}
std::unique_ptr<Backend> MonitoringFactory::GetBackend(std::string& url) {
static const std::map<std::string, std::function<std::unique_ptr<Backend>(const http::url&)>> map = {
{"infologger", getInfoLogger},
{"influxdb-udp", getInfluxDb},
{"influxdb-http", getInfluxDb},
{"apmon", getApMon},
{"flume", getFlume},
};
http::url parsedUrl = http::ParseHttpUrl(url);
if (parsedUrl.protocol.empty()) {
throw std::runtime_error("Ill-formed URI");
}
auto iterator = map.find(parsedUrl.protocol);
if (iterator != map.end()) {
return iterator->second(parsedUrl);
} else {
throw std::runtime_error("Unrecognized backend " + parsedUrl.protocol);
}
}
std::unique_ptr<Monitoring> MonitoringFactory::Get(std::string urlsString)
{
auto monitoring = std::make_unique<Monitoring>();
std::vector<std::string> urls;
boost::split(urls, urlsString, boost::is_any_of(","));
for (auto url : urls) {
monitoring->addBackend(MonitoringFactory::GetBackend(url));
}
return monitoring;
}
} // namespace monitoring
} // namespace o2