| 51 | } |
| 52 | |
| 53 | void PrometheusMetricsWriter::write(WriteBuffer & wb) const |
| 54 | { |
| 55 | if (send_events) |
| 56 | { |
| 57 | for (size_t i = 0, end = ProfileEvents::end(); i < end; ++i) |
| 58 | { |
| 59 | const auto counter = ProfileEvents::global_counters[i].load(std::memory_order_relaxed); |
| 60 | |
| 61 | std::string metric_name{ProfileEvents::getName(static_cast<ProfileEvents::Event>(i))}; |
| 62 | std::string metric_doc{ProfileEvents::getDocumentation(static_cast<ProfileEvents::Event>(i))}; |
| 63 | |
| 64 | if (!replaceInvalidChars(metric_name)) |
| 65 | continue; |
| 66 | std::string key{profile_events_prefix + metric_name}; |
| 67 | |
| 68 | writeOutLine(wb, "# HELP", key, metric_doc); |
| 69 | writeOutLine(wb, "# TYPE", key, "counter"); |
| 70 | writeOutLine(wb, key, counter); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (send_metrics) |
| 75 | { |
| 76 | for (size_t i = 0, end = CurrentMetrics::end(); i < end; ++i) |
| 77 | { |
| 78 | const auto value = CurrentMetrics::values[i].load(std::memory_order_relaxed); |
| 79 | |
| 80 | std::string metric_name{CurrentMetrics::getName(static_cast<CurrentMetrics::Metric>(i))}; |
| 81 | std::string metric_doc{CurrentMetrics::getDocumentation(static_cast<CurrentMetrics::Metric>(i))}; |
| 82 | |
| 83 | if (!replaceInvalidChars(metric_name)) |
| 84 | continue; |
| 85 | std::string key{current_metrics_prefix + metric_name}; |
| 86 | |
| 87 | writeOutLine(wb, "# HELP", key, metric_doc); |
| 88 | writeOutLine(wb, "# TYPE", key, "gauge"); |
| 89 | writeOutLine(wb, key, value); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (send_asynchronous_metrics) |
| 94 | { |
| 95 | auto async_metrics_values = async_metrics.getValues(); |
| 96 | for (const auto & name_value : async_metrics_values) |
| 97 | { |
| 98 | std::string key{asynchronous_metrics_prefix + name_value.first}; |
| 99 | |
| 100 | if (!replaceInvalidChars(key)) |
| 101 | continue; |
| 102 | auto value = name_value.second; |
| 103 | |
| 104 | // TODO: add HELP section? asynchronous_metrics contains only key and value |
| 105 | writeOutLine(wb, "# TYPE", key, "gauge"); |
| 106 | writeOutLine(wb, key, value); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (send_status_info) |
no test coverage detected