Script to tune/debug RRD files on windows console

Post support questions that relate to the Windows 2003/2000/XP operating systems.

Moderators: Developers, Moderators

Post Reply
lazna
Posts: 7
Joined: Tue Nov 22, 2011 2:16 pm

Script to tune/debug RRD files on windows console

Post by lazna »

Dealing with strange numbers in RRD file, wrote this script to easier read `rrdtool fetch`output. Hope this could help to somone alse.

Code: Select all

@echo off & setlocal ENABLEDELAYEDEXPANSION
::
:: This script translate output of command 'rrdtool fetch' to non-scientific
:: (human readable) numbers format. Its purpose is to help debug rrd database
:: creation/updates from windows console.
:: It handle 'no data' [NaN/IND] by converting them to zero values. If you need 
:: distinct between value zero and NaN, cou _CAN`T_ you this script. Maximal 20
:: data sources are supported.  
::
:: Usage: rrd_fetch.cmd <filename> <seconds>
:: <filename> specify name of your RRD database file [path is specified in variable]
:: <seconds> parameter specify time period you want to display data for 
::
:: Script requires date.exe [rename to edate.exe here to avoid conflict with windows
:: date command] utility from Gnuwin package, fprint.exe and rrdtool.exe
:: Check following links:
::
:: http://gnuwin32.sourceforge.net/downlinks/coreutils-bin-zip.php
:: https://www.dostips.com/forum/viewtopic.php?f=3&t=7312#p48055
:: https://github.com/oetiker/rrdtool-1.x/releases
::
set "rrdtool=C:\Inetpub\monitoring_test\utilities\rrdtool\rrdtool.exe"
set "rrdfile=X:\RRD\DEVICES\%~1"
::
set "ind=-1.#IND000000e+000"
set "zero=0.000000000e+000"
::
set "item=%%8.2f"
::
if "%~1"=="" (
			echo Parameter missing
			echo Usage: rrd_fetch.cmd ^<filename^> ^<seconds^>
			exit /B
			)
::
REM == Read data sources counts from given RRD file ============================
for /f %%a in ('
			%rrdtool% info %rrdfile% ^| findstr /B "ds[" ^| find /C "ds"
			') do (
REM == Set data sources total count, minus one compensate inital 'set item=' ===
			set /a "ds_cnt=(%%~a/8)-1"
			)
REM == Check if number od data sources does not crossing limit =================
if %ds_cnt% GTR 20 (
			echo Program support maximal 20 datasources per single RRD file
			exit /B
			)
::
REM == Generate fprint pattern according to data sources count ================= 
for /l %%A in (1,1,%ds_cnt%) do set "items=!items!,%%8.2f"
::
for /F "skip=1 tokens=1-21 delims=: " %%a in ('
			%rrdtool% fetch %rrdfile% AVERAGE -s -%~2s -e now
			') do (
REM == Compuate time from RRD timestamp ========================================
			for /f %%a in ('edate "+%%H:%%M:%%S" -d@%%~a') do set "datetime=%%~a"
REM == Replace possible NaN/IND by zero value ================================== 
			if "%%~b"=="%ind%" (set "b=%zero%") else (set "b=%%~b")
			if "%%~c"=="%ind%" (set "c=%zero%") else (set "c=%%~c")
			if "%%~d"=="%ind%" (set "d=%zero%") else (set "d=%%~d")
			if "%%~e"=="%ind%" (set "e=%zero%") else (set "e=%%~e")
			if "%%~f"=="%ind%" (set "f=%zero%") else (set "f=%%~f")
			if "%%~g"=="%ind%" (set "g=%zero%") else (set "g=%%~g")
			if "%%~h"=="%ind%" (set "h=%zero%") else (set "h=%%~h")
			if "%%~i"=="%ind%" (set "i=%zero%") else (set "i=%%~i")
			if "%%~j"=="%ind%" (set "j=%zero%") else (set "j=%%~j")
			if "%%~k"=="%ind%" (set "k=%zero%") else (set "k=%%~k")
			if "%%~l"=="%ind%" (set "l=%zero%") else (set "l=%%~l")
			if "%%~m"=="%ind%" (set "m=%zero%") else (set "m=%%~m")
			if "%%~n"=="%ind%" (set "n=%zero%") else (set "n=%%~n")
			if "%%~o"=="%ind%" (set "o=%zero%") else (set "o=%%~o")
			if "%%~p"=="%ind%" (set "p=%zero%") else (set "p=%%~p")
			if "%%~q"=="%ind%" (set "q=%zero%") else (set "q=%%~q")
			if "%%~r"=="%ind%" (set "r=%zero%") else (set "r=%%~r")
			if "%%~s"=="%ind%" (set "s=%zero%") else (set "s=%%~s")
			if "%%~t"=="%ind%" (set "t=%zero%") else (set "t=%%~t")
			if "%%~u"=="%ind%" (set "u=%zero%") else (set "u=%%~u")
			if "%%~v"=="%ind%" (set "v=%zero%") else (set "v=%%~v")										
REM == Print human readable time =============================================== 
			<nul set /p= !datetime!
REM == Print data itself translated from 'acientific notation' =================
			@printf.exe "%%8.2f%items% \n" !b! !c! !d! !e! !f! !g! !h! !i! !j! !k! !l! !m! !n! !o! !p! !q! !r! !s! !t! !u!
			)
exit /B
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests