mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-27 04:54:22 +00:00
use unified parser for pressure stats
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
0bc3dac963
commit
eadfaabdae
@ -387,18 +387,9 @@ sub get_pressure_stat {
|
|||||||
# container or VM most likely isn't running
|
# container or VM most likely isn't running
|
||||||
return undef;
|
return undef;
|
||||||
} elsif ($ver == 2) {
|
} elsif ($ver == 2) {
|
||||||
|
for my $type (qw(cpu memory io)) {
|
||||||
foreach my $type (qw(cpu memory io)) {
|
my $stats = PVE::ProcFSTools::parse_pressure("$path/$type.pressure");
|
||||||
if (my $fh = IO::File->new ("$path/$type.pressure", "r")) {
|
$res->{$type} = $stats if $stats;
|
||||||
while (defined (my $line = <$fh>)) {
|
|
||||||
if ($line =~ /^(some|full)\s+avg10\=(\d+\.\d+)\s+avg60\=(\d+\.\d+)\s+avg300\=(\d+\.\d+)\s+total\=(\d+)/) {
|
|
||||||
$res->{$type}->{$1}->{avg10} = $2;
|
|
||||||
$res->{$type}->{$1}->{avg60} = $3;
|
|
||||||
$res->{$type}->{$1}->{avg300} = $4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$fh->close;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
die "bad cgroup version: $ver\n";
|
die "bad cgroup version: $ver\n";
|
||||||
|
@ -132,20 +132,29 @@ sub read_loadavg {
|
|||||||
return wantarray ? (0, 0, 0) : 0;
|
return wantarray ? (0, 0, 0) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub read_pressure {
|
sub parse_pressure {
|
||||||
|
my ($path) = @_;
|
||||||
|
|
||||||
my $res = {};
|
my $res = {};
|
||||||
foreach my $type (qw(cpu memory io)) {
|
my $v = qr/\d+\.\d+/;
|
||||||
if (my $fh = IO::File->new ("/proc/pressure/$type", "r")) {
|
my $fh = IO::File->new($path, "r") or return undef;
|
||||||
while (defined (my $line = <$fh>)) {
|
while (defined (my $line = <$fh>)) {
|
||||||
if ($line =~ /^(some|full)\s+avg10\=(\d+\.\d+)\s+avg60\=(\d+\.\d+)\s+avg300\=(\d+\.\d+)\s+total\=(\d+)/) {
|
if ($line =~ /^(some|full)\s+avg10\=($v)\s+avg60\=($v)\s+avg300\=($v)\s+total\=(\d+)/) {
|
||||||
$res->{$type}->{$1}->{avg10} = $2;
|
$res->{$1}->{avg10} = $2;
|
||||||
$res->{$type}->{$1}->{avg60} = $3;
|
$res->{$1}->{avg60} = $3;
|
||||||
$res->{$type}->{$1}->{avg300} = $4;
|
$res->{$1}->{avg300} = $4;
|
||||||
|
$res->{$1}->{total} = $4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$fh->close;
|
$fh->close;
|
||||||
}
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub read_pressure {
|
||||||
|
my $res = {};
|
||||||
|
foreach my $type (qw(cpu memory io)) {
|
||||||
|
my $stats = parse_pressure("/proc/pressure/$type");
|
||||||
|
$res->{$type} = $stats if $stats;
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user