Apply mathematical operations to |query...| ?

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
Frances
Cacti User
Posts: 60
Joined: Sun Apr 10, 2005 11:26 pm
Location: west coast

Apply mathematical operations to |query...| ?

Post by Frances »

I'm displaying a piece of data that's being gathered in an SNMP walk as part of a data query as "input" (ungraphed) data. I'm attaching it to a graph template as a 'COMMENT' using a '|query|', but the appropriate method for applying mathematical operations to the figure is eluding me. In this case, I'm pulling a numerical value from the query and I'd like to divide that value by ten. It seems I'm either missing something embarassingly simple, or it just can't be done in 'COMMENT' statements (or) can only be done with "output" data. Help..? ;b
pfarmer
Posts: 4
Joined: Thu Jun 16, 2005 9:46 pm

Post by pfarmer »

Hi Frances,

I'm trying to do something similar - I want to graph my traffic in/out for my router interfaces (which isn't a problem) and I've created a comment that tells the link speed (which also isn't a problem.)

However, the graphs I'm creating I want to use bytes, not bits, so I want to convert the ifSpeed value to bytes instead of bits .......

So I get a COMMENT of "Link speed: 32KB/s"
JVandermark
Posts: 14
Joined: Tue Dec 14, 2004 9:54 am

Post by JVandermark »

Just use the CDEF Function: /cacti/CDEF.php. You can add them and apply...

"out of the box" Cacti comes with "Turn Bytes into Bits" In your case you can just reverse this
pfarmer
Posts: 4
Joined: Thu Jun 16, 2005 9:46 pm

Post by pfarmer »

Thanks JVandermark - I understand this and I've made a CDEF to convert bits to kilobytes (using the same method as the bytes to bits) but I can make it actually change the ifSpeed value.....
Frances
Cacti User
Posts: 60
Joined: Sun Apr 10, 2005 11:26 pm
Location: west coast

Post by Frances »

Hmm... If I recall correctly, I tried to use a CDEF for this, but wasn't able to get a CDEF to apply to "input" data. The trick is, the OID for this piece of data is found via a query, but the data is not expected to change once found, so I'm grabbing it as "input" rather than "output" data in the query. I could grab it as "output" data, but I don't have need to graph it, I just want it displayed.
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

I am contemplating a patch to support the parsing of |query_...| in both COMMENTS and HRULE/VRULE before I return to work on July 18th. I will be out of town until July the 9th however.

TheWitness
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
interweave
Posts: 5
Joined: Tue Dec 19, 2006 12:13 pm

This worked for me

Post by interweave »

I was having the same problem, wanting to change the ifSpeed to Mbps.

I was getting "ERROR: rpn expressions without DEF or CDEF variables are not supported" if I did:

cdef=|query_ifSpeed|,1000000,/

Here's the CDEF I came up with:

cdef=CURRENT_DATA_SOURCE,CURRENT_DATA_SOURCE,-,|query_ifSpeed|,+,1000000,/


I take the current data and subract it from itself and add the result (which is 0) to the value returned by the query.

Works quite well.

Scott
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: This worked for me

Post by gandalf »

interweave wrote:cdef=CURRENT_DATA_SOURCE,CURRENT_DATA_SOURCE,-,|query_ifSpeed|,+,1000000,/
Yep, ok. Reason for this is, that each CDEF must reference some DEF. Another approach may be

Code: Select all

cdef=CURRENT_DATA_SOURCE,POP,|query_ifSpeed|,+,1000000,/

Reinhard
interweave
Posts: 5
Joined: Tue Dec 19, 2006 12:13 pm

I like yours better!

Post by interweave »

Thanks Reinhard! I like your version better!

Scott
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest