Sometimes I have already e.g. nodes: Vec<Node> in the application state where Node is like
struct Node {
url: String,
requests: AtomicU64,
}
(When you are already working with a &Node, bumping the requests counter is just an atomic inc. It's much more efficient than get_or_create(...).inc().)
And I'd like to expose the requests counter of all nodes as a metric family. It might be possible with the collector API, but it would still require quite some boxing, cloning and iterator mapping.
Instead I'd like to encode the metrics myself, e.g.:
encode_descriptor(&mut buf, ...);
for n in &ctx.nodes {
encode_counter_with_labels(&mut buf, [("node", &n.url)], n.requests.load(...));
}
encode_eof(&mut buf);
This will not require any extra allocation or cloning. By fusing the collecting and encoding phase, metrics can be encoded very efficiently.
Sometimes I have already e.g.
nodes: Vec<Node>in the application state whereNodeis like(When you are already working with a
&Node, bumping the requests counter is just an atomic inc. It's much more efficient thanget_or_create(...).inc().)And I'd like to expose the requests counter of all nodes as a metric family. It might be possible with the collector API, but it would still require quite some boxing, cloning and iterator mapping.
Instead I'd like to encode the metrics myself, e.g.:
This will not require any extra allocation or cloning. By fusing the collecting and encoding phase, metrics can be encoded very efficiently.