8 Metrics global_metrics;
10 void Metrics::register_int_metric(const string &name, atomic<int64_t> *location, Metrics::Type type)
12 lock_guard<mutex> lock(mu);
13 int_metrics.emplace(name, Metric<int64_t>{ type, location });
16 void Metrics::register_double_metric(const string &name, atomic<double> *location, Metrics::Type type)
18 lock_guard<mutex> lock(mu);
19 double_metrics.emplace(name, Metric<double>{ type, location });
22 string Metrics::serialize() const
25 ss.imbue(locale("C"));
29 lock_guard<mutex> lock(mu);
30 for (const auto &key_and_value : int_metrics) {
31 if (key_and_value.second.type == TYPE_GAUGE) {
32 ss << "# TYPE nageru_" << key_and_value.first << " gauge\n";
34 ss << "nageru_" << key_and_value.first << " " << key_and_value.second.location->load() << "\n";
36 for (const auto &key_and_value : double_metrics) {
37 if (key_and_value.second.type == TYPE_GAUGE) {
38 ss << "# TYPE nageru_" << key_and_value.first << " gauge\n";
40 ss << "nageru_" << key_and_value.first << " " << key_and_value.second.location->load() << "\n";