MCPcopy Create free account
hub / github.com/ByConity/ByConity / write

Method write

src/Server/PrometheusMetricsWriter.cpp:53–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51}
52
53void 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)

Callers 13

finishHandshakeMethod · 0.45
handleRequestMethod · 0.45
runImplMethod · 0.45
sendProfileInfoMethod · 0.45
sendTotalsMethod · 0.45
sendExtremesMethod · 0.45
receiveDataMethod · 0.45
sendDataMethod · 0.45
sendLogDataMethod · 0.45
sendProgressMethod · 0.45

Calls 10

writeCharFunction · 0.85
writeDoubleQuotedStringFunction · 0.85
replaceInvalidCharsFunction · 0.70
writeOutLineFunction · 0.70
endFunction · 0.50
getNameFunction · 0.50
getDocumentationFunction · 0.50
writeTextFunction · 0.50
loadMethod · 0.45
getValuesMethod · 0.45

Tested by

no test coverage detected