|
@@ -1,6 +1,6 @@
|
|
-# $Id: SymuxClient.pm,v 1.6 2003/10/10 15:19:47 dijkstra Exp $
|
|
|
|
|
|
+# $Id: SymuxClient.pm,v 1.7 2003/12/20 16:30:44 dijkstra Exp $
|
|
#
|
|
#
|
|
-# Copyright (c) 2001-2002 Willem Dijkstra
|
|
|
|
|
|
+# Copyright (c) 2001-2003 Willem Dijkstra
|
|
# All rights reserved.
|
|
# All rights reserved.
|
|
#
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# Redistribution and use in source and binary forms, with or without
|
|
@@ -33,43 +33,43 @@ package SymuxClient;
|
|
use Carp;
|
|
use Carp;
|
|
use IO::Socket;
|
|
use IO::Socket;
|
|
|
|
|
|
-my $streamitem =
|
|
|
|
|
|
+my $streamitem =
|
|
{cpu => {user => 1, nice => 2, system => 3, interrupt => 4, idle => 5},
|
|
{cpu => {user => 1, nice => 2, system => 3, interrupt => 4, idle => 5},
|
|
- mem => {real_active => 1, real_total => 2, free => 3, swap_used => 4,
|
|
|
|
|
|
+ mem => {real_active => 1, real_total => 2, free => 3, swap_used => 4,
|
|
swap_total =>5},
|
|
swap_total =>5},
|
|
- if => {packets_in => 1, packets_out => 2, bytes_in => 3, bytes_out => 4,
|
|
|
|
- multicasts_in => 5, multicasts_out => 6, errors_in => 7,
|
|
|
|
|
|
+ if => {packets_in => 1, packets_out => 2, bytes_in => 3, bytes_out => 4,
|
|
|
|
+ multicasts_in => 5, multicasts_out => 6, errors_in => 7,
|
|
errors_out => 8, collisions => 9, drops => 10},
|
|
errors_out => 8, collisions => 9, drops => 10},
|
|
io => {total_transfers => 1, total_seeks => 2, total_bytes => 3},
|
|
io => {total_transfers => 1, total_seeks => 2, total_bytes => 3},
|
|
pf => {bytes_v4_in => 1, bytes_v4_out => 2, bytes_v6_in => 3,
|
|
pf => {bytes_v4_in => 1, bytes_v4_out => 2, bytes_v6_in => 3,
|
|
- bytes_v6_out => 4, packets_v4_in_pass => 5,
|
|
|
|
|
|
+ bytes_v6_out => 4, packets_v4_in_pass => 5,
|
|
packets_v4_in_drop => 6, packets_v4_out_pass => 7,
|
|
packets_v4_in_drop => 6, packets_v4_out_pass => 7,
|
|
- packets_v4_out_drop => 8, packets_v6_in_pass => 9,
|
|
|
|
|
|
+ packets_v4_out_drop => 8, packets_v6_in_pass => 9,
|
|
packets_v6_in_drop => 10, packets_v6_out_pass => 11,
|
|
packets_v6_in_drop => 10, packets_v6_out_pass => 11,
|
|
- packets_v6_out_drop => 12, states_entries => 13,
|
|
|
|
- states_searches => 14, states_inserts => 15,
|
|
|
|
- states_removals => 16, counters_match => 17,
|
|
|
|
|
|
+ packets_v6_out_drop => 12, states_entries => 13,
|
|
|
|
+ states_searches => 14, states_inserts => 15,
|
|
|
|
+ states_removals => 16, counters_match => 17,
|
|
counters_badoffset => 18, counters_fragment => 19,
|
|
counters_badoffset => 18, counters_fragment => 19,
|
|
- counters_short => 20, counters_normalize => 21,
|
|
|
|
|
|
+ counters_short => 20, counters_normalize => 21,
|
|
counters_memory => 22},
|
|
counters_memory => 22},
|
|
debug => {debug0 => 1, debug1 => 2, debug3 => 3, debug4 => 4, debug5 => 5,
|
|
debug => {debug0 => 1, debug1 => 2, debug3 => 3, debug4 => 4, debug5 => 5,
|
|
- debug6 => 6, debug7 => 7, debug8 => 8, debug9 => 9,
|
|
|
|
|
|
+ debug6 => 6, debug7 => 7, debug8 => 8, debug9 => 9,
|
|
debug10 => 10, debug11 => 11, debug12 => 12, debug13 => 13,
|
|
debug10 => 10, debug11 => 11, debug12 => 12, debug13 => 13,
|
|
debug14 => 14, debug15 => 15, debug16 => 16, debug17 => 17,
|
|
debug14 => 14, debug15 => 15, debug16 => 16, debug17 => 17,
|
|
debug18 => 18, debug19 => 19},
|
|
debug18 => 18, debug19 => 19},
|
|
- proc => {number => 1, uticks => 2, sticks => 3, iticks => 4, cpusec => 5,
|
|
|
|
|
|
+ proc => {number => 1, uticks => 2, sticks => 3, iticks => 4, cpusec => 5,
|
|
cpupct => 6, procsz => 7, rsssz => 8},
|
|
cpupct => 6, procsz => 7, rsssz => 8},
|
|
mbuf => {totmbufs => 1, mt_data => 2, mt_oobdata => 3, mt_control => 4,
|
|
mbuf => {totmbufs => 1, mt_data => 2, mt_oobdata => 3, mt_control => 4,
|
|
mt_header => 5, mt_ftable => 6, mt_soname => 7, mt_soopts => 8,
|
|
mt_header => 5, mt_ftable => 6, mt_soname => 7, mt_soopts => 8,
|
|
- pgused => 9, pgtotal => 10, totmem => 11, totpct => 12,
|
|
|
|
|
|
+ pgused => 9, pgtotal => 10, totmem => 11, totpct => 12,
|
|
m_drops => 13, m_wait => 14, m_drain => 15 },
|
|
m_drops => 13, m_wait => 14, m_drain => 15 },
|
|
sensor => {value => 1}};
|
|
sensor => {value => 1}};
|
|
sub new {
|
|
sub new {
|
|
my ($class, %arg) = @_;
|
|
my ($class, %arg) = @_;
|
|
my $self;
|
|
my $self;
|
|
-
|
|
|
|
- (defined $arg{host} && defined $arg{port}) or
|
|
|
|
- croak "error: need a host and a port to connect to.";
|
|
|
|
|
|
+
|
|
|
|
+ (defined $arg{host} && defined $arg{port}) or
|
|
|
|
+ croak "error: need a host and a port to connect to.";
|
|
|
|
|
|
($self->{host}, $self->{port}) = ($arg{host}, $arg{port});
|
|
($self->{host}, $self->{port}) = ($arg{host}, $arg{port});
|
|
|
|
|
|
@@ -86,25 +86,25 @@ sub DESTROY {
|
|
my $self = shift;
|
|
my $self = shift;
|
|
|
|
|
|
if (defined $self->{sock}) {
|
|
if (defined $self->{sock}) {
|
|
- close($self->{sock});
|
|
|
|
|
|
+ close($self->{sock});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
sub connect {
|
|
sub connect {
|
|
my $self = shift;
|
|
my $self = shift;
|
|
|
|
|
|
if (defined $self->{sock} && $self->{sock}->connected() ne '') {
|
|
if (defined $self->{sock} && $self->{sock}->connected() ne '') {
|
|
- return;
|
|
|
|
- } else {
|
|
|
|
- close($self->{sock});
|
|
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ close($self->{sock});
|
|
}
|
|
}
|
|
-
|
|
|
|
- $self->{sock} = new
|
|
|
|
|
|
+
|
|
|
|
+ $self->{sock} = new
|
|
IO::Socket::INET(PeerAddr => $self->{host},
|
|
IO::Socket::INET(PeerAddr => $self->{host},
|
|
- PeerPort => $self->{port},
|
|
|
|
- Proto => "tcp",
|
|
|
|
- Type => SOCK_STREAM)
|
|
|
|
- or croak "error: could not connect to $self->{host}:$self->{port}";
|
|
|
|
|
|
+ PeerPort => $self->{port},
|
|
|
|
+ Proto => "tcp",
|
|
|
|
+ Type => SOCK_STREAM)
|
|
|
|
+ or croak "error: could not connect to $self->{host}:$self->{port}";
|
|
}
|
|
}
|
|
|
|
|
|
sub getdata {
|
|
sub getdata {
|
|
@@ -116,16 +116,16 @@ sub getdata {
|
|
$tries = 0;
|
|
$tries = 0;
|
|
|
|
|
|
while (1) {
|
|
while (1) {
|
|
- $self->connect();
|
|
|
|
- $sock = $self->{sock};
|
|
|
|
- $data = <$sock>;
|
|
|
|
- if ((index($data, "\012") != -1) && (index($data, ';') != -1)) {
|
|
|
|
- $self->{rawdata} = $data;
|
|
|
|
- return $data;
|
|
|
|
- } else {
|
|
|
|
- croak "error: tried to get data $tries times and failed"
|
|
|
|
- if (++$tries == $self->{retry});
|
|
|
|
- }
|
|
|
|
|
|
+ $self->connect();
|
|
|
|
+ $sock = $self->{sock};
|
|
|
|
+ $data = <$sock>;
|
|
|
|
+ if ((index($data, "\012") != -1) && (index($data, ';') != -1)) {
|
|
|
|
+ $self->{rawdata} = $data;
|
|
|
|
+ return $data;
|
|
|
|
+ } else {
|
|
|
|
+ croak "error: tried to get data $tries times and failed"
|
|
|
|
+ if (++$tries == $self->{retry});
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -142,21 +142,21 @@ sub parse {
|
|
chop $self->{rawdata};
|
|
chop $self->{rawdata};
|
|
|
|
|
|
@streams = split(/;/, $self->{rawdata});
|
|
@streams = split(/;/, $self->{rawdata});
|
|
- croak "error: expected a symux dataline with ';' delimited streams"
|
|
|
|
- if ($#streams < 2);
|
|
|
|
-
|
|
|
|
|
|
+ croak "error: expected a symux dataline with ';' delimited streams"
|
|
|
|
+ if ($#streams < 2);
|
|
|
|
+
|
|
$self->{datasource} = shift @streams;
|
|
$self->{datasource} = shift @streams;
|
|
-
|
|
|
|
|
|
+
|
|
foreach $stream (@streams) {
|
|
foreach $stream (@streams) {
|
|
- ($name, $arg, @data) = split(':', $stream);
|
|
|
|
-
|
|
|
|
- croak "error: expected a symux stream with ':' delimited values"
|
|
|
|
- if ($#data < 2);
|
|
|
|
|
|
+ ($name, $arg, @data) = split(':', $stream);
|
|
|
|
|
|
- $name .= '('.$arg.')' if ($arg ne '');
|
|
|
|
|
|
+ croak "error: expected a symux stream with ':' delimited values"
|
|
|
|
+ if ($#data < 2);
|
|
|
|
|
|
- @{$self->{data}{$name}} = @data;
|
|
|
|
- $number++;
|
|
|
|
|
|
+ $name .= '('.$arg.')' if ($arg ne '');
|
|
|
|
+
|
|
|
|
+ @{$self->{data}{$name}} = @data;
|
|
|
|
+ $number++;
|
|
}
|
|
}
|
|
|
|
|
|
$self->{rawdata} = '';
|
|
$self->{rawdata} = '';
|
|
@@ -168,22 +168,22 @@ sub getcacheditem {
|
|
my ($streamtype, @addr, $element);
|
|
my ($streamtype, @addr, $element);
|
|
|
|
|
|
return undef if not defined $self->{datasource};
|
|
return undef if not defined $self->{datasource};
|
|
- return undef if (($host ne $self->{datasource}) &&
|
|
|
|
|
|
+ return undef if (($host ne $self->{datasource}) &&
|
|
($host ne "*"));
|
|
($host ne "*"));
|
|
|
|
|
|
- croak "error: source $host does not contain stream $streamname"
|
|
|
|
- if not defined $self->{data}{$streamname};
|
|
|
|
|
|
+ croak "error: source $host does not contain stream $streamname"
|
|
|
|
+ if not defined $self->{data}{$streamname};
|
|
|
|
|
|
($streamtype = $streamname) =~ s/^([a-z]+).*/\1/;
|
|
($streamtype = $streamname) =~ s/^([a-z]+).*/\1/;
|
|
|
|
|
|
if ($item eq 'timestamp') {
|
|
if ($item eq 'timestamp') {
|
|
- $element = 0;
|
|
|
|
|
|
+ $element = 0;
|
|
} elsif (not defined $$streamitem{$streamtype}{$item}) {
|
|
} elsif (not defined $$streamitem{$streamtype}{$item}) {
|
|
- croak "error: unknown stream item '$item' - check symux(8) for names";
|
|
|
|
|
|
+ croak "error: unknown stream item '$item' - check symux(8) for names";
|
|
} else {
|
|
} else {
|
|
- $element = $$streamitem{$streamtype}{$item};
|
|
|
|
|
|
+ $element = $$streamitem{$streamtype}{$item};
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
return $self->{data}{$streamname}[$element];
|
|
return $self->{data}{$streamname}[$element];
|
|
}
|
|
}
|
|
|
|
|
|
@@ -191,18 +191,18 @@ sub getitem {
|
|
my ($self, $host, $streamname, $item) = @_;
|
|
my ($self, $host, $streamname, $item) = @_;
|
|
my $data;
|
|
my $data;
|
|
my %hosts = ();
|
|
my %hosts = ();
|
|
-
|
|
|
|
|
|
+
|
|
undef $data;
|
|
undef $data;
|
|
while (! defined $data) {
|
|
while (! defined $data) {
|
|
- $self->getdata();
|
|
|
|
- $self->parse();
|
|
|
|
- $hosts{$self->{datasource}} += 1;
|
|
|
|
- if ($hosts{$self->{datasource}} > $self->{retry}) {
|
|
|
|
- croak "error: seen a lot of data ($tries strings), but none that matches $host";
|
|
|
|
- }
|
|
|
|
- $data = $self->getcacheditem($host, $streamname, $item);
|
|
|
|
- return $data if defined $data;
|
|
|
|
- $tries++;
|
|
|
|
|
|
+ $self->getdata();
|
|
|
|
+ $self->parse();
|
|
|
|
+ $hosts{$self->{datasource}} += 1;
|
|
|
|
+ if ($hosts{$self->{datasource}} > $self->{retry}) {
|
|
|
|
+ croak "error: seen a lot of data ($tries strings), but none that matches $host";
|
|
|
|
+ }
|
|
|
|
+ $data = $self->getcacheditem($host, $streamname, $item);
|
|
|
|
+ return $data if defined $data;
|
|
|
|
+ $tries++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -239,17 +239,17 @@ and data it receives from that connection. Arguments are:
|
|
|
|
|
|
host dotted quad ipv4 hostaddress
|
|
host dotted quad ipv4 hostaddress
|
|
port tcp port that symux is on
|
|
port tcp port that symux is on
|
|
- retry* maximum number of retries; used to limit number
|
|
|
|
- of connection attempts and number of successive
|
|
|
|
- read attempts
|
|
|
|
|
|
+ retry* maximum number of retries; used to limit number
|
|
|
|
+ of connection attempts and number of successive
|
|
|
|
+ read attempts
|
|
|
|
|
|
Arguments marked with * are optional.
|
|
Arguments marked with * are optional.
|
|
|
|
|
|
Example:
|
|
Example:
|
|
$sc = new SymuxClient(host => 127.0.0.1,
|
|
$sc = new SymuxClient(host => 127.0.0.1,
|
|
- port => 2100);
|
|
|
|
|
|
+ port => 2100);
|
|
|
|
|
|
-=back
|
|
|
|
|
|
+=back
|
|
|
|
|
|
=head2 METHODS
|
|
=head2 METHODS
|
|
|
|
|
|
@@ -273,22 +273,21 @@ with 'error: '.
|
|
Get the symon source host of the currently cached information. Usefull to see
|
|
Get the symon source host of the currently cached information. Usefull to see
|
|
what host's data getcacheditem is working on.
|
|
what host's data getcacheditem is working on.
|
|
|
|
|
|
-Example:
|
|
|
|
|
|
+Example:
|
|
$sc = new SymuxClient(host => 127.0.0.1,
|
|
$sc = new SymuxClient(host => 127.0.0.1,
|
|
- port => 2100);
|
|
|
|
|
|
+ port => 2100);
|
|
|
|
|
|
- print $sc->getitem("127.0.0.1", "if(de0)",
|
|
|
|
- "packets_out");
|
|
|
|
|
|
+ print $sc->getitem("127.0.0.1", "if(de0)",
|
|
|
|
+ "packets_out");
|
|
|
|
|
|
# get more data from that measurement
|
|
# get more data from that measurement
|
|
- print $sc->getcacheditem("127.0.0.1","if(de0)",
|
|
|
|
- "packets_in");
|
|
|
|
|
|
+ print $sc->getcacheditem("127.0.0.1","if(de0)",
|
|
|
|
+ "packets_in");
|
|
|
|
|
|
# start a new measurement
|
|
# start a new measurement
|
|
- print $sc->getitem("*", "if(de0)",
|
|
|
|
- "packets_out");
|
|
|
|
|
|
+ print $sc->getitem("*", "if(de0)",
|
|
|
|
+ "packets_out");
|
|
# which hosts packets_out was that?
|
|
# which hosts packets_out was that?
|
|
print $sc->getsource();
|
|
print $sc->getsource();
|
|
|
|
|
|
=cut
|
|
=cut
|
|
-
|
|
|