Indexed script query with multiple output fields

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
User avatar
Setarcos
Cacti User
Posts: 143
Joined: Mon Dec 13, 2004 2:55 pm
Location: San Jose, CA
Contact:

Indexed script query with multiple output fields

Post by Setarcos »

Please excuse the duplicate post, but I wanted to see if this was possible before posting a feature request.

I have an existing indexed script query which contains 10 output parameters. The current implementation of the script query stuff appears to do a get for all of these output parameters per index, rather than a query to do them for all index values which due to the execution speed of the script when geting serially (via spine) can cause the poller time to exceed 300 seconds when used with dozens of indexes on hundreds of hosts.

It would be possible to write a script that collect all 10 of these output parameters and output them (ala a new Script/Command data input method with defined output field names) to cut down the need to run the script for an index from 10 to 1, but this way one would need to be created for each of the indexes by hand since it couldn't be templated (I really like the pointy-clicky aspect of using templates)

This doesn't appear to be possible by existing means, so my request is to have indexed script queries support multiple output fields.
ut03550
Posts: 14
Joined: Wed Feb 13, 2008 12:09 pm

Re: Indexed script query with multiple output fields

Post by ut03550 »

I'm looking for the same.

Any Ideas?
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Re: Indexed script query with multiple output fields

Post by rony »

Usually my suggestion is to use some sort of caching with in the polling script so that it does not have to hit the device for every time Cacti calls it.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
ut03550
Posts: 14
Joined: Wed Feb 13, 2008 12:09 pm

Re: Indexed script query with multiple output fields

Post by ut03550 »

Thanks. I have thought about it already.

But my problem is that I have to poll to a Database every 5 minutes and I can't to cache it... I'll continue thinking about how to do it...

What I need is to reduce the numbers of queries every 5 minutes, because I do over 3000 queries to the database every 5 minutes... I have 350 indexed data, 3 kind of answers for every data, also 3 kind of answers for every kind.

Then I have 350 x 3 x 3 queries if I have to obtain data by data. Returning "kind1:X kind2:X kind3:X" for every first kind, like you can do with a "Data Input Method" for non indexes data, it will reduce the queries to 1000, that is an important change.
ut03550
Posts: 14
Joined: Wed Feb 13, 2008 12:09 pm

Re: Indexed script query with multiple output fields

Post by ut03550 »

Ok, Thanks Rony.

Almost you give me an idea, I will run a cron that connects to de DataBase in the way I want, and that create files with the results of my queries. Then other "script server" from cacti will read those files.

It's a chance, but then I need to control two scripts, one running by cron, other running by cacti...

It will be perfect that Cacti will be able to return several fields from script server indexed, like data input method do.

Hopefully some day...

I will try to publish my work in a few time, in order to other people can use it. It's not a great job, but the idea can be usefull, I think.
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Re: Indexed script query with multiple output fields

Post by rony »

I agree, it would be much more ideal for Cacti to be smarter about it.

But, this work around will work and I employ the same techniques on multiple Cacti installations.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
ut03550
Posts: 14
Joined: Wed Feb 13, 2008 12:09 pm

Re: Indexed script query with multiple output fields

Post by ut03550 »

I have implemented the cron solution, but now I have another problem, the cron job takes more than 5 minutes because there are many queries to do to the database... I will need to implement a fork solution in my php script... something like spine does, I suppose... It will be harder than I thought.

I will try.

I think this solution, implement a multiple output fields for a indexed script query, would be a powerful solution to Cacti... instead of to do it manually.
User avatar
gninja
Cacti User
Posts: 371
Joined: Tue Aug 24, 2004 5:02 pm
Location: San Francisco, CA
Contact:

Re: Indexed script query with multiple output fields

Post by gninja »

Here's the script I use. Creates a short lived cache in a subdir in /tmp.. I call it inside my query scripts - where I parse and present the data, using it to call the command that collects the actual data.

In a script (also bash for this one):

Code: Select all

scripts="/data/cacti/scripts"
cache="${scripts}/cache 270"
esx="${cache} ${scripts}/check_esx3.pl"
And later when it's actually being called:

Code: Select all

io_vm_all=`${esx} -H $2 -N $3 -u $UN -p $PW -l IO`
So for this, any time check_esx3.pl is called by this script, it'll first check to see if there's a cache file for the same set of arguments, and if there is one less than 4 and a half minutes old, it'll cough it up. Cut a significant chunk of time off my polling. The way it does the caching is pretty simple if you want to repurpose it and add it directly to your script.
Attachments
cache.gz
Bash cache script
(369 Bytes) Downloaded 238 times
Last edited by gninja on Mon Jun 27, 2011 5:39 pm, edited 1 time in total.
FreeBSD/RHEL
cacti-0.8.7i, spine 0.8.7i, PIA 3.1+boost 5.1
MySQL 5.5/InnoDB
RRDtool 1.2.27, PHP 5.1.6
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Re: Indexed script query with multiple output fields

Post by gandalf »

Recently, I found a Cacti script for XEN monitoring that used some php caching magic (I fear it required php5). Just a hint.
R.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests