Hello, everyone.
I am using a combination of promtail and prometheus to get a custom metric, and I am thinking of using the increment function to handle this.
increase(promtail_custom_metrics_from_promtail{job="sample"}[24h])
My custom metric is of type counter, but as far as I know, counter values start at 1. Because of this, when the custom metric is output for the first time, the increment function does not return 1.
To work around this problem, I also tried or On() vector(0) but it did not give me the desired result because it treats the data series differently.
I think the only way to solve this problem is to output a metric with a value of 0 when there is no log output that matches the condition, but I don’t know how to do it.
Here is the sample config I am using and an example of the desired output.
I would also welcome any solutions other than what I have in mind.
scrape_configs:
- job_name: sample
static_configs:
- targets:
- localhost
labels:
job: sample
__path__: /var/log/sample.log
pipeline_stages:
- regex:
expression: "^(?P<samplelog>hello,world\\.)$"
- metrics:
metrics_from_promtail:
type: Counter
description: "counter metric from promtail"
source: samplelog
config:
action: inc
# HELP promtail_custom_metrics_from_promtail counter metric from promtail
# TYPE promtail_custom_metrics_from_promtail counter
promtail_custom_metrics_from_promtail{filename="/var/log/sample.log",job="sample"} 0