I create a dashboard using grafana and prometheus. All is working fine and the metrics is correct.
Now, I just need to show the hostname instead IP on dashboard.
For now, I have this variable that is showing the just the IP:
And its show in the dashboard like that:
Could you please help me understand how I can do it or provide a guide?
Thank you for the help!
If you’re giving only the IP address in the node exporter’s configuration, that’s what it’s going to show in the instance. You can either change it to hostname, or you can add a label which contains hostname for each of your IP.
Typical Node Exporter configuration which shows IP:
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['<node-exporter-ip>:9100']
Hi,
I came up with something like this (it might be a bit complex though).
Instead of using Label values
query type, use Query result
. Type in the query you’d like to use (in your case it might be count({instance=~".+"}) by (instance, hostname)
by I would use some metric, if that’s possible to limit the number of series returned, as I guess all series would have instance labels. The by (...)
part depends on your labels - one is instance and the other one (the friendly one containing the hostname) I’m assuming is named hostname
(if not, change accordingly). You will receive this kind of values:
{hostname="<name>",instance="<IP>"} <value> <timestamp>
now you can use regex field (right below the query) to type in the following regex:
/.*hostname="(?<text>(.*?))",instance="(?<value>(.*?))".*/
what it will do is it will display the value of hostname for the users to pick but variable will resolve to instance IP. Also notice that the order of the labels is important (e.g. if you’ll have {instance="<IP>",hostname="<name>"} <value> <timestamp>
as the query result before applying regex, the regex will have to be reversed, i.e. /.*instance="(?<value>(.*?))",hostname="(?<text>(.*?))".*/
).
Worked for me (at least I hope I got you right
), here’s a piece of documentation.