I want to configure the alerts with custom email templates
We need to receive the notification with server name and CPU used percentage from the Grafana alert - We have used inbuilt OLVM Grafana for Monitoring
As per the inbuilt OLVM used Ovirt Data Warehouse + Grafana, I hope VDSM is metrics collector. Kindly suggest the exact label name for the environment. Kindly help on this
Correct Label Identify may be host or vds_name
Best Practice Alert Template
Summary:
High CPU usage on {{ $labels.host }}
Description:
Host: {{ $labels.host }}
CPU Usage: {{ printf “%.2f” $values.B }} %
Time: {{ $labels.name }}
we have tried as you mentioned the above Alert template used with labels.host, labels.host_name,labels.vds_name, but still getting error, please find attached screenshot for reference.
– This report returns for all hosts in the data source
– the cpu and memory usage rate over time.
– CPU usage
SELECT DISTINCT
$__time(sub_query.time),
COALESCE ( host_name, MAX ( host_name ) over ( partition BY 1 ), ‘’ ) AS host_name,
CPU_Usage
FROM
(
SELECT
samples.host_id,
host_name,
samples.history_datetime AS time,
SUM ( COALESCE ( samples.cpu_usage_percent, 0 ) * COALESCE ( samples.minutes_in_status, 0 ) ) /
SUM ( COALESCE ( samples.minutes_in_status, 0 ) ) AS CPU_Usage
FROM
(
SELECT history_datetime, host_id, cpu_usage_percent, minutes_in_status
FROM v4_4_statistics_hosts_resources_usage_samples
WHERE host_status = 1
) AS samples
INNER JOIN v4_4_configuration_history_hosts
ON
(
v4_4_configuration_history_hosts.host_id = samples.host_id
AND delete_date ISNULL
)
WHERE
samples.history_datetime >= $__timeFrom()
AND samples.history_datetime < $__timeTo()
– Here we get the latest hosts configuration
AND v4_4_configuration_history_hosts.history_id
IN
(
SELECT MAX ( a.history_id )
FROM v4_4_configuration_history_hosts a
GROUP BY a.host_id
)
GROUP BY samples.host_id, host_name, history_datetime
) AS sub_query
ORDER BY sub_query.time, CPU_Usage DESC
try this
change
GROUP BY samples.host_id, host_name, history_datetime
to
GROUP BY samples.host_id, host_name, samples.history_datetime
host_name ALWAYS present.
Remove duplicate rows – use DISTINCT ON
SELECT DISTINCT ON (host_name, time)
time,
host_name,
CPU_Usage
FROM (
– your subquery
) t
ORDER BY host_name, time, CPU_Usage DESC;
then:
Query A → multiple series (per host)
Expression B:
Reduce
Function: last()
Expression C:
Threshold > 40
Labels properly set
{{ $labels.vds_name }} or {{ $labels.host_name }}
try this
SELECT
$__time(sub_query.time),
sub_query.host_name,
sub_query.CPU_Usage
FROM (
SELECT
samples.host_id,
host_name,
samples.history_datetime AS time,
SUM(samples.cpu_usage_percent * samples.minutes_in_status) /
NULLIF(SUM(samples.minutes_in_status), 0) AS CPU_Usage
FROM v4_4_statistics_hosts_resources_usage_samples samples
JOIN v4_4_configuration_history_hosts h
ON h.host_id = samples.host_id
AND h.delete_date IS NULL
WHERE samples.host_status = 1
AND samples.history_datetime BETWEEN $__timeFrom() AND $__timeTo()
GROUP BY samples.host_id, host_name, samples.history_datetime
) sub_query
ORDER BY time
I have modified the Alert A, please check and confirm
Alert A
GROUP BY samples.host_id, host_name, samples.history_datetime
host_name ALWAYS present.
SELECT DISTINCT ON (host_name, time)
time,
host_name,
CPU_Usage
FROM
(
SELECT
samples.host_id,
host_name,
samples.history_datetime AS time,
SUM ( COALESCE ( samples.cpu_usage_percent, 0 ) * COALESCE ( samples.minutes_in_status, 0 ) ) /
SUM ( COALESCE ( samples.minutes_in_status, 0 ) ) AS CPU_Usage
FROM
(
SELECT history_datetime, host_id, cpu_usage_percent, minutes_in_status
FROM v4_4_statistics_hosts_resources_usage_samples
WHERE host_status = 1
) AS samples
INNER JOIN v4_4_configuration_history_hosts
ON
(
v4_4_configuration_history_hosts.host_id = samples.host_id
AND delete_date ISNULL
)
WHERE
samples.history_datetime >= $__timeFrom()
AND samples.history_datetime < $__timeTo()
– Here we get the latest hosts configuration
AND v4_4_configuration_history_hosts.history_id
IN
(
SELECT MAX ( a.history_id )
FROM v4_4_configuration_history_hosts a
GROUP BY a.host_id
)
ORDER BY host_name, time, CPU_Usage DESC;
Query A → multiple series (per host) —> where i need to mention?
try this
SELECT
$__time(sub_query.time),
sub_query.host_name,
sub_query.CPU_Usage
FROM (
SELECT
samples.host_id,
host_name,
samples.history_datetime AS time,
SUM(samples.cpu_usage_percent * samples.minutes_in_status) /
NULLIF(SUM(samples.minutes_in_status), 0) AS CPU_Usage
FROM v4_4_statistics_hosts_resources_usage_samples samples
JOIN v4_4_configuration_history_hosts h
ON h.host_id = samples.host_id
AND h.delete_date IS NULL
WHERE samples.host_status = 1
AND samples.history_datetime BETWEEN $__timeFrom() AND $__timeTo()
GROUP BY samples.host_id, host_name, samples.history_datetime
) sub_query
ORDER BY time
hello @petchimuthup please check the table view data , check the labels, query cross check , in my case i used prometheus datasource where metrices come and alert discription show correct value.
thanks