summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f0caaae)
raw | patch | inline | side by side (parent: f0caaae)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 28 Feb 2008 17:33:06 +0000 (18:33 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Thu, 28 Feb 2008 18:58:02 +0000 (19:58 +0100) |
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
Signed-off-by: Florian Forster <octo@huhu.verplant.org>
bindings/perl/Collectd/Unixsock.pm | patch | blob | history | |
contrib/cussh.pl | patch | blob | history |
index d3b77d02e4d714f5fbf6ad24022f7c7dd6700705..3b6fa5d13d96c58634cac3fe8c8f263d15229b51 100644 (file)
return;
} # putnotif
+=item I<$obj>-E<gt>B<flush> (B<timeout> =E<gt> I<$timeout>, B<plugins> =E<gt> [...]);
+
+Flush cached data.
+
+Valid options are:
+
+=over 4
+
+=item B<timeout>
+
+If this option is specified, only data older than I<$timeout> seconds is
+flushed.
+
+=item B<plugins>
+
+If this option is specified, only the selected plugins will be flushed.
+
+=back
+
+=cut
+
+sub flush
+{
+ my $obj = shift;
+ my %args = @_;
+
+ my $fh = $obj->{'sock'} or confess;
+
+ my $status = 0;
+ my $msg = "FLUSH";
+
+ if ($args{'timeout'})
+ {
+ $msg .= " timeout=" . $args{'timeout'};
+ }
+
+ if ($args{'plugins'})
+ {
+ foreach my $plugin (@{$args{'plugins'}})
+ {
+ $msg .= " plugin=" . $plugin;
+ }
+ }
+
+ $msg .= "\n";
+
+ send ($fh, $msg, 0) or confess ("send: $!");
+ $msg = undef;
+ recv ($fh, $msg, 1024, 0) or confess ("recv: $!");
+
+ ($status, $msg) = split (' ', $msg, 2);
+ return (1) if ($status == 0);
+
+ $obj->{'error'} = $msg;
+ return;
+}
+
=item I<$obj>-E<gt>destroy ();
Closes the socket before the object is destroyed. This function is also
diff --git a/contrib/cussh.pl b/contrib/cussh.pl
index 65c634e0f8637dc57c34d8812645639b3a7fad13..c19c3f3092c659a860e108b753fac6505dcba3c6 100755 (executable)
--- a/contrib/cussh.pl
+++ b/contrib/cussh.pl
my $path = $ARGV[0] || "/var/run/collectd-unixsock";
my $sock = Collectd::Unixsock->new($path);
+ my $cmds = {
+ PUTVAL => \&putval,
+ GETVAL => \&getval,
+ FLUSH => \&flush,
+ };
+
if (! $sock) {
print STDERR "Unable to connect to $path!\n";
exit 1;
}
- print "cussh version 0.1, Copyright (C) 2007 Sebastian Harl\n"
+ print "cussh version 0.2, Copyright (C) 2007 Sebastian Harl\n"
. "cussh comes with ABSOLUTELY NO WARRANTY. This is free software,\n"
. "and you are welcome to redistribute it under certain conditions.\n"
. "See the GNU General Public License 2 for more details.\n\n";
$cmd = uc $cmd;
my $f = undef;
- if ($cmd eq "PUTVAL") {
- $f = \&putval;
- }
- elsif ($cmd eq "GETVAL") {
- $f = \&getval;
+ if (defined $cmds->{$cmd}) {
+ $f = $cmds->{$cmd};
}
else {
print STDERR "ERROR: Unknown command $cmd!\n";
my $id = getid(\$line);
- return if (! $id);
+ if (! $id) {
+ print STDERR $sock->{'error'} . $/;
+ return;
+ }
my ($time, @values) = split m/:/, $line;
return $sock->putval(%$id, $time, \@values);
my $id = getid(\$line);
- return if (! $id);
+ if (! $id) {
+ print STDERR $sock->{'error'} . $/;
+ return;
+ }
my $vals = $sock->getval(%$id);
return 1;
}
+sub flush {
+ my $sock = shift || return;
+ my $line = shift;
+
+ my $res;
+
+ if (! $line) {
+ $res = $sock->flush();
+ }
+ else {
+ my %args = ();
+
+ foreach my $i (split m/ /, $line) {
+ my ($option, $value) = $i =~ m/^([^=]+)=(.+)$/;
+ next if (! ($option && $value));
+
+ if ($option eq "plugin") {
+ push @{$args{"plugins"}}, $value;
+ }
+ elsif ($option eq "timeout") {
+ $args{"timeout"} = $value;
+ }
+ else {
+ print STDERR "Invalid option \"$option\".\n";
+ return;
+ }
+ }
+
+ $res = $sock->flush(%args);
+ }
+
+ if (! $res) {
+ print STDERR $sock->{'error'} . $/;
+ return;
+ }
+ return 1;
+}
+
=head1 SEE ALSO
L<collectd(1)>, L<collectd-unisock(5)>