I’m writing ifHCOutOctets & ifHCInOctets values from two routers into a single influxdb table using telegraf. my requirement is to show aggregate traffic from one interface from router 1 & one interface from router 2. How can i do that in grafana or using influxdb query ?
This is my query for a single interface in a single router:
SELECT non_negative_derivative(mean("ifHCOutOctets"), 1s) *8 / 1000000000, non_negative_derivative(mean("ifHCInOctets"), 1s) *8 / 1000000000 FROM "HuaweiRouter" WHERE ("agent_host" = '10.24.1.X' AND "Interface" = 'Eth-Trunk32') AND $timeFilter GROUP BY time($__interval), "Interface" fill(null)
Screenshot of query
Related
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.
I've started shipping traefik access logs (in JSON) to Grafana Loki and wanted to visualize the top 3 ClientHosts.
This is the LogQL I have written for this but it returns all ClientHosts for the selected time range instead of only the top 3.
What am I missing?
topk(3, sum by (ClientHost)(count_over_time({filename="/var/log/traefik/access-json.log"}|json[5m])))
Are you using the "Explore" on Grafana? Do not forget to select the following option:
Query type = Instant
In a Grafana dashboard panel, I have two queries:
rate(container_cpu_usage_seconds_total{cloud=~"${cloud}",environment=~"${environment}",location=~"${location}",container="tlm-telemetry-service",namespace="tlm"}[5m])
and
avg(kube_pod_container_resource_limits_cpu_cores{namespace="tlm"})
which can be shown well separately:
But when I try to use the "avg" one to divide the "rate" one:
rate(container_cpu_usage_seconds_total{cloud=~"${cloud}",environment=~"${environment}",location=~"${location}",container="tlm-telemetry-service",namespace="tlm"}[5m])/avg(kube_pod_container_resource_limits_cpu_cores{namespace="tlm"})
the result shows "no data".
This query used to work in Grafana Version 6.7.5, but when I tried to move it to Grafana Cloud, this problem happened.
Any one has any idea?
This throws a No data because you have two different expression data types. On the left side, you have a range vector and the right side scalar type. The query should return the same LabelSet in each part, so you need to group the right side also with the by clause.
E.g. the following query should work:
sum by (namespace,container) (rate(container_cpu_usage_seconds_total{cloud=~"${cloud}",environment=~"${environment}",location=~"${location}",container="tlm-telemetry-service",namespace="tlm"}[5m])) /
avg by (namespace,container) (kube_pod_container_resource_limits_cpu_cores{namespace="tlm"})
How does one add a where clause in PromQL?
I'm trying to construct a query that displays when an application running in Kubernetes has been up for more than one minute but I want to filter by namespace.
This is what my query looks like at the moment
100 * (count(up == 1) BY (job, namespace, service) ) > 1
This works fine but it gives me additional information that I don't need.
{job="prometheus-grafana", namespace="monitor", service="prometheus-grafana"}
{job="jenkins", namespace="jenkins", service="jenkins"}
{job="kube-state-metrics", namespace="monitor", service="prometheus-kube-state-metrics"}
{job="node-exporter", namespace="monitor", service="prometheus-prometheus-node-exporter"}
{job="kubelet", namespace="kube-system", service="prometheus-kube-prometheus-kubelet"}
{job="apiserver", namespace="default", service="kubernetes"}
What I'm trying to accomplish is to get results for only the jenkins and default namespace.
{job="apiserver", namespace="default", service="kubernetes"}
{job="jenkins", namespace="jenkins", service="jenkins"}
I've tried doing
100 * (count(up == 1) BY (job, namespace, service) ) > 1 and ON {namespace="jenkins"}
But I get an invalid parameter "query": 1:65: parse error: unexpected "{" in grouping opts, expected "(" error.
You would have to filter the metric "up" by the labels you want (namespaces) in your case it should look something like this:
100 * count(up{namespace=~"default|jenkins"} == 1) > 1
You can try this too. In Kubernetes all resources uses pod. So if you take pod status metrics and minus current time with 60, which gives post 1 min pods running status.
time()-60 > (kube_pod_start_time)
Prometheus provides the following ways for filtering the data in queries:
Time series selectors. They allow filtering time series by metrics and labels. For example, up{namespace=~"default|jenkins"} is a series selector, which returns only time series with the name up, which contain label namespace matching the given given regular expression: default|jenkins. This is roughly equivalent to the following SQL:
SELECT * FROM table WHERE name = 'up' and namespace ~ '^(default|jenkins)$'
Comparison operators, which allow filtering time series by values. For example, up == 0 returns time series with up name, which have 0 value. This is roughly equivalent to the following SQL:
SELECT * FROM table WHERE name = 'up' and value == 0
Time series matching via binary operators. This allows performing join-like queries. For example, up * on(instance) group_left(name) node_os_info joins up metric with node_os_info metric via instance label and selects additional name label from node_os_info metric. This is roughly equivalent to the following SQL:
SELECT up.*, node_os_info.name
FROM up LEFT JOIN node_os_info ON (instance)
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)