Révision 6d2da7ad
p/cpu_linux_multi: remove the use of /proc/cpuinfo
| plugins/system/cpu_linux_multi | ||
|---|---|---|
| 37 | 37 |
# multigraph, supersampling, extended cpu informations |
| 38 | 38 |
# |
| 39 | 39 |
# require: mpstat (to actually collect the data) |
| 40 |
# require linux /proc |
|
| 41 |
# (sorry, quick/dirty retrieve the number of cpu from /proc/cpuinfo) |
|
| 42 | 40 |
# |
| 43 | 41 |
# |
| 44 | 42 |
# ENV (default): |
| ... | ... | |
| 186 | 184 |
|
| 187 | 185 |
my $cpu_count_cache = undef; |
| 188 | 186 |
sub cpu_count() {
|
| 189 |
# XXX: is there any way to do that cleanly ? |
|
| 190 | 187 |
if (not defined $cpu_count_cache) {
|
| 191 |
$cpu_count_cache = `grep -c ^processor /proc/cpuinfo`; |
|
| 192 |
chomp $cpu_count_cache; |
|
| 188 |
open MPSTAT, "$mpstat -P ALL |" or die "open mpstat|: $!\n"; |
|
| 189 |
$cpu_count_cache = 0; |
|
| 190 |
while (<MPSTAT>) {
|
|
| 191 |
chomp; |
|
| 192 |
my @field = split(); |
|
| 193 |
next unless ($field[1] && ($field[1] =~ /^([0-9]+)$/)); |
|
| 194 |
$cpu_count_cache ++; |
|
| 195 |
} |
|
| 196 |
close(MPSTAT); |
|
| 193 | 197 |
} |
| 194 | 198 |
return $cpu_count_cache; |
| 195 | 199 |
} |
Formats disponibles : Unified diff