[collectd] how to create more graphs wwith one perl script
Frank Kellner
Frank.Kellner at gmx.at
Sun Nov 22 17:06:47 CET 2009
Hello,
at first please excuse my bad english.
I have create an perl script to receive four values.
Now I want to create four single rrd files, but I don't now how.
When I start collectd with the option -T I get this message
LOG: 4 - perl: Collectd::plugin_dispatch_values with two arguments is
deprecated - pass the type through values->{type}.
At this time I get only one rrd-file with the four values.
What is the right way to get four single rrd-files?
Can someone help me?
Thanks,
Frank
This is my config in collectd.conf:
<Plugin perl>
IncludeDir "/home/frank"
BaseName "Collectd::Plugins"
LoadPlugin "Energymeter"
</Plugin>
And this is my perl.script:
#!/usr/bin/perl -w
use IO::Socket;
use strict;
use warnings;
package Collectd::Plugins::Energymeter;
use Collectd qw( :all );
my $dataset =
[
{
name => 'energy1_ds',
type => Collectd::DS_TYPE_GAUGE,
min => 0,
max => 65536.0,
},
{
name => 'energy2_ds',
type => Collectd::DS_TYPE_GAUGE,
min => 0,
max => 65536.0,
},
{
name => 'energy3_ds',
type => Collectd::DS_TYPE_GAUGE,
min => 0,
max => 65536.0,
},
{
name => 'energy4_ds',
type => Collectd::DS_TYPE_GAUGE,
min => 0,
max => 65536.0,
}
];
# This code is executed after loading the plugin to register it with
collectd.
Collectd::plugin_register (Collectd::TYPE_LOG, 'Energymeter', 'my_log' );
Collectd::plugin_register (Collectd::TYPE_DATASET, 'Energymeter', $dataset);
Collectd::plugin_register (Collectd::TYPE_INIT, 'Energymeter', 'my_init' );
Collectd::plugin_register (Collectd::TYPE_READ, 'Energymeter', 'my_read' );
Collectd::plugin_register (Collectd::TYPE_WRITE, 'Energymeter', 'my_write'
);
Collectd::plugin_register (Collectd::TYPE_SHUTDOWN, 'Energymeter',
'my_shutdown' );
# This function is called once upon startup to initialize the plugin.
sub my_init
{
# open sockets, initialize data structures, ...
# A false return value indicates an error and causes the plugin to
be
# disabled.
return 1;
} # my_init ()
# This function is called in regular intervals to collectd the data.
sub my_read
{
my $vl = {};
my $socket = '';
my $ip_address = "192.168.210.10";
my $power1 = 0;
my $power2 = 0;
my $power3 = 0;
my $power4 = 0;
$socket = new IO::Socket::INET (
PeerAddr => $ip_address,
PeerPort => 3673,
Type => 1,
Proto => getprotobyname('tcp'),
);
die "Energymeter: Unable to open connection: $!\n"
unless defined $socket;
$socket->autoflush(1);
print $socket "get_value";
#while (<$socket>)();
my $data = <$socket>;
my @tokens = split(/ /,$data);
my @local_temp = split(/:/,$tokens[0]);
$power1 = $local_temp[1];
@local_temp = split(/:/,$tokens[1]);
$power2 = $local_temp[1];
@local_temp = split(/:/,$tokens[2]);
$power3 = $local_temp[1];
@local_temp = split(/:/,$tokens[3]);
chop($local_temp[1]);
$power4 = $local_temp[1];
$vl->{'values'} = [ $power1, $power2, $power3, $power4 ];
$vl->{'plugin'} = 'Energymeter';
Collectd::plugin_dispatch_values ( 'Energymeter', $vl );
close $socket;
return 1;
}
# This function is called after values have been dispatched to collectd.
sub my_write
{
my $type = shift;
my $ds = shift;
my $vl = shift;
if (scalar (@$ds) != scalar (@{$vl->{'values'}})) {
Collectd::plugin_log (Collectd::LOG_WARNING,
"DS number does not match values length");
return;
}
for (my $i = 0; $i < scalar (@$ds); ++$i) {
# do the magic to output the data
print "$vl->{'host'}: $vl->{'plugin'}: ";
if (defined $vl->{'plugin_instance'}) {
print "$vl->{'plugin_instance'}: ";
}
print "$type: ";
if (defined $vl->{'type_instance'}) {
print "$vl->{'type_instance'}: ";
}
print "$vl->{'values'}->[$i]\n";
}
return 1;
} # my_write()
# This function is called before shutting down collectd.
sub my_shutdown
{
# close sockets, ...
return 1;
} # my_shutdown ()
# This function is called when plugin_log () has been used.
sub my_log
{
my $level = shift;
my $msg = shift;
print "LOG: $level - $msg\n";
return 1;
} # my_log ()
return 1;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.verplant.org/pipermail/collectd/attachments/20091122/d29c5d0d/attachment.htm
More information about the collectd
mailing list