Set a variable on legends depends from prometheus query

i’ve a raw result from a query like this :

dovecot_num_logins{ambiente="ambiente_dev", db="ambiente_devtest", host="dovecot.test.local", server="/var/run/dovecot-backend_1/stats-reader", type="global"}

and i want to put on legends for example :
{{host}} backend {{number_backend}} where host is the host from raw result and number_backend is the number 1 from “/var/run/dovecot-backend_1/stats-reader” .
How can i do?
do you’ve some ideas?