Glad it's working. A couple of ideas:

(1) You said *"Put another way I was looking for  'a list of unique values 
for the key "instance""*

The simplest way to do that is to query 'up' or 'up{job="foo"}'.  This is a 
metric synthesised by Prometheus with one entry for every scrape, and hence 
every job/instance combination.  It also tells you whether the scrape was 
successful or not.

(2) In general, it's a good idea to keep the port number out of the 
instance label in the first place, even though Prometheus puts it there by 
default if you don't set the instance label explicitly.

Apart from making dashboards and the like clearer, it makes it much easier 
to write join queries which combine the results of different exporters on 
the same host.

https://www.robustperception.io/controlling-the-instance-label
https://groups.google.com/forum/#!topic/prometheus-users/I4dVtwI5YrM
https://groups.google.com/forum/#!msg/prometheus-users/PPwF-2CQiSc/FsSvfCm3AwAJ

On Thursday, 24 August 2023 at 21:05:02 UTC+1 Richie wrote:

> came up with the following
> label_replace(group by (instance) (agent_build_info), "instance", '$1', 
> "instance", '(.+):12345')
>
> On Thursday, August 24, 2023 at 3:37:40 PM UTC-4 Richie wrote:
>
>> Brian your suggestions ultimately helped as it introduced me a new 
>> concept.  I don't think I conveyed what I wanted properly.   Put another 
>> way I was looking for  'a list of unique values for the key "instance".  
>> Still not sure if that's the best way to articulate it.
>>
>> Based on your suggestions this is what I came up with
>> group by (instance) (agent_build_info)
>>
>> Ideally the port ':12345' could be stripped, but what is generated from 
>> the above is plenty sufficient.
>>
>> Thanks for the help.
>>
>> On Thursday, August 24, 2023 at 2:04:26 PM UTC-4 Brian Candler wrote:
>>
>>> Aha, I just discovered you can do:
>>>
>>> count without (instance, job) (agent_build_info)
>>> group without (instance, job) (agent_build_info)
>>>
>>> That should be what you want :-)
>>>
>>> On Thursday, 24 August 2023 at 18:59:24 UTC+1 Brian Candler wrote:
>>>
>>>> If you are happy to list all the labels of interest (i.e. everything 
>>>> apart from the 'job' and 'instance' labels and any other labels you've 
>>>> added yourself):
>>>>
>>>> count by (goversion,version,branch,revision) (agent_build_info)
>>>>
>>>> Or you can use "group by" instead of "count by" to get a value of 1 for 
>>>> everything (although personally I think the counts are useful!)
>>>>
>>>> On Thursday, 24 August 2023 at 16:05:17 UTC+1 Richie wrote:
>>>>
>>>>> or i suppose i could process the results as they come from the api via 
>>>>> python
>>>>>
>>>>> On Thursday, August 24, 2023 at 10:59:18 AM UTC-4 Richie wrote:
>>>>>
>>>>>> I would like to pull a line by line list of unique instances from 
>>>>>> agent_build_info and save it to a file for the purpose of cross checking 
>>>>>> via script against a list of known instances that should be monitored 
>>>>>> (reporting purposes).
>>>>>>
>>>>>> so in short is it possible to create a query that equivalent of *select 
>>>>>> distinct instance from agent_build_info --(were it a traditional table) *
>>>>>> ?
>>>>>>
>>>>>> -Richie
>>>>>>
>>>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/283cb5c0-d2fc-4d69-8463-a27e8fd459efn%40googlegroups.com.

Reply via email to