Monitor windows process with Grafana infinity datasource

grafana_process_monitor

Monitor windows process with Grafana infinity datasource

  • Grafana can generate alerts by periodically monitoring a datasource based on user-defined conditions.
  • This alerting capability enables continuous monitoring of Windows processes in Grafana.
  • A Windows batch script, as shown below, can produce a CSV file with timestamps and status updates of the desired program.
@echo off

@rem process_monitor.bat

set processName=notepad.exe

@REM run command to check if process is running
for /f "delims=" %%i in ('tasklist /FI "IMAGENAME eq %processName%"') do set cmdRes=%%i

setlocal enabledelayedexpansion
@REM set the flag if process is running
set isOk=0
if NOT "!cmdRes:%processName%=!"=="%cmdRes%" (
    set isOk=1
)
echo %isOk%

@REM derive current UTC timestamp
@REM <https://stackoverflow.com/questions/9871499/how-to-get-utc-time-with-windows-batch-file>
for /f %%x in ('wmic path win32_utctime get /format:list ^| findstr "="') do set %%x

if %Month% lss 10 set Month=0%Month%
if %Day% lss 10 set Day=0%Day%
if %Hour% lss 10 set Hour=0%Hour%
if %Minute% lss 10 set Minute=0%Minute%
if %Second% lss 10 set Second=0%Second%
set curTs=%Year%-%Month%-%Day% %Hour%:%Minute%:%Second%

@REM dump results into file
(
    echo time,val
    echo %curTs%,%isOk%
) > "C:\\app_status.csv"

  • A sample CSV file (C:\app_status.csv) generated by the above script is shown below. This script can be configured in Windows Task Scheduler to update the CSV file at regular intervals.
time,val
2024-10-17 06:58:25,1


  • The csv file can be hosted as a static file from a web server like IIS, Apache or simple python server and made available to Grafana through infinity DataSource. The data flow for real time monitoring of csv file by Grafana is illustrated below

image.png

Setup Infinity Datasource in Grafana

  • Install the infinity datasource plugin in Grafana
  • Create a datasource connection in Grafana as shown below

image.png

Create alert rule in Grafana

  • Create an alert rule in Grafana with the csv URL as shown below

image.png

  • The above alert rule will trigger if value in csv is less than 1. The alert rule can be configured to run at regular intervals, say 5 minutes as shown below

image.png

  • Grafana will generate an alert as shown below when the process is stopped

image.png

Comments