Writing an influx query using Join - grafana

I have TIG stacks (Grafana for the dashboard and Influx for the database and my collector is Telegraf).
I need an output where the CPU and memory columns of each server are shown in one row. I expect the following output:
Expected result
I wrote the following code in Grafana using the InfluxQL language:
SELECT last("used_percent") as lastmem ,last("usage_system") as lastcpu FROM "mem" ,"cpu"
WHERE ("province" =~ /^$SelectProvince$/)
--AND ("cpu" = 'cpu-total')
AND $timeFilter
GROUP BY "host"
which gives the following output:
Result now
Can anyone advise how I should rewrite the query?

Related

different results for api request vs manual sql query in postgresql

from the logs in my express server after a request from my front end:
Executing (default): SELECT "id", "associatedModelId", ... , "createdAt", "updatedAt" FROM
"Model" AS "Model" WHERE "Model"."otherModelId" = '11856';
console logging the result:
number of Models found: 0
yet if I cut and paste the same sql code into the psql console, I see the records I am looking for. Likewise, I get the correct results via a Postman request, using the same parameter.
Why can I not get the right outcome from the front end?

Multiple Database on Same Server Join Query in laravel query builder

$employee_attendance =
DB::Connection('sql_srv')
->table('CHECKINOUT')
->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
->leftjoin(DB::Connection('mysql_srv'))
->table('EMPLOYEE', 'USERINFO.CardNo', '=', 'EMPLOYEE.CardID')
->get();
Hi, I had been searching for the solution in the internet for a long time but still I couldn't find the solution, most of the search results is joining on different tables in single database.
I need the solution for different DB::Connection left join and get the query results.
Moreover, all databases are within the same server, if using single connection like DB::connection('sql_srv') or ('mysq_srv') can get the result easily only when join is having issues.

Unable to set Disk usage alert on grafana

In multiple VM machine (15+) I use TIG framework (Telegraf, Influxdb and grafana) to monitoring system stats like (CPU, RAM, Disk etc)
So data is exported via telegraf and stored in InfluxDB which is further use as datasource in Grafana.
The problem I m facing is setting up alert on any system metric
In Query section I uses Raw Query like this
Disk
SELECT last(used_percent) AS PercentageUsed FROM "disk" WHERE
"host" =~ /$server$/ AND "path" = '/' AND $timeFilter GROUP BY
time($interval), "host", "path"
CPU
SELECT mean("usage_user") AS "user" FROM "cpu" WHERE ("cpu" =
'cpu-total') AND host =~ /$server$/ AND $timeFilter GROUP BY
time($interval), host ORDER BY asc
It is my requirement to use variable for simmilar stat data of all VM in one graph
But the problem is I am unable to configure any alert on this query due to Error
Template variables are not supported in alert queries
It does not sound like that is possible per this thread.
This means you will either have to have multiple panels - one per template variable value per panel or use regex instead of the template variable.

Grafana Reference DataSet Variable to Translate Legend Values using Postgres Driver

I have a postgres data-source in Grafana that's normalized which restricts my graph-visualization legend to show only the ID (hash) of my record. I want to make this human-readable but the id -> name mapping is in a different datasource/postgres database.
Grafana supports templating-variables which I think could allow me to load my id -> naming reference data but there isn't clear documentation on how to access the label_values as a reference-table within the postgres driver's query editor.
Is there a way to configure the template variable to load reference data (id -> name) & leverage it to translate my metric/legend ids within the grafana postgres driver?
For Example (pseudo-grafana postgres query editor):
SELECT
$__timeGroupAlias(start,$__interval),
animal_names.__value AS metric,
count(dog.chewed_bones) AS “# bones chewed“
FROM animals.dog dog
JOIN $TEMPLATE_VAR_REF_DATA animal_names ON dog.id = animal_names.__text
WHERE $__timeFilter(start_time)
GROUP BY 1,2
ORDER BY 1,2
Closest answer I found is here but doesn't get into details:
johnymachine's comment # https://github.com/grafana/grafana/issues/1032
I realized the github comment meant use a jsonb aggregate function as a variable like in the following solution:
Dashboard Variable (Type Query): select jsonb_object_agg(id,name) from animal_names;
Grafana Postgres Pseudo-Query:
SELECT
$__timeGroupAlias(start,$__interval),
animal_names::jsonb ->> dog.id::text AS metric,
count(dog.chewed_bones) AS “# bones chewed“
FROM animals.dog
WHERE $__timeFilter(start_time)

How to check the status of long running DB2 query?

I am running a db2 query that unions two very large tables. I started the query 10 hours ago, and it doesn't seem to finish yet.
However, when I check the status of the process by using top, it shows the status is 'S'. Does this mean that my query stopped running? But I couldn't find any error message.
How can I check what is happening to the query?
In DB2 for LUW 11.1 there is a text-based dsmtop utility that allows you to monitor the DB2 instance, down to individual executing statements, in real time. It's pre-11.1 equivalent is called db2top.
There is also a Web-based application, IBM Data Server Manager, which has a free edition with basic monitoring features.
Finally, you can query one of the supplied SQL monitor interfaces, for example, the SYSIBMADM.MON_CURRENT_SQL view:
SELECT session_auth_id,
application_handle,
elapsed_time_sec,
activity_state,
rows_read,
SUBSTR(stmt_text,1,200)
FROM sysibmadm.mon_current_sql
ORDER BY elapsed_time_sec DESC
FETCH FIRST 5 ROWS ONLY
You can try this command as well
db2 "SELECT agent_id,
Substr(appl_name, 1, 20) AS APPLNAME,
elapsed_time_min,
Substr(authid, 1, 10) AS AUTH_ID,
agent_id,
appl_status,
Substr(stmt_text, 1, 30) AS STATEMENT
FROM sysibmadm.long_running_sql
WHERE elapsed_time_min > 0
ORDER BY elapsed_time_min desc
FETCH first 5 ROWS only"