Parser script (sample)

All scripts in this page are used with the ACME Humidifier 2140. The script assume that the interrogation was completed according to the interrogation scripts available here.

Hardware Monitoring Script
 

#! META
name: ssh-hardware-stats
description: fetch hardware stats for ACME Humidifier
type: monitoring
monitoring_interval: 5 minute
requires:
	vendor: acme
	product: humidifier

#! REMOTE::SSH
show hardware stats

#! PARSER::AWK


BEGIN {
}

# Sample line from the output of "show hardware stats" on the ACME Humidifier:
# Current humidity: 27%
# Fan speed: 200 RPM
# Water remaining: 1.72 L
 
/Current humidity/ {
	# $NF means "give me the last field" in awk.
	percentage=$NF
 
	# Remove the "%", we don't include that in the value we store (a double metric can only be a number with a decimal place, nothing around it)
	sub(/%/, "", percentage)
 
	# We write the humidity level metric, informing the db that this is a gauge that is updated every 5 minutes.
	# We also include information for "live config".
	writeDoubleMetricWithLiveConfig("humidity", null, "gauge", "300", percentage, "Hardware - Stats", "percentage", "")
}
 
/Fan speed/ {
	# Get the one-before-last field - we don't need the "RPM" stuff
	speed=$(NF-1)
 
	# We write the fan speed metric, same parameters as humidity.
	writeDoubleMetricWithLiveConfig("fan-speed", null, "gauge", "300", speed, "Hardware - Stats", "number", "")
}
 
/Water remaining/ {
	water=$(NF-1)

	# We write the water remaining metric, same parameters as humidity.
	writeDoubleMetricWithLiveConfig("water-remaining", null, "gauge", "300", water, "Hardware - Stats", "number", "")
}

END {
}

The result of running the above script on the ACME Humidifier is this:


DOUBLE_METRIC:im.name=humidity,display-name=Hardware - Stats,live-config=true,im.dstype.displayType=percentage,im.identity-tags="",im.metric-type=ts,dsType=gauge,step=300,value=27
DOUBLE_METRIC:im.name=fan-speed,display-name=Hardware - Stats,live-config=true,im.dstype.displayType=number,im.identity-tags="",im.metric-type=ts,dsType=gauge,step=300,value=200
DOUBLE_METRIC:im.name=water-remaining,display-name=Hardware - Stats,live-config=true,im.dstype.displayType=number,im.identity-tags="",im.metric-type=ts,dsType=gauge,step=300,value=1.72

These three metrics are now sent by the collector to the server for storage in the db. The metrics will have the device-id and timestamp included as well (the collector adds them).