Hi,
On 12/7/19 10:27 PM, sunil sagar wrote:
> I need additional metrics in prometheus based on the instance name . My
> current instance name is as below :
>
> servername1.doman.com:port1
> servername1.doman.com:port2
> servername1.doman.com:port3
>
> I want to relabel instance name so that I can draw dashboard by instance
> (servername1 - combined)
What exactly do you want to do? Do you want to strip the port, i.e. turn
instance="servername1.doman.com:port1" into
instance="
servername1.doman.com"?
(I assume you checked that your metrics will remain unique despite this
change)
You can accomplish that by overriding the instance label in your service
discovery or by using relabeling.
> I tried below relabelling in yml file but it didn't worked out . Please
> help . Thanks
>
>
> metric_relabel_configs:
> - source_labels: [instance]
> regex: '/system.slice/var-lib-docker-containers.*-shm.mount'
> action: replacereplace: $1target_labels: host
I don't know what your metrics look like, but your regex sounds like
they could come from cadvisor and you are trying to extract container
names from cgroup names.
Your example looks almost good. However, in order to be able to
reference the $1 variable, you have to tell Prometheus what this should
refer to. You use this by placing brackets around the part you are
interested in. E.g.:
regex: '/system.slice/var-lib-docker-containers(.*)-shm.mount'
However, to provide semantically more thorough advice, we would need
some more context.
Kind regards,
Christian