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"));
27 lock_guard<mutex> lock(mu);
28 for (const auto &key_and_value : int_metrics) {
29 if (key_and_value.second.type == TYPE_GAUGE) {
30 ss << "# TYPE nageru_" << key_and_value.first << " gauge\n";
32 ss << "nageru_" << key_and_value.first << " " << key_and_value.second.location->load() << "\n";
37 for (const auto &key_and_value : double_metrics) {
38 if (key_and_value.second.type == TYPE_GAUGE) {
39 ss << "# TYPE nageru_" << key_and_value.first << " gauge\n";
41 ss << "nageru_" << key_and_value.first << " " << key_and_value.second.location->load() << "\n";