| 98 | | my $output = run_command("$zonecfg -z $zone info zonepath"); |
|---|
| 99 | | chomp $output; |
|---|
| 100 | | my @result = split(/:\s*/, $output); |
|---|
| 101 | | my $path = $result[1]; |
|---|
| 102 | | my $dataset = $mounts->{$path}; |
|---|
| 103 | | if ($dataset) { |
|---|
| 104 | | my $creation = run_command("$zfs get -H -o value -p creation $dataset"); |
|---|
| 105 | | chomp $creation; |
|---|
| 106 | | $status->{"${zone}_creation"} = [$creation, "i"]; |
|---|
| 107 | | } else { |
|---|
| 108 | | $dataset = "Not a mountpoint"; |
|---|
| 109 | | } |
|---|
| 110 | | # Store the values |
|---|
| 111 | | $status->{"${zone}_path"} = [$path, "s"]; |
|---|
| 112 | | $status->{"${zone}_dataset"} = [$dataset, "s"]; |
|---|
| | 111 | my $output = run_command("$zonecfg -z $zone info zonepath"); |
|---|
| | 112 | chomp $output; |
|---|
| | 113 | my @result = split(/:\s*/, $output); |
|---|
| | 114 | my $path = $result[1]; |
|---|
| | 115 | my $dataset = $mounts->{$path}; |
|---|
| | 116 | if ($dataset) { |
|---|
| | 117 | my $creation = run_command("$zfs get -H -o value -p creation $dataset"); |
|---|
| | 118 | chomp $creation; |
|---|
| | 119 | $status->{"${zone}_creation"} = [$creation, "i"]; |
|---|
| | 120 | } |
|---|
| | 121 | else { |
|---|
| | 122 | $dataset = "Not a mountpoint"; |
|---|
| | 123 | } |
|---|
| | 124 | |
|---|
| | 125 | # Store the values |
|---|
| | 126 | $status->{"${zone}_path"} = [$path, "s"]; |
|---|
| | 127 | $status->{"${zone}_dataset"} = [$dataset, "s"]; |
|---|
| | 128 | |
|---|
| | 129 | $zoneroots .= "$path "; |
|---|
| 115 | | return $status; |
|---|
| | 132 | our %units = ( |
|---|
| | 133 | 'B' => 1, |
|---|
| | 134 | 'K' => 1024, |
|---|
| | 135 | 'M' => 1048576, |
|---|
| | 136 | 'G' => 1073741824, |
|---|
| | 137 | 'T' => 1099511627776, |
|---|
| | 138 | 'P' => 1125899906842624, |
|---|
| | 139 | 'E' => 1152921504606846976, |
|---|
| | 140 | 'Z' => 1180591620717411303424 |
|---|
| | 141 | ); |
|---|
| | 142 | |
|---|
| | 143 | unless ( $config->{disable_fsstat} ) { |
|---|
| | 144 | my $fsstat = run_command("/bin/fsstat $zoneroots 5 2 "); |
|---|
| | 145 | foreach (split(/\n/, $fsstat)) { |
|---|
| | 146 | 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+)$/); |
|---|
| | 147 | my $fs = $12; |
|---|
| | 148 | |
|---|
| | 149 | my $fs_read_bytes; |
|---|
| | 150 | my $fs_read = $9; |
|---|
| | 151 | |
|---|
| | 152 | my $fs_write_bytes; |
|---|
| | 153 | my $fs_write = $11; |
|---|
| | 154 | |
|---|
| | 155 | foreach my $unit ( keys %units ) { |
|---|
| | 156 | if ( $fs_read =~ m/$unit$/ ) { |
|---|
| | 157 | $fs_read =~ s/$unit$//; |
|---|
| | 158 | $fs_read_bytes = $fs_read * $units{$unit}; |
|---|
| | 159 | } |
|---|
| | 160 | |
|---|
| | 161 | if ( $fs_write =~ m/$unit$/ ) { |
|---|
| | 162 | $fs_write =~ s/$unit$//; |
|---|
| | 163 | $fs_write_bytes = $fs_write * $units{$unit}; |
|---|
| | 164 | } |
|---|
| | 165 | } |
|---|
| | 166 | |
|---|
| | 167 | # The fsstat output does not specify B for bytes. |
|---|
| | 168 | # Assume bytes if value is empty. |
|---|
| | 169 | unless ( $fs_read_bytes ) { $fs_read_bytes = $fs_read } |
|---|
| | 170 | unless ( $fs_write_bytes ) { $fs_write_bytes = $fs_write } |
|---|
| | 171 | |
|---|
| | 172 | # There is almost certainly a less stupid way of doing this. |
|---|
| | 173 | my $zone = `/usr/sbin/zoneadm list -p | /bin/grep $fs | /bin/awk -F: '{print \$2}'`; |
|---|
| | 174 | chomp $zone; |
|---|
| | 175 | |
|---|
| | 176 | $status->{"${zone}_read_bytes"} = [ $fs_read_bytes, "i" ]; |
|---|
| | 177 | $status->{"${zone}_write_bytes"} = [ $fs_write_bytes, "i" ]; |
|---|
| | 178 | |
|---|
| | 179 | $status->{"${zone}_read_kbytes"} = [ int($fs_read_bytes/1024), "i" ]; |
|---|
| | 180 | $status->{"${zone}_write_kbytes"} = [ int($fs_write_bytes/1024), "i" ]; |
|---|
| | 181 | |
|---|
| | 182 | $status->{"${zone}_read_mbytes"} = [ int($fs_read_bytes/1048576), "i" ]; |
|---|
| | 183 | $status->{"${zone}_write_mbytes"} = [ int($fs_write_bytes/1048576), "i" ]; |
|---|
| | 184 | } |
|---|
| | 185 | } |
|---|
| | 186 | |
|---|
| | 187 | unless ( $config->{disable_resource_collection} ) { |
|---|
| | 188 | my $prstat = run_command("prstat -Z -n 1,500 -c 1 1 | tail +4 | grep -v Total"); |
|---|
| | 189 | foreach ( split(/\n/, $prstat) ) { |
|---|
| | 190 | next unless /^\s+(\d+)/; |
|---|
| | 191 | my ( $s, $zid, $nproc, $swap, $rss, $mem_pct, $time, $cpu_pct, $zone ) = split(/\s+/, $_); |
|---|
| | 192 | |
|---|
| | 193 | my $swap_bytes; |
|---|
| | 194 | my $rss_bytes; |
|---|
| | 195 | |
|---|
| | 196 | $mem_pct =~ s/%//; |
|---|
| | 197 | $cpu_pct =~ s/%//; |
|---|
| | 198 | |
|---|
| | 199 | foreach my $unit ( keys %units ) { |
|---|
| | 200 | if ( $swap =~ m/$unit$/ ) { |
|---|
| | 201 | $swap =~ s/$unit$//; |
|---|
| | 202 | $swap_bytes = $swap * $units{$unit}; |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | if ( $rss =~ m/$unit$/ ) { |
|---|
| | 206 | $rss =~ s/$unit$//; |
|---|
| | 207 | $rss_bytes = $rss * $units{$unit}; |
|---|
| | 208 | } |
|---|
| | 209 | } |
|---|
| | 210 | |
|---|
| | 211 | $status->{"${zone}_id"} = [ $zid, "i" ]; |
|---|
| | 212 | $status->{"${zone}_nproc"} = [ $nproc, "i" ]; |
|---|
| | 213 | $status->{"${zone}_swap_bytes"} = [ $swap_bytes, "n" ]; |
|---|
| | 214 | $status->{"${zone}_rss_bytes"} = [ $rss_bytes, "n" ]; |
|---|
| | 215 | $status->{"${zone}_mem_pct"} = [ $mem_pct, "n" ]; |
|---|
| | 216 | $status->{"${zone}_cpu_pct"} = [ $cpu_pct, "n" ]; |
|---|
| | 217 | $status->{"${zone}_uptime"} = [ $time, "s" ]; |
|---|
| | 218 | } |
|---|
| | 219 | } |
|---|
| | 220 | |
|---|
| | 221 | return $status; |
|---|