client_java
client_java copied to clipboard
Equivalent usage of Simpleclient in micrometer-registry-prometheus `1.13.x`
Hi Team! We are migrating our project from micrometer-registry-prometheus:1.12.8 to version 1.13.8 . I see that the io.prometheus:simpleclient:jar:0.16.0 has been deprecated.
We have few scenarios which I do not see in the migration guide.
Here are few scenarios,
- What is the equivalent of
io.prometheus.client.Collector.MetricFamilySamplesand theMetricFamilySamples.Sample
PrometheusMeterRegistry instance = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
MetricFamilySamples samples = instance.getPrometheusRegistry().metricFamilySamples()
if (sample == null || sample.name == null || sample.labelNames == null || sample.labelValues == null) {
LOGGER.error("The provided Sample object is either null or one of its fields is null: {}", sample);
throw new IllegalArgumentException("The provided Sample object is either null or one of its fields is null: " + sample);
}
- Is the import
io.prometheus.metrics.model.registry.Collectora replacement ofio.prometheus.client.Collector, however, I couldn't find the below in the new Collector.
Enumeration<Collector.MetricFamilySamples> metricFamilySamples;
- Similarly how we can replace the
io.prometheus.client.exporter.common.TextFormat?
Could you please help me with the code changes. Also, can you share any additional docs available that we can follow for migrating from the usage of simpleclient.
Hi @siddhant16, could you provide more context on what you would like to achieve?
MetricFamilySamples samples = instance.getPrometheusRegistry().metricFamilySamples()
Sounds like you are manually collecting metrics in code. I'm wondering why you do that rather than just using Micrometer to expose a Prometheus endpoint?
Thank you for the response. So, the MetricFamilySamples that are collected in the above code is to be used for custom metric generation and filtering. We filter the provided MetricsFamilySamples with the endpoint processor and also generate additional metrics for provided PrometheusMetrics using provided MetricFamilySample.
Using the MetricFamilySamples to apply filtering,
...
...
TextFormat.writeFormat(TextFormat.CONTENT_TYPE_004, writer,
applySourceFiltering(configToProcessor, metricsFamilySamples));
Hi @fstab In addition to above I also wanted to know how we can get the names based on the type of metric, the MetricFamilySamples use to have getNames() like below,
public String[] getNames() {
switch (this.type) {
case COUNTER:
return new String[]{this.name + "_total", this.name + "_created", this.name};
case SUMMARY:
return new String[]{this.name + "_count", this.name + "_sum", this.name + "_created", this.name};
case HISTOGRAM:
return new String[]{this.name + "_count", this.name + "_sum", this.name + "_bucket", this.name + "_created", this.name};
case GAUGE_HISTOGRAM:
return new String[]{this.name + "_gcount", this.name + "_gsum", this.name + "_bucket", this.name};
case INFO:
return new String[]{this.name + "_info", this.name};
default:
return new String[]{this.name};
}
}
@fstab Do you know if there is a plan to migrate from the deprecated simpleclient to 1.X (https://prometheus.github.io/client_java/)? Thank you.