File tree Expand file tree Collapse file tree 5 files changed +18
-11
lines changed
Expand file tree Collapse file tree 5 files changed +18
-11
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,12 @@ class MonitoringFactory
2424
2525 // / Provides single instance on Monitoring Monitoring (singleton)
2626 // / \return renerence to Monitoring instance
27- static std::unique_ptr<Monitoring> Get (std::string urlsString);
27+ // / \throw MonitoringException when backend initialisation failed
28+ static std::unique_ptr<Monitoring> Get (std::string urlsString) noexcept (false );
2829
2930 // / Provides a Monitoring backend based on the URL
3031 // / \return monitoring backend
32+ // / \throw MonitoringException when backend initialisation failed
3133 static std::unique_ptr<Backend> GetBackend (std::string& url);
3234 private:
3335 // / Private constructor disallows to create instance of Factory
Original file line number Diff line number Diff line change 1313#include < memory>
1414#include < string>
1515#include < vector>
16- #include " MonLogger.h"
1716#include " VariantVisitorRate.h"
1817#include " VariantVisitorAdd.h"
1918
Original file line number Diff line number Diff line change 44// /
55
66#include " Monitoring/Monitoring.h"
7+ #include " Exceptions/MonitoringException.h"
78
89#include < boost/lexical_cast.hpp>
910#include < chrono>
@@ -198,14 +199,17 @@ void Monitoring::pushToBackends(Metric&& metric)
198199
199200void Monitoring::send (Metric&& metric, DerivedMetricMode mode)
200201{
201- if (mode == DerivedMetricMode::RATE) {
202- pushToBackends (mDerivedHandler ->rate (metric));
203- }
202+ try {
203+ if (mode == DerivedMetricMode::RATE) {
204+ pushToBackends (mDerivedHandler ->rate (metric));
205+ }
204206
205- if (mode == DerivedMetricMode::INCREMENT) {
206- pushToBackends (mDerivedHandler ->increment (metric));
207+ if (mode == DerivedMetricMode::INCREMENT) {
208+ pushToBackends (mDerivedHandler ->increment (metric));
209+ }
210+ } catch (MonitoringException& e) {
211+ MonLogger::Get () << " [WARN] " << e.what () << MonLogger::End ();
207212 }
208-
209213 pushToBackends (std::move (metric));
210214}
211215
Original file line number Diff line number Diff line change 44// /
55
66#include " HTTP.h"
7+ #include " ../MonLogger.h"
78#include " ../Exceptions/MonitoringException.h"
89#include < boost/algorithm/string.hpp>
910#include < iostream>
@@ -57,10 +58,10 @@ void HTTP::send(std::string&& post)
5758 response = curl_easy_perform (curlHandle.get ());
5859 curl_easy_getinfo (curlHandle.get (), CURLINFO_RESPONSE_CODE, &responseCode);
5960 if (response != CURLE_OK) {
60- throw MonitoringException ( " HTTP Tranposrt " , curl_easy_strerror (response));
61+ MonLogger::Get () << " HTTP Tranport " << curl_easy_strerror (response) << MonLogger::End ( );
6162 }
6263 if (responseCode < 200 || responseCode > 206 ) {
63- throw MonitoringException ( " HTTP Transport" , " Response code : " + std::to_string (responseCode));
64+ MonLogger::Get () << " HTTP Transport: Response code : " << std::to_string (responseCode) << MonLogger::End ( );
6465 }
6566}
6667
Original file line number Diff line number Diff line change 77#include < string>
88#include < iostream>
99#include " Exceptions/MonitoringException.h"
10+ #include " ../MonLogger.h"
1011
1112namespace o2
1213{
@@ -40,7 +41,7 @@ void TCP::send(std::string&& message)
4041 try {
4142 mSocket .send (boost::asio::buffer (message));
4243 } catch (const boost::system::system_error& e) {
43- throw MonitoringException ( " TCP send" , e.what ());
44+ MonLogger::Get () << " TCP send: " << e.what () << MonLogger::End ( );
4445 }
4546}
4647
You can’t perform that action at this time.
0 commit comments