How to create Drop Down metrics(Legend)

Hi Support Team,

I am using the following Query ,

select collection_date AS time , count(cpu) AS “payment”
from host
where host_name=‘payment’
group by collection_date
order by 1

++ Using Add Query , i have added same query 10 time with different host_name

The graph os showing perfectly with 10 lines , But i want metrics should be in Drop-Down list , so that i can select what ever server i want and ‘ALL’ option if required.

I am using Postgres as a DataSource.

Thanks in Advance