Getting hostnames instead of IP as the legends of Graph

Using prometheus as my DataSource. The legends displayed are the IPs, but I want hostnames as I am monitoring over 100 servers and it is just not possible to keep track of them using their IPs.


I have tried many different combination of varibales in the Legend Format but nothing has worked.