Evgeny Lundberg
04/17/2024, 8:58 AM100 * (1 - (avg by(host_name) (irate(system_cpu_time{state="idle"}[5m]))))SELECThost_name,100 * (1 - avg(system_cpu_time_idle) / avg(system_cpu_time_total)) AS idle_cpu_percentageFROMsignoz_metrics.time_serie_v2WHEREdatetime >= now() - INTERVAL 5 MINUTEGROUP BYhost_nameSrikanth Chekuri
04/18/2024, 3:02 AMEvgeny Lundberg
04/18/2024, 8:35 AMEvgeny Lundberg
04/18/2024, 8:51 AMsystem_cpu_timeSrikanth Chekuri
04/18/2024, 10:26 AMavg_rateEvgeny Lundberg
04/18/2024, 11:16 AMavg_rateSrikanth Chekuri
04/18/2024, 1:17 PMEvgeny Lundberg
04/19/2024, 11:13 AMtop -bn2 | grep '%Cpu' | tail -1 | grep -P '(....|...) id,'|awk '{print "CPU Usage: " 100-$8 "%"}'Evgeny Lundberg
04/19/2024, 1:19 PM100 * (1 - (avg by(host_name) (irate(system_cpu_time{state="idle"}[5m]))))Evgeny Lundberg
04/30/2024, 12:46 PMSELECTs.metric_name,s.timestamp_ms,s.value,JSONExtractString(t.labels, 'host_name') AS host_name,JSONExtractString(t.labels, 'state') AS stateFROMsignoz_metrics.samples_v2 sINNER JOINsignoz_metrics.time_series_v2 tONs.fingerprint = t.fingerprintWHEREs.metric_name = 'system_cpu_time'AND JSONExtractString(t.labels, 'host_name') = 'hostname4'AND JSONExtractString(t.labels, 'state') = 'idle'AND s.timestamp_ms >= (toUnixTimestamp(now() - INTERVAL 5 MINUTE) * 1000)  -- Last 5 minutesORDER BYs.timestamp_ms DESC LIMIT 1;Srikanth Chekuri
04/30/2024, 3:04 PMavg_rate100 * (1-A)Evgeny Lundberg
05/02/2024, 2:13 PMavg_rateSrikanth Chekuri
05/02/2024, 5:40 PMEvgeny Lundberg
05/08/2024, 8:05 AMavg_rateWITH-- Query to get the total CPU time for all hosts that exist in host_infototal_cpu_time AS (SELECTJSONExtractString(t.labels, 'host_name') AS host_name,SUM(s.value) AS total_timeFROMsignoz_metrics.samples_v2 sINNER JOINsignoz_metrics.time_series_v2 tONs.fingerprint = t.fingerprintINNER JOINsignoz_metrics.host_info hi ON JSONExtractString(t.labels, 'host_name') = hi.host_nameWHEREs.metric_name = 'system_cpu_time'AND JSONExtractString(t.labels, 'state') IN ('nice', 'user', 'steal', 'wait', 'system', 'softirq', 'idle')  -- Relevant CPU statesAND s.timestamp_ms >= (toUnixTimestamp(now() - INTERVAL 5 MINUTE) * 1000)  -- Last 5 minutesGROUP BYJSONExtractString(t.labels, 'host_name')),-- Query to get the idle CPU time for all hosts that exist in host_infoidle_cpu_time AS (SELECTJSONExtractString(t.labels, 'host_name') AS host_name,SUM(s.value) AS idle_timeFROMsignoz_metrics.samples_v2 sINNER JOINsignoz_metrics.time_series_v2 tONs.fingerprint = t.fingerprintINNER JOINsignoz_metrics.host_info hi ON JSONExtractString(t.labels, 'host_name') = hi.host_nameWHEREs.metric_name = 'system_cpu_time'AND JSONExtractString(t.labels, 'state') = 'idle'AND s.timestamp_ms >= (toUnixTimestamp(now() - INTERVAL 5 MINUTE) * 1000)GROUP BYJSONExtractString(t.labels, 'host_name'))-- Calculate the CPU usage percentage for all hosts in host_infoSELECThi.host_name AS Host,hi.ip_address AS IP,ROUND(100 * (1 - (ic.idle_time / tc.total_time)), 2) AS cpu_usageFROMtotal_cpu_time tcLEFT JOINidle_cpu_time ic ON tc.host_name = ic.host_nameLEFT JOINsignoz_metrics.host_info hi ON tc.host_name = hi.host_nameWHEREhi.host_name IS NOT NULL  -- Ensure the host_name exists in host_infoORDER BYcpu_usage DESCSrikanth Chekuri
05/08/2024, 8:43 AMavg_rateSigNoz is an open-source APM. It helps developers monitor their applications & troubleshoot problems, an open-source alternative to DataDog, NewRelic, etc.
Powered by