Send CPU load from BAT file in Windows

This is an example of sending the CPU load from a Windows machine using a BAT file. It retrieves the CPU load using the built-in Windows command 'wmic' and sends it to Gazer Cloud.

BAT File Code


@echo off
setlocal enabledelayedexpansion
rem === Set your API_KEY below ==========================
set API_KEY=6ruyjBszNj1RvHLNGPDRjT
rem =====================================================

for /f "usebackq tokens=* delims=" %%A in (`curl -s https://gazer.cloud/view_url_by_api_key/%API_KEY%`) do set VIEW_URL=%%A
echo =====================================================
echo View URL:
echo %VIEW_URL%
echo =====================================================
echo Press Ctrl+C to stop sending data.
echo.

:loop

for /f "tokens=* delims=" %%A in ('wmic cpu get loadpercentage ^| findstr /r "^[0-9]"') do (
    set CPU_LOAD_RAW=%%A
)

set CPU_LOAD=%CPU_LOAD_RAW: =%
echo CPU Load: !CPU_LOAD!%%

set VALUE_Main=!CPU_LOAD!
set VALUE_Main_Name="CPU Load"
set VALUE_Main_UOM=%%25

echo Sending time: !VALUE_Main!
set CMD=curl -s -X POST "https://gazer.cloud/set/%API_KEY%"
set CMD=!CMD! -d "/=!VALUE_Main!"
set CMD=!CMD! -d "/_name=!VALUE_Main_Name!"
set CMD=!CMD! -d "/_uom=!VALUE_Main_UOM!"
!CMD!
	
timeout /t 1 >nul
goto loop
        

Instructions

  1. Copy the above BAT file code into a text editor and save it with a .bat extension, e.g., send_cpu_load.bat.
  2. Replace the placeholder API key (6ruyjBszNj1RvHLNGPDRjT) with your actual Gazer Cloud API key.
  3. Open a Command Prompt window and navigate to the directory where you saved the BAT file.
  4. Run the BAT file by typing its name (e.g., send_cpu_load.bat) and pressing Enter.
  5. The script will start sending CPU load data to Gazer Cloud every second. You can stop it by pressing Ctrl+C.
Copyright © 2020-2025 Gazer.Cloud Authors. All rights reserved.