-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
273 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/// | ||
/// \file StdOut.cxx | ||
/// \author Adam Wegrzynek <[email protected]> | ||
/// | ||
|
||
#include "StdOut.h" | ||
|
||
#include <iostream> | ||
#include "../MonLogger.h" | ||
|
||
namespace o2 | ||
{ | ||
/// ALICE O2 Monitoring system | ||
namespace monitoring | ||
{ | ||
/// Monitoring backends | ||
namespace backends | ||
{ | ||
|
||
inline unsigned long StdOut::convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp) | ||
{ | ||
return std::chrono::duration_cast <std::chrono::milliseconds>( | ||
timestamp.time_since_epoch() | ||
).count(); | ||
} | ||
|
||
StdOut::StdOut() | ||
{ | ||
setVerbosisty(backend::Verbosity::DEBUG); | ||
MonLogger::Get() << "StdOut backend initialized" << MonLogger::End(); | ||
} | ||
|
||
void StdOut::addGlobalTag(std::string name, std::string value) | ||
{ | ||
if (!tagString.empty()) { | ||
tagString += ","; | ||
} | ||
tagString += name + "=" + value; | ||
} | ||
|
||
void StdOut::send(std::vector<Metric>&& metrics) { | ||
for (auto& m : metrics) { | ||
send(m); | ||
} | ||
} | ||
|
||
void StdOut::sendMultiple(std::string measurement, std::vector<Metric>&& metrics) | ||
{ | ||
for (auto& m : metrics) { | ||
std::string tempName = m.getName(); | ||
m.setName(measurement + "-" + m.getName()); | ||
send(m); | ||
m.setName(tempName); | ||
} | ||
} | ||
|
||
void StdOut::send(const Metric& metric) | ||
{ | ||
std::string metricTags{}; | ||
for (const auto& tag : metric.getTags()) { | ||
if (!metricTags.empty()) { | ||
metricTags += ","; | ||
} | ||
metricTags += tag.name + "=" + tag.value; | ||
} | ||
if (!metricTags.empty()) { | ||
metricTags = "," + metricTags; | ||
} | ||
MonLogger::Get() << "[METRIC] " << metric.getName() << "," << metric.getType() << " " << metric.getValue() | ||
<< " " << convertTimestamp(metric.getTimestamp()) << " " << tagString << metricTags | ||
<< MonLogger::End(); | ||
} | ||
|
||
} // namespace backends | ||
} // namespace monitoring | ||
} // namespace o2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/// | ||
/// \file StdOut.h | ||
/// \author Adam Wegrzynek <[email protected]> | ||
/// | ||
|
||
#ifndef ALICEO2_MONITORING_BACKEND_STDOUT_H | ||
#define ALICEO2_MONITORING_BACKEND_STDOUT_H | ||
|
||
#include "Monitoring/Backend.h" | ||
#include <string> | ||
|
||
namespace o2 | ||
{ | ||
/// ALICE O2 Monitoring system | ||
namespace monitoring | ||
{ | ||
/// Monitoring backends | ||
namespace backends | ||
{ | ||
|
||
/// \brief Backend that injects metrics to InfoLogger | ||
/// | ||
/// InfoLogger does not support std::chrono::time_point therefore timestamps is converted to unsigned long | ||
class StdOut final : public Backend | ||
{ | ||
public: | ||
/// Default constructor | ||
StdOut(); | ||
|
||
/// Default destructor | ||
~StdOut() = default; | ||
|
||
/// Sends metric to InfoLogger library | ||
/// \param metric reference to metric object | ||
void send(const Metric& metric) override; | ||
|
||
/// Sends multiple metrics not related to each other | ||
/// \@param metrics vector of metrics | ||
void send(std::vector<Metric>&& metrics) override; | ||
|
||
/// Sending multiple metrics is NOT supported by the InfoLogger therefore it falls back to sending metric one by one | ||
/// \param measurement measurement name | ||
/// \param metrics list of metrics | ||
void sendMultiple(std::string measurement, std::vector<Metric>&& metrics) override; | ||
|
||
/// Adds tag | ||
/// \param name tag name | ||
/// \param value tag value | ||
void addGlobalTag(std::string name, std::string value) override; | ||
|
||
private: | ||
/// Converts timestamp to unsigned long (miliseconds from epoch) | ||
/// \param timestamp timestamp in std::chrono::time_point format | ||
/// \return timestamp as unsigned long (miliseconds from epoch) | ||
unsigned long convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp); | ||
|
||
std::string tagString; ///< Global tagset (common for each metric) | ||
}; | ||
|
||
} // namespace backends | ||
} // namespace monitoring | ||
} // namespace o2 | ||
|
||
#endif // ALICEO2_MONITORING_BACKEND_STDOUT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.