Publish metrics also for metricbeat

This commit is contained in:
Dominik Werder
2023-11-28 15:55:43 +01:00
parent 3ae555565a
commit 71fa333f75
6 changed files with 82 additions and 33 deletions
+32
View File
@@ -152,6 +152,36 @@ fn stats_struct_impl(st: &StatsStructDef) -> String {
"
)
};
let fn_json = {
let mut buf = String::new();
for x in &st.counters {
buf.push_str(&format!(
"ret.insert(\"{x}\".to_string(), Value::Number(Number::from(self.{x}.load())));\n"
));
}
for x in &st.values {
buf.push_str(&format!(
"ret.insert(\"{x}\".to_string(), Value::Number(Number::from(self.{x}.load())));\n"
));
}
for x in &st.histolog2s {
buf.push_str(&format!("let v = self.{x}.to_json(\"__dummyname__\");\n"));
buf.push_str(&format!("ret.insert(\"{x}\".to_string(), v);\n"));
}
format!(
"
pub fn json(&self) -> stats_types::serde_json::Value {{
use serde_json::Map;
use serde_json::Number;
use serde_json::Value;
use stats_types::serde_json;
let mut ret = Map::new();
// {buf}
Value::Object(ret)
}}
"
)
};
let fn_snapshot = {
let mut init_counters = String::new();
for x in &st.counters {
@@ -193,6 +223,8 @@ impl {name} {{
{fn_prometheus}
{fn_json}
{fn_snapshot}
}}