Skip to content

Commit 13b03e4

Browse files
authored
Allow seting StdOut prefix (#121)
* Allow seting StdOut prefix * Use search instead of path to unify with Kafka
1 parent 6c9781c commit 13b03e4

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/Backends/StdOut.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ inline unsigned long StdOut::convertTimestamp(const std::chrono::time_point<std:
2323
).count();
2424
}
2525

26-
StdOut::StdOut() : mStream(std::cout)
26+
StdOut::StdOut(const std::string& prefix) : mStream(std::cout), mPrefix(prefix)
2727
{
2828
setVerbosisty(Verbosity::Debug);
2929
MonLogger::Get() << "StdOut backend initialized" << MonLogger::End();
@@ -54,15 +54,15 @@ void StdOut::sendMultiple(std::string measurement, std::vector<Metric>&& metrics
5454
metricTags += tags::GetValue(value);
5555
}
5656
for (auto& metric : metrics) {
57-
mStream << "[METRIC] " << measurement << '/' << metric.getName() << ',' << metric.getType() << ' '
57+
mStream << "[" << mPrefix << "] " << measurement << '/' << metric.getName() << ',' << metric.getType() << ' '
5858
<< metric.getValue() << ' ' << convertTimestamp(metric.getTimestamp()) << ' ' << tagString
5959
<< metricTags << '\n';
6060
}
6161
}
6262

6363
void StdOut::send(const Metric& metric)
6464
{
65-
mStream << "[METRIC] " << metric.getName() << ',' << metric.getType() << " " << metric.getValue()
65+
mStream << "[" << mPrefix << "] " << metric.getName() << ',' << metric.getType() << " " << metric.getValue()
6666
<< ' ' << convertTimestamp(metric.getTimestamp()) << ' ' << tagString;
6767

6868
for (const auto& [key, value] : metric.getTags()) {

src/Backends/StdOut.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class StdOut final : public Backend
2323
{
2424
public:
2525
/// Default constructor
26-
StdOut();
26+
StdOut(const std::string& prefix = "METRIC");
2727

2828
/// Default destructor
2929
~StdOut() = default;
@@ -56,6 +56,7 @@ class StdOut final : public Backend
5656
unsigned long convertTimestamp(const std::chrono::time_point<std::chrono::system_clock>& timestamp);
5757

5858
std::string tagString; ///< Global tagset (common for each metric)
59+
const std::string mPrefix; ///< Metric prefix
5960
};
6061

6162
} // namespace backends

src/MonitoringFactory.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ static const std::map<std::string, Verbosity> verbosities = {
3333
{"/debug", Verbosity::Debug}
3434
};
3535

36-
std::unique_ptr<Backend> getStdOut(http::url) {
37-
return std::make_unique<backends::StdOut>();
36+
std::unique_ptr<Backend> getStdOut(http::url uri) {
37+
if (uri.search.size() > 0) {
38+
return std::make_unique<backends::StdOut>(uri.search);
39+
} else {
40+
return std::make_unique<backends::StdOut>();
41+
}
3842
}
3943

4044
std::unique_ptr<Backend> getInfluxDb(http::url uri) {

0 commit comments

Comments
 (0)