Prometheus QL get the first values from the query result - kubernetes

I write the query below to get the up time for the microvices.
base_jvm_uptime_seconds{kubernetes_name="namepspce1"}
However, it returns multiple values, so the grafana returns "Only queries that return single series/table is supported". I am wondering how can I the first velus from the query result?
I tried base_jvm_uptime_seconds{kubernetes_name="namepspce1"}[0], but it doesn't work..
Thanks!

I suggest you first inspect the label values of these multiple time series by running the query in Prometheus Graph console.
The you'll need to decide which one you want to display. Random first usually isn't the best idea.
But you can always do topk(1,query) if it helps. Just turn the Instant mode on in the Grafana Query editor.

Related

How to filter prometheus series based on the results of another query in grafana dashboard?

I am using Grafana 9.3.1 for monitoring of our system. Among other things, I am trying to monitor the remaining FUP of a phone number for each unit we operate.
Basically, we intend to use two data sources.
Database mapping of the unit ID to its phone number (e.g. "unit_id=123, phone_number="00 123456789")
Prometheus time series remaining_fup{phone_number="00 123456789"}. However, remaining_fup is a 3rd party data and does not include unit_id.
In my unit-detail dashboard I have unit_id variable which indicates which unit FUP should be displayed (among other things depending on unit_id)
My original approach was this:
Create a mixed datasource dashboard
Add database datasource as data A. SELECT phone_number FROM units WHERE unit_id='$unit_id'
Add prometheus datasource remaining_fup and filter it based on A.phone_number: remaining_fup{phone_number="${A.phone_number}"}
Unfortunatelly such use of A isn't supported. I used to hope for applying some transformation like Merge or Join by field and then Filter but with no success. After a lot of googling and trying I feel hopeless.
Could you help please? Is such filter even possible? Thanks!
TL;DR: In grafana dashboard I want to query one datasource in order to obtain a value which I subsequently want to use in another datasource query.
1.) Create variable - name phone_number, type: Query and query your database datasource SELECT phone_number FROM units WHERE unit_id='$unit_id'. You can hide this variable if you don't want it to be visible for the dashboard users.
2.) Variable phone_number may have multiple values, so use advance variable formatting to create valid regex query syntax for your prometheus datasource, e.g.
remaining_fup{phone_number=~"${phone_number:pipe}"}
Of course this queries are just examples and they may need some (syntax) tweaking for the use case. Main idea: don't use 2 queries, but one variable and one query (where you use that variable).

Usage of dashboard variable in queries

I'm fairly new to grafana and I am confused how to solve this elegantly:
I have a custom dashboard variable ["device1", "device2", "device3"].
I know how to use the $(variablename) Syntax to query for the currently selected option.
But in an overview dashboard I want to query for all 3 devices from the variable.
Is there a way to use the actual array instead of the currently selected option in queries?
Or is there any other way that I could define a set of values per org by which I then can query?
Thx

How to create a dropdown variable with tag values in a Grafana dashboard?

I am using Grafana and InfluxDB with K6. My tests are generating data for some metrics and I am always defining a test-wide tag testrunname which is set to a different value every time.
In Grafana, I want to add a variable in my dashboard, and I want it to be one of all the available values so far added for the tests that I run. Basically the dropdown will have to display all the values of tag testrunname available in the database.
Not having much luck so far.
How to achieve this?
The query is:
SHOW TAG VALUES WITH KEY = "testrunname"
From documentation.

How to display a table of results in Grafana

I have a query (using CloudWatch as a data source) that retrieves a dataset that includes a count of certain event types - fields x, y, z | stats count() by x
the result returned by the query (e.g. if I run the query in log insights):
x | count()
-------------
Foo | 16
Bar | 3
(So the aggregation of stats is run in CW Logs). I want to represent this in Grafana in the same way it is shown above, but when I use the query with a table panel, the results are populated into a drop-down selector, and the table only shows 1 row - e.g. Foo 16 and I need to select which row I want to display in the table.
What is the best way to show all results? I'm not sure whether I should be leaving the stats function off the data query and doing the aggregation / count on Grafana side, or if I am using the wrong panel type / visualation and the query is right (looking on which approach would be best here if both are possible).
thanks in advance.
I encountered this same issue with Grafana 7.0.0.
When parsing an arrayed query response using the Grafana "Table" visualization, the drop-down result selector is a feature of the v7+ versions. The Grafana Explore functions apparently use the older table visualization, which is bundled in V7 versions as "table-old". The table-old visualization should return all query results as rows in the table, without a selector.
It is also possible to click on "Inspect" and then click on the JSON tab.
remove the below field from the JSON:
"statsGroups": [
...
]
NOTE 1: it is sometimes annoying that when editing the panel it is added back automatically
UPDATE
A more clean solution (but sometimes limiting) is to use the "Merge" transformation

Grafana worldmap panel with Influxdb

I am struggling to get the worldmap panel working with influxdb.
Can someone explain what I am doing wrong?
I am assuming that you have saved geohash as a tag.
If I run your query in a table panel, then I get two fields in the result called geohash and one of them is empty.
I think you can remove the field(geohash) from the select and get the result you want. (Or remove the last selector or change the alias so that there is no conflict between it and the group by).