Skip to content
Snippets Groups Projects
Commit ae69dda0 authored by Bryan Allen's avatar Bryan Allen
Browse files

Add fsstat and zoneinfo support to Zoneinfo.pm

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@420 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55
parent 738312f2
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,15 @@ Optional. Specifies the path to the zoneadm command.
Optional. Specifies the path to the zfs command.
=item disable_fsstat
Optional. Set to 1 if you do not wish to gather per-zone fsstat metrics.
=item disable_resource_collection
Optional. Set to 1 if you do not wish to gather per-zone resource metrics (CPU,
memory, etc.
=back
=head1 METRICS
......@@ -88,31 +97,128 @@ sub handler {
# to see if it is a mountpoint.
my $mounts = {};
my $output = run_command("/sbin/mount");
foreach my $line (split(/\n/, $output)) {
my @parts = split(/\s+/, $line);
next unless $parts[2] =~ /\//;
$mounts->{$parts[0]} = $parts[2];
my @parts = split(/\s+/, $line);
next unless $parts[2] =~ /\//;
$mounts->{$parts[0]} = $parts[2];
};
my $status = {};
my $zoneroots = "";
foreach my $zone (@zones) {
my $output = run_command("$zonecfg -z $zone info zonepath");
chomp $output;
my @result = split(/:\s*/, $output);
my $path = $result[1];
my $dataset = $mounts->{$path};
if ($dataset) {
my $creation = run_command("$zfs get -H -o value -p creation $dataset");
chomp $creation;
$status->{"${zone}_creation"} = [$creation, "i"];
} else {
$dataset = "Not a mountpoint";
}
# Store the values
$status->{"${zone}_path"} = [$path, "s"];
$status->{"${zone}_dataset"} = [$dataset, "s"];
my $output = run_command("$zonecfg -z $zone info zonepath");
chomp $output;
my @result = split(/:\s*/, $output);
my $path = $result[1];
my $dataset = $mounts->{$path};
if ($dataset) {
my $creation = run_command("$zfs get -H -o value -p creation $dataset");
chomp $creation;
$status->{"${zone}_creation"} = [$creation, "i"];
}
else {
$dataset = "Not a mountpoint";
}
# Store the values
$status->{"${zone}_path"} = [$path, "s"];
$status->{"${zone}_dataset"} = [$dataset, "s"];
$zoneroots .= "$path ";
};
return $status;
our %units = (
'B' => 1,
'K' => 1024,
'M' => 1048576,
'G' => 1073741824,
'T' => 1099511627776,
'P' => 1125899906842624,
'E' => 1152921504606846976,
'Z' => 1180591620717411303424
);
unless ( $config->{disable_fsstat} ) {
my $fsstat = run_command("/bin/fsstat $zoneroots 5 2 ");
foreach (split(/\n/, $fsstat)) {
next unless (/^\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/);
my $fs = $12;
my $fs_read_bytes;
my $fs_read = $9;
my $fs_write_bytes;
my $fs_write = $11;
foreach my $unit ( keys %units ) {
if ( $fs_read =~ m/$unit$/ ) {
$fs_read =~ s/$unit$//;
$fs_read_bytes = $fs_read * $units{$unit};
}
if ( $fs_write =~ m/$unit$/ ) {
$fs_write =~ s/$unit$//;
$fs_write_bytes = $fs_write * $units{$unit};
}
}
# The fsstat output does not specify B for bytes.
# Assume bytes if value is empty.
unless ( $fs_read_bytes ) { $fs_read_bytes = $fs_read }
unless ( $fs_write_bytes ) { $fs_write_bytes = $fs_write }
# There is almost certainly a less stupid way of doing this.
my $zone = `/usr/sbin/zoneadm list -p | /bin/grep $fs | /bin/awk -F: '{print \$2}'`;
chomp $zone;
$status->{"${zone}_read_bytes"} = [ $fs_read_bytes, "i" ];
$status->{"${zone}_write_bytes"} = [ $fs_write_bytes, "i" ];
$status->{"${zone}_read_kbytes"} = [ int($fs_read_bytes/1024), "i" ];
$status->{"${zone}_write_kbytes"} = [ int($fs_write_bytes/1024), "i" ];
$status->{"${zone}_read_mbytes"} = [ int($fs_read_bytes/1048576), "i" ];
$status->{"${zone}_write_mbytes"} = [ int($fs_write_bytes/1048576), "i" ];
}
}
unless ( $config->{disable_resource_collection} ) {
my $prstat = run_command("prstat -Z -n 1,500 -c 1 1 | tail +4 | grep -v Total");
foreach ( split(/\n/, $prstat) ) {
next unless /^\s+(\d+)/;
my ( $s, $zid, $nproc, $swap, $rss, $mem_pct, $time, $cpu_pct, $zone ) = split(/\s+/, $_);
my $swap_bytes;
my $rss_bytes;
$mem_pct =~ s/%//;
$cpu_pct =~ s/%//;
foreach my $unit ( keys %units ) {
if ( $swap =~ m/$unit$/ ) {
$swap =~ s/$unit$//;
$swap_bytes = $swap * $units{$unit};
}
if ( $rss =~ m/$unit$/ ) {
$rss =~ s/$unit$//;
$rss_bytes = $rss * $units{$unit};
}
}
$status->{"${zone}_id"} = [ $zid, "i" ];
$status->{"${zone}_nproc"} = [ $nproc, "i" ];
$status->{"${zone}_swap_bytes"} = [ $swap_bytes, "n" ];
$status->{"${zone}_rss_bytes"} = [ $rss_bytes, "n" ];
$status->{"${zone}_mem_pct"} = [ $mem_pct, "n" ];
$status->{"${zone}_cpu_pct"} = [ $cpu_pct, "n" ];
$status->{"${zone}_uptime"} = [ $time, "s" ];
}
}
return $status;
};
1;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment