Notification with server name and cpu used percentage

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

Kindly help on this. Thanks for your support.

Hi Team,

please reply

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 }}

Hi @infofcc3 , Thanks for the update.

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.

use group by your query return multip row.

Thanks for the info @infofcc3

where i need to mention group by?

Below mentioned detailed alert A configuration for reference. Rule B and detailed alert attached here.

Alert Rule:

A

– 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:

  1. Query A → multiple series (per host)
  2. Expression B:
  • Reduce
  • Function: last()
  1. 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

Hi @infofcc3 ,

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;

  1. Query A → multiple series (per host) —> where i need to mention?

  2. Expression B:

  3. Expression C
     

Where i need to add this Query?

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

please suggest this..

Thanks for the quick response..

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

Hi @infofcc3 ,

Thanks for the quick response, Could you please schedule call better clarification?