VMware Cloud Community
MMazaOIT
Contributor
Contributor

How to adjust metric values through plugin?

Hello everyone.

I have written an smnp-plugin, which works fine.

But some values need to be adjusted.

For example in OID table is a value which need to be divided by 10 or there is percentage number saved as "100", but Hyperic shows it as 10000.0%, because it multiplyies by 100, so I need to divide it by 100 for Hyperic.

This example metric looks like this in the plugin.xml:

<metric name="Battery: Capacity"
             alias="mib-2.33.1.2.4.0"
             category="AVAILABILITY"
             units="percentage"
             defaultOn="true"
             collectionType="static"/>

I have read the documentation and tryed to search, but could not find how to use arithmetic operations on the OID values (for the Hyperic Manager, not change the OID table values).

I think this should be simple to do, maybe with template or script, but I could not find the exact syntax how to do that.

Would be thankfull if someone could help Smiley Happy

Reply
0 Kudos
5 Replies
MMazaOIT
Contributor
Contributor

So sad nobody can help me.

Reply
0 Kudos
dhustace
Contributor
Contributor

On Jun 14, 2012, at 4:11 AM, hq-users@hyperic.org wrote:

So sad nobody can help me.

Open source gurus help those that help themselves.  The mantra of open source is "free as in freedom."  You have the freedom (access) to view, change, and contribute the code to suite your needs.  If you don't want to do that, become a commercial user and request an enhancement.  This is the way of the world.  No one gets a "free as in free beer" free ride.

So sad... indeed.

Reply
0 Kudos
hqpso
Enthusiast
Enthusiast

You cannot perform math inside the plugin XML.

You would need to format the value outside.

If the value being returned by the SNMP GET is represented as a percentage, use a value of 'units=none' and no formatting will be performed.

http://support.hyperic.com/display/DOCS46/metric#metric-units

I would also consider using a collectionType of dynamic not static since the value will trend both directions.

Reply
0 Kudos
staceyeschneide
Hot Shot
Hot Shot

Thanks hqpso!

Reply
0 Kudos
MMazaOIT
Contributor
Contributor

I have solved that problem by using a script which divides the value by 100.

Under Windows I have written a C-crogramm (as .exe) which were used by batch script (it divides the value by 100).

The name of the programm is am_snmp_grep_div100.

The batch script looks like:

@echo off

setlocal enableextensions

REM Battery Capacity: bat_cap_value
for /f "tokens=*" %%a in (
  'snmpget -Ov -v 2c -c public 244.244.244.244 SNMPv2-SMI::mib-22.33.11.22.24.10.0'
) do (
  set myvar=%%a
)
echo/%%myvar%%=%myvar%

for /f "tokens=*" %%a in (
  'am_snmp_grep_div100 %myvar%'
) do (
  set agea=%%a
)
echo/%%agea%%=%agea%
echo bat_cap_value=%agea%

Under Linux its much easier. (No extra C-programm needed!)

The script:

bat_cap=$(snmpget -Ov -v 2c -c public 244.244.244.244 SNMPv2-SMI::mib-22.33.11.22.24.10.0 | awk '{print $NF}')
bat_cap_val=`echo "scale=2; $bat_cap/100" | bc`
echo "bat_cap_value=$bat_cap_val"

Here the awk function cut out the value at the end of the snmpget command.

"scale=2; $bat_cap/100" | bc

The value will me dividen by 100 and

scale=2 mean, 2 positions behind the point e.g. 2.55.

Then the metric in XML-plugin looks like

...

    <config>
      <option name="script"
            description="Script"
            default="/scriptpath/scriptname.sh"/>
    </config>
    <filter name="template"
            value="exec:file=%script%"/>

...

<metric name="Battery: Capacity"
            category="PERFORMANCE"
            units="percentage"
            template="${template}:bat_cap_value"
            indicator="true"/>

...

Here the units=percentage means the value will be multiplied by 100.

Reply
0 Kudos