powershell_ise my RRD

Why ?

We looked for a way to add punctually and easily new monitoring, but, nothing that justify to add it in cacti or else. However, the idea of ​​re-use “cacti-like graphs” has naturally imposed. In order to facilitate the use of RRDTool, we started to write a small powershell module PSH-RRDTool.

Prerequisite

You must have an installation of “RRDTool for windows” to use this module, this distribution really fits our need : RRDTool For Windows

Note

Warning, this module is functional for basic needs, however it is far from completed neither it allows to use all rrdtool possibility

Create a new Round Robin Database

To create a new RRD, this module export 3 functions :

  • New-RRD
  • Create a new RRD

  • New-DataSource
  • Return a object representing a new DataSource

  • New-RRA
  • Return a object representing a new RRA.

#multiligne
$ds = @(New-DataSource -dsname rtt -Max 2000)
$rra = @( (new-rra -type MIN ),(new-rra -type MAX ),(new-rra -type AVERAGE ) )
$rrd =New-Rrd -filename ping.rrd -step 300 -ds $ds -rra $rra
#oneliner
$rrd =New-Rrd -filename ping.rrd -step 300 -ds@(New-DataSource -dsname rtt -Max 2000) -rra @( (new-rra -type MIN ),(new-rra -type MAX ),(new-rra -type AVERAGE ) )

Update the DataBase

The module export Update-RRD

$ping = New-Object System.Net.Networkinformation.ping
while($true){
	$result = $ping.send('address.example.com')
	Update-Rrd -rrd $rrd -value $result.RoundTripTime
	Start-Sleep -second 300
}

Generate a graph

The module export 4 functions to generate a graph :

  • Get-Graph
  • Generate a graph following entered parameters

  • Get-Graphdef
  • return a new “DEF” string

  • Get-Graphvdef
  • return a new “VDEF” string

  • Get-Graphline
  • Return a string representing a new graph item (LINE1, COMMENT, GPRINT)

$def = @(new-graphdef -rrd $rrd -mesure "rtt" -cf average -name rtt)
$vdef = @( (new-graphvdef -name rtt_max -cf MAX -vname rtt),(new-graphvdef -name rtt_min -cf MIN -vname rtt),(new-graphvdef -name rtt_avg -cf AVERAGE -vname rtt) )
$lines =@( (new-graphline -type 'LINE1' -mesure rtt -color "#000000" -desc "Roudn Trip Time"), 
			(new-graphline -type 'GPRINT' -mesure rtt_max -Format "Max: %3.1lf"),
			(new-graphline -type 'GPRINT' -mesure rtt_min -Format "Min: %3.1lf")
			(new-graphline -type 'GPRINT' -mesure rtt_avg -Format "Avg: %3.1lf")
		)
get-graph -Format PNG -file NASPing.png -title "NAS Ping RoundTripTime" -def $def -vdef $vdef -line $lines

NASPing