Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::statsd_metric_data Struct Reference

StatsD-specific metric representation. More...

#include <metric_exporters.h>

Collaboration diagram for kcenon::monitoring::statsd_metric_data:
Collaboration graph

Public Member Functions

std::string to_statsd_format (bool datadog_format=false) const
 Convert to StatsD format.
 

Public Attributes

std::string name
 
metric_type type
 
double value
 
double sample_rate = 1.0
 
std::unordered_map< std::string, std::string > tags
 

Detailed Description

StatsD-specific metric representation.

Definition at line 194 of file metric_exporters.h.

Member Function Documentation

◆ to_statsd_format()

std::string kcenon::monitoring::statsd_metric_data::to_statsd_format ( bool datadog_format = false) const
inline

Convert to StatsD format.

Definition at line 204 of file metric_exporters.h.

204 {
205 std::ostringstream ss;
206
207 ss << name << ":" << value << "|";
208
209 // Add type indicator
210 switch (type) {
211 case metric_type::counter: ss << "c"; break;
212 case metric_type::gauge: ss << "g"; break;
213 case metric_type::timer: ss << "ms"; break;
214 case metric_type::histogram: ss << "h"; break;
215 case metric_type::summary: ss << "s"; break;
216 }
217
218 // Add sample rate if not 1.0
219 if (sample_rate != 1.0) {
220 ss << "|@" << sample_rate;
221 }
222
223 // Add tags (DataDog format)
224 if (datadog_format && !tags.empty()) {
225 ss << "|#";
226 bool first = true;
227 for (const auto& [key, tag_value] : tags) {
228 if (!first) ss << ",";
229 ss << key << ":" << tag_value;
230 first = false;
231 }
232 }
233
234 return ss.str();
235 }
@ timer
StatsD-specific timer metric.
@ gauge
Instantaneous value that can go up and down.
@ counter
Monotonically increasing counter.
@ summary
Pre-calculated quantiles and count/sum.
@ histogram
Distribution of values with buckets.
std::unordered_map< std::string, std::string > tags

References kcenon::monitoring::counter, kcenon::monitoring::gauge, kcenon::monitoring::histogram, name, sample_rate, kcenon::monitoring::summary, tags, kcenon::monitoring::timer, type, and value.

Referenced by TEST_F().

Here is the caller graph for this function:

Member Data Documentation

◆ name

std::string kcenon::monitoring::statsd_metric_data::name

Definition at line 195 of file metric_exporters.h.

Referenced by TEST_F(), and to_statsd_format().

◆ sample_rate

double kcenon::monitoring::statsd_metric_data::sample_rate = 1.0

Definition at line 198 of file metric_exporters.h.

Referenced by TEST_F(), and to_statsd_format().

◆ tags

std::unordered_map<std::string, std::string> kcenon::monitoring::statsd_metric_data::tags

Definition at line 199 of file metric_exporters.h.

Referenced by TEST_F(), and to_statsd_format().

◆ type

metric_type kcenon::monitoring::statsd_metric_data::type

Definition at line 196 of file metric_exporters.h.

Referenced by TEST_F(), and to_statsd_format().

◆ value

double kcenon::monitoring::statsd_metric_data::value

Definition at line 197 of file metric_exporters.h.

Referenced by TEST_F(), and to_statsd_format().


The documentation for this struct was generated from the following file: