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

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).

Related

Grafana is that possible to map prometheus label values according to another key-value pair variable?

I have a prometheus metric like this:
lines_added{project="xx",user="xx"}
the project label and user label are integer ids, not good for legend on graph.
and I have another variable members as query from postgresql datasource:
select u.id as __value,u.name as __text
from project_authorizations pa left join users u
on pa.user_id = u.id
where pa.project_id=[[project]]
now for the lines_added metric how can I make it display user's real name according "id"->"name" mapping in variable members
Is that possible with grafana?
Would it perhaps work if you stashed the SQL mappings into a variable and then perform some combination of label_replace regex magic on Prometheus query? At least that's how you get mappings into Prometheus world. But from there, I am yet to figure out how to pull it off in bulk. How many IDs you need to map?

How to filter dashboard based on quick filter values selected in Tableau ?

I'm having Dashboard-1 with the data source from SQL Server Table-A having columns
Col1,Col2,Col3
Now, i'm creating a new dashboard-2 with data source as Table-B having columns Col1,Col4,Col5.
But Col1 which is common in both these tables doesn't have common data.
Eg. Col1 from Table-A is having records till 100 and Table-B is having records from 101.Also, the data is not static, its keeps on increasing in Table-B , Table-A is no longer populating but we need the data from it.
Problem1-- How to merge two column as single column for filter in Tableau
Problem2-- in the dashboard i need to show single filter as a union of Col1 from both tables, if user select value <100 then Dashboard-1 will open otherwise Dashboard-2.
Can someone provide me a correct approach.
1) Instead of merging after you have brought the data in, try merging the data using SQL UNION.
2) If that's not possible, do the same after importing both the datasets into Tableau. For an example, try from this official link
3) Try different Joins to see which one works for merging your table columns:
4) If all the above fails, try setting up an Action Filter explained in this link. Essentially you have to use Tiled Containers instead of Floating Containers and set up a action filter using a custom Parameter. This custom Parameter will help display Dashboard 1 when user selects <100 in the filter(for example) and Dashboard 2 when user selects >100(again example)

Prioritise which identifier to use

My crystal report pulls data about books, including an identifier (isbn, issn order number etc.), author, and publisher.
The ID field stores multiple ways to identify the book. The report displays any of the identifiers for that record. If one book has two identifiers; issn and order number, the report currently displays one apparently at random.
How can I make it prioritise which type to use based on a preset order? I figured some sort of filter on the field could work, but I haven't figured out how. I can't edit the table, but I can use SQL within the report.
If all the different types of ID are stored in a single field, your best bet is to use a SQL Command inside your report to separate them into multiple virtual fields.
Go to Database Fields / Database Expert, expand the connection you want to use, and pick Add Command. From here you can write a custom SQL statement to grab the information you're currently using, and at the same time separate the ID field into multiple different fields (as far as the report will be concerned, anyway. The table will stay unchanged.)
The trick is to figure out how to write your command to do the separation. We don't know what your data looks like, so you're on your own from here.
Based on the very little information that you have provided and if i was to make a guess.I suggest you make use of the formula field in your report and then use something like this to accomplish your goal.
IF ISNULL{first_priority_field_name} OR {first_priority_field_name} = '' THEN
{second_priority_field_name}
ELSE
{first_priority_field_name}
Use nested IF statement in case there are more than 2 identifier fields.

How to create table occurrences for filtered data..?

I have a table called transactions. Within that is a field called ipn_type. I would like to create separate table occurrences for the different ipn types I may have.
For example, one value for ipn_type is "dispute". In the past I would create a global field called "rel_dispute" and I would populate that with the value of "dispute". Then I could create a new table occurrence of the transactions table, and make a relationship based on transactions::ipn_type = transactions::rel_dispute. This way only the dispute records would show up in my new table occurrence.
Not long ago, somebody pointed out to me that this is no longer necessary, and there is a simpler way to setup such a relationship to create a new table occurrence. I can't for the life of me remember how that was done, though.
Any information on this would be greatly appreciated. Thanks!
To show a found set of only one type, you must either perform a find or use the Go to Related Record script step to show only related records. What you describe as your previous setup fits the latter.
The simpler way is to perform a find - either on demand, or by a script triggered OnLayoutEnter.
The new 'easy' way is probably:
using one base relationship only and
filtering only the displaying portal by type. This can be done with a global field, a global variable containing current display type. Multiple portals with different filter conditions are possible as well.
~jens

Two SQL query inside single JasperReport and populating Data

We are using reports in our web application.
The report is generated using JasperReports.
The problem I am facing is:
My SQL query fetches data based on a where clause:
SELECT * FROM table WHERE level='c'
I can easily show this information inside the iReport.
But I need to fire another query where level='d' and the information for the same needs to be appended to the report with that of level='c'.
I tried grouping both the outputs. But problem is how do I fire two different query while generating the report because I can write only one query in QueryBuilder inside the iReport.
Is there anyway of achieving the same.
In essence:
The report should look like:
Level=C
Name Age Phone number
Level=D
Name Age Phone number
Level D should appear only after level c is completed.
Can anyone please guide.
I finally managed to achieve the same..Grouping the data using level_id..
Initially I was trying to group in a different manner and hence the value was not getting shown..
The same is explained pretty nicely in ireport Ultimate guide-3 document.