New plugin: lookalike

Announcements concerning Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
tcolgate
Posts: 13
Joined: Fri Sep 11, 2009 7:08 am

New plugin: lookalike

Post by tcolgate »

Hi All,

I've developed a plugin for cacti to perform time series comparison of the data set used by a graph against all data sources on the system. Basically it finds stuff that looks a bit like the graph you query. The performance is quite good, on my install it searches over 16,000 RRD files (over 46,000 data sources), in a bit under 2.5 seconds).

I've only developed it on linux, it may be possible to get it to run on windows if you can get the binary to build. There is still one annoying bug, a error is logged that seems to be related to the navigation string stuff, any help would be appreciated.

The plugin is available at https://github.com/tcolgate/lookalike/

Here are a couple of screenshots:

Image

Image
rvd
Posts: 34
Joined: Wed Nov 21, 2007 10:09 am
Location: France

Re: New plugin: lookalike

Post by rvd »

Hi Tristan,
It seems great but I can't make it work.
After changing default values in settings, I always get a white page.
When I try to launch it as a command line, I find matchind rrd:

# /var/www/html/cacti/plugins/lookalike/bin/lookalike -g /var/www/html/cacti/rra/\*.rrd -s 10 /var/www/html/cacti-0.8.7i-PIA-3.1/rra/proxyag1_cache_clients_11237.rrd cache_clients 1327915398 1328001798
Search for time series matching gggfcbbbbg using paa size 10...
Match:/var/www/html/cacti/rra/dnsdmz_cpu_system_7426.rrd:cpu_system
Match:/var/www/html/cacti/rra/proxyag1_cache_clients_11237.rrd:cache_clients
Processed 4618 RRAs
Matched 2 RRAs


I thought I would have 2 graphs on screen but it remains empty.
No error in apache log.
Any idea ?
tcolgate
Posts: 13
Joined: Fri Sep 11, 2009 7:08 am

Re: New plugin: lookalike

Post by tcolgate »

rvd wrote:Hi Tristan,
It seems great but I can't make it work.
After changing default values in settings, I always get a white page.
When I try to launch it as a command line, I find matchind rrd:
Hi, thanks for giving it a try!

One one other system a colleague tried we saw this behavor when the file glob setting for the plugin didn't match the rra_path in cacti. He had (quite rightly), used the /var/www/cacti/... but that was a symlink. Cacti uses the actual name /var/www/cacti-x.x.x. Changing the glob to use the real path instead of the symlink did the trick.

I've got a couple of idea of how to remedy that, I'll put something together when I get the chance.
tcolgate
Posts: 13
Joined: Fri Sep 11, 2009 7:08 am

Re: New plugin: lookalike

Post by tcolgate »

rvd wrote:Hi Tristan,
It seems great but I can't make it work.
After changing default values in settings, I always get a white page.
When I try to launch it as a command line, I find matchind rrd:
Hi, thanks for giving it a try!

One one other system a colleague tried we saw this behavor when the file glob setting for the plugin didn't match the rra_path in cacti. He had (quite rightly), used the /var/www/cacti/... but that was a symlink. Cacti uses the actual name /var/www/cacti-x.x.x. Changing the glob to use the real path instead of the symlink did the trick.

I've got a couple of idea of how to remedy that, I'll put something together when I get the chance.
rvd
Posts: 34
Joined: Wed Nov 21, 2007 10:09 am
Location: France

Re: New plugin: lookalike

Post by rvd »

Tristan,
It was too a symbolic link for me. I changed it, unfortunately it doesn't work.

I think the output of the 'exec' php function is not integrally taken.
Have a look at the test below:

# /var/www/html/cacti/plugins/lookalike/bin/lookalike -g /var/lib/cacti08/\*.rrd -s 10 /var/www/html/cacti-0.8.7i-PIA-3.1/rra/proxy1_cache_clients_13881.rrd cache_clients 1328114483 1328200883
Search for time series matching cbbbbbgggX using paa size 10...
Match:/var/lib/cacti08/consadmin1_wl_rsaapps_users_11476.rrd:users
Match:/var/lib/cacti08/consadmin1_wl_rsaapps_users_11477.rrd:users
Match:/var/lib/cacti08/proxy1_cache_clients_13881.rrd:cache_clients
Match:/var/lib/cacti08/proxy1_http_data_received_13887.rrd:http_data_received
Match:/var/lib/cacti08/proxy2_fd_used_13907.rrd:fd_used
Match:/var/lib/cacti08/switch-bleu-1_traffic_in_14369.rrd:traffic_out
Match:/var/lib/cacti08/wldomain_grh_consadmin2_users_14608.rrd:users
Processed 4629 RRAs
Matched 7 RRAs
# cat /tmp/test.php
<?php
$cmd = escapeshellcmd("/var/www/html/cacti/plugins/lookalike/bin/lookalike -g /var/lib/cacti08/\*.rrd -s 10 /var/www/html/cacti-0.8.7i-PIA-3.1/rra/proxy1_cache_clients_13881.rrd cache_clients 1328114483 1328200883");
exec($cmd, $output);
print_r($output);
?>
# php /tmp/test.php
Array
(
[0] => Search for time series matching cbbbbbgggX using paa size 10...
)

It displays only the first line.
As php manual says for exec function :

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array.

Am I wrong ?
tcolgate
Posts: 13
Joined: Fri Sep 11, 2009 7:08 am

Re: New plugin: lookalike

Post by tcolgate »

rvd wrote: <?php
$cmd = escapeshellcmd("/var/www/html/cacti/plugins/lookalike/bin/lookalike -g /var/lib/cacti08/\*.rrd -s 10 /var/www/html/cacti-0.8.7i-PIA-3.1/rra/proxy1_cache_clients_13881.rrd cache_clients 1328114483 1328200883");
exec($cmd, $output);
print_r($output);
?>
# php /tmp/test.php
Array
(
[0] => Search for time series matching cbbbbbgggX using paa size 10...
)

Try

Code: Select all

<?php
$cmd = escapeshellcmd("/var/www/html/cacti/plugins/lookalike/bin/lookalike -g /var/lib/cacti08/*.rrd -s 10 /var/www/html/cacti-0.8.7i-PIA-3.1/rra/proxy1_cache_clients_13881.rrd cache_clients 1328114483 1328200883");
exec($cmd, $output);
print_r($output);
?>
I get this same behavior if the file glob doesn't match any RRD files.
You do not need to escape the * in your actual setting, escapeshellcmd does that automatically.
You need the \ when you run from the CLI to stop the shell from expanding the pattern.

Also, the result of that glob is what needs to match to your rra path, so it should probably be

Code: Select all

 /var/www/html/cacti-0.8.7i-PIA-3.1/rra/*.rrd 
tcolgate
Posts: 13
Joined: Fri Sep 11, 2009 7:08 am

Re: New plugin: lookalike

Post by tcolgate »

I've updated the code to allow <path_rra> in the RRD path setting, and to use it by default
rvd
Posts: 34
Joined: Wed Nov 21, 2007 10:09 am
Location: France

Re: New plugin: lookalike

Post by rvd »

Thanks, but it still doesn't work. But now I know what is my problem :

Match:/var/lib/cacti08/proxy1_cache_clients_13881.rrd:cache_clients
matchedrrd=/var/lib/cacti08/proxy1_cache_clients_13881.rrd rrdbase=/var/www/html/cacti-0.8.7i-PIA-3.1/rra

rrdbase is not like in rrdglob (/var/lib/cacti08/*.rrd) because of symlink

So I patch lookalike.php like this :

//$rrdbase = $config["rra_path"];
$rrdbase = '/var/lib/cacti08'; //Real path

And now it works like a charm. Thanks !
But may be you could investigate in this direction because I suppose symlink is often used for rra_path in cacti to store files elsewhere.
tcolgate
Posts: 13
Joined: Fri Sep 11, 2009 7:08 am

Re: New plugin: lookalike

Post by tcolgate »

I've pushed a couple of updates that might make things a bit easier.
You can now set multiple RRA paths (the two default options cacti uses are included in the defaults)
<path_rra> can be included, and used by default.
You could add arbitrary RRA paths.
If an RRA matches multiple times it will be queried multiple times, so it's still best to tune the paths if you need to.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests