Send RAM usage from BAT file in Windows

This is an example of sending the RAM usage from a Windows machine using a BAT file. It retrieves the RAM usage 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=933jpw1TEtPscRQRoLvrpE
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=1,2 delims==" %%A in ('wmic OS get FreePhysicalMemory^,TotalVisibleMemorySize /Value ^| findstr "="') do (
    if "%%A"=="FreePhysicalMemory" set FREE_MEM_KB=%%B
    if "%%A"=="TotalVisibleMemorySize" set TOTAL_MEM_KB=%%B
)

set /a FREE_MEM_MB=%FREE_MEM_KB% / 1024
set /a TOTAL_MEM_MB=%TOTAL_MEM_KB% / 1024
set /a USED_MEM_MB=%TOTAL_MEM_MB% - %FREE_MEM_MB%

set /a MEM_PERCENT=(%USED_MEM_MB% * 100) / %TOTAL_MEM_MB%

echo RAM: %USED_MEM_MB% MB / %TOTAL_MEM_MB% MB (%MEM_PERCENT%%%)

set VALUE_Main=!USED_MEM_MB!
set VALUE_Main_Name="MEM%%20Load"
set VALUE_Main_UOM="MB"

set VALUE_Percent=!MEM_PERCENT!
set VALUE_Percent_Name="MEM%%20Load%%20(%%25)"
set VALUE_Percent_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!"
set CMD=!CMD! -d "/Percent=!VALUE_Percent!"
set CMD=!CMD! -d "/Percent/_name=!VALUE_Percent_Name!"
set CMD=!CMD! -d "/Percent/_uom=!VALUE_Percent_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_mem_usage.bat.
  2. Replace the placeholder API key (933jpw1TEtPscRQRoLvrpE) 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_mem_usage.bat) and pressing Enter.
  5. The script will start sending RAM usage data to Gazer Cloud every second. You can stop it by pressing Ctrl+C.
Copyright © 2020-2025 Gazer.Cloud Authors. All rights reserved.