using namespace std::chrono;
Metrics global_metrics;
+string Metrics::prefix = "nageru";
double get_timestamp_for_metrics()
{
string Metrics::serialize_name(const string &name, const vector<pair<string, string>> &labels)
{
- return "nageru_" + name + serialize_labels(labels);
+ return prefix + "_" + name + serialize_labels(labels);
}
string Metrics::serialize_labels(const vector<pair<string, string>> &labels)
// If this is the last metric with this name, remove the type as well.
if (!((it != metrics.begin() && prev(it)->first.name == name) ||
- (it != metrics.end() && next(it)->first.name == name))) {
+ (it != metrics.end() && next(it) != metrics.end() && next(it)->first.name == name))) {
types.erase(name);
}
lock_guard<mutex> lock(mu);
auto type_it = types.cbegin();
for (const auto &key_and_metric : metrics) {
- string name = "nageru_" + key_and_metric.first.name + key_and_metric.first.serialized_labels;
+ string name = prefix + "_" + key_and_metric.first.name + key_and_metric.first.serialized_labels;
const Metric &metric = key_and_metric.second;
if (type_it != types.cend() &&
// It's the first time we print out any metric with this name,
// so add the type header.
if (type_it->second == TYPE_GAUGE) {
- ss << "# TYPE nageru_" << type_it->first << " gauge\n";
+ ss << "# TYPE " + prefix + "_" << type_it->first << " gauge\n";
} else if (type_it->second == TYPE_HISTOGRAM) {
- ss << "# TYPE nageru_" << type_it->first << " histogram\n";
+ ss << "# TYPE " + prefix + "_" << type_it->first << " histogram\n";
} else if (type_it->second == TYPE_SUMMARY) {
- ss << "# TYPE nageru_" << type_it->first << " summary\n";
+ ss << "# TYPE " + prefix + "_" << type_it->first << " summary\n";
}
++type_it;
}