Examples

These examples demonstrate how to use the arithmetic subagent to perform specific tasks.

CPU usage alarm with hysteresis

Create an genalarm-style hysteresis-mode alarm for the host system's CPU usage with rising and falling thresholds of 80% and 60% respectively, evaluated at one-minute intervals with rising and falling durations of five minutes:

subagent load mib2	
subagent load rmonc
subagent load sysres
subagent load arithmetic

event type=snmp-trap
event community=public
event description="CPU usage event"
event create
eventIdx=$?

arithmetic reset
arithmetic interval=60
arithmetic window=5
arithmetic description="CPU Usage"
arithmetic event=$eventIdx
arithmetic expression="
 @val = .srSystemCPUUsage.0; 
 @rise = 80;
 @fall = 60;
 (min(@val) > @rise && @state != 2) ? 
   @result = "CPU usage above @rise", 
   @state = 2 
 : (max(@val) <= @fall && @state != 0) ? 
   @result = "CPU usage returned to normal (less than @fall)", 
   @state = 0
 : (min(@val) <= @rise && max(@val) >= @fall) ? 
   @result = 0,
   @state = 1
 : @result = 0;
 @result
"
arithmetic create

Monitoring growth rates

Monitor the growth rate of storage on the local file system, and generate an alarm if it changes by more than 5% in one hour:

subagent load mib2
subagent load rmonc
subagent load hostres
subagent load sysres
subagent load arithmetic

event type=snmp-trap
event community=public
event description="Storage growth rate event"
event create
eventIdx=$?


arithmetic reset
arithmetic interval=3600
arithmetic window=1
arithmetic event=$eventIdx
arithmetic description="Storage growth rate"
arithmetic expression="
 @fixed = 4;
 @used = .srStorageLogicalUsedPercent.(@fixed).?;
 @delta = delta(@used); 
 @delta ? 
   @part=.hrStorageDescr.[0];
   @result = "Growth rate on partition @part was @delta % in the last hour"
 : @result = 0;
 @result
"
arithmetic create

Predicting disk usage

Monitor disk usage on the host system and generate an alarm if the fixed disk usage exceeds 80% and the usage trend indicates that it will exceed 95% in the next day:

subagent load mib2
subagent load rmonc
subagent load hostres
subagent load sysres
subagent load arithmetic

event reset
event type=snmp-trap
event community=public
event description="Disk usage trend critical"
event createeventIdx=$?

arithmetic reset
arithmetic event=$eventIdx
arithmetic interval=3600
arithmetic window=12
arithmetic expression="
 @fixed = 4;
 @usedmax = 80;
 @trendmax = 95;
 @used = .srStorageLogicalUsedPercent.(@fixed).?;
 @trend = trend(@used,1d);
 (@used > 80 && @trend > 95) ?
  @disk = .hrStorageDescr.[0]; 
  @result = "Usage on @disk is @used % and will exceed @trendmax % in 1 day"
 : @result = 0;
 @result
"
arithmetic create

Monitoring Windows services

Monitor all Windows services that are configured to start automatically, and generate an alarm if any of them stop:

subagent load mib2
subagent load rmonc
subagent load ntscm
subagent load arithmetic

event reset
event type=snmp-trap
event community=public
event description="Windows service failure"
event create
eventIdx=$?

arithmetic reset
arithmetic event=$eventIdx
arithmetic interval=10
arithmetic window=1
arithmetic expression="
 ((.ntServiceTableCurrentState.*==7)&&(.ntServiceTableStartType.[*]==1))? 
  @name = .ntServiceTableDisplayName.[*];
  @result = "Automatic service @name has stopped"
 : @result = 0;
 @result
"
arithmetic create

Calculating total swap usage

Calculate total swap usage in kilobytes, using data from hrStorageTable. Swap space data in this table is indicated by the type hrStorageVirtualMemory (OID .1.3.6.1.2.1.25.2.1.3):

subagent load hostres
subagent load arithmetic

arithmetic reset
arithmetic description="Total swap usage in KB"
arithmetic expression='
sum((
  @hrstoragetype=str(.hrStorageType.*);
  @swap=".1.3.6.1.2.1.25.2.1.3";
  @hrstoragetype == @swap ?
    @units=.hrStorageAllocationUnits.[0];
    @used=.hrStorageUsed.[0];
    @byteused=@used * @units;
    @byteused / 1024
  : 0
))
'
arithmetic create

Miscellaneous monitor expressions

This section provides a list of expression definitions for a selection of monitoring tasks:

  1. Monitor only DB2 file systems and generate an alarm on 85% usage:
    arithmetic expression="
     (.hrStorageDesc.*#/\/db2.*/) 
     && 
     (.hrStorageUsed.[*] * 100 / .hrStorageSize.[*] > 85)
    "
  2. Monitor CPU usage and generate an alarm containing a severity code based on the level of use:
    arithmetic expression="
     @val=.srSystemCPUUsage.0 ; 
     (@val >= 75) ? 
       @code = "CPU usage critical (@val%)" 
     : (@val >= 60) ? 
       @code = "CPU usage high (@val%)"
     : (@val >= 50) ? 
       @code = "CPU usage moderate (@val%)"
     : @code = 0; 
     @code
    "
  3. Monitor the free space ratio of Oracle tablespaces. Generate an alarm if the ratio falls below 10%. Embed the percentage of free space, the name of the tablespace, and the SID of the corresponding Oracle instance as varbinds in the events generated:
    arithmetic expression="
     ({.oraTableSpaceFreeSpaceRatio.*} < 10) ?
      {@name = .oraTableSpaceName.[*]};
      {@sid = .oraInstanceSID.[0]};
      @result = "Free space ratio low on @name, @sid"
     : @result = 0;
     @result
    "