Index: ossp-pkg/snmpdx/snmpdx.d/hwCpu.pm RCS File: /v/ossp/cvs/ossp-pkg/snmpdx/snmpdx.d/hwCpu.pm,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/snmpdx/snmpdx.d/hwCpu.pm,v' 2>/dev/null --- hwCpu.pm 2003/09/01 15:22:42 1.1 +++ hwCpu.pm 2003/09/08 10:49:35 1.2 @@ -36,27 +36,70 @@ sub probe ($$) { my ($self, $obj) = @_; - if ($obj->{-name} =~ m|\.hwCpuNum$|) { - if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) { - # query sysctl(8) - my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.ncpu", "forever"); - $obj->{-value} = $out->{-stdout}; - $obj->{-value} =~ s/^\s*(.+?)\s*$/$1/s; + if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) { + # query sysctl(8) + my $out = $self->{-ctx}->{-sys}->run("/sbin/sysctl -n hw.ncpu", "forever"); + $obj->{-value} = $out->{-stdout}; + $obj->{-value} =~ s/^\s*(.+?)\s*$/$1/s; + } + elsif ($self->{-ctx}->{-platform}->id() =~ m/Linux/i) { + # query dmesg(8) + # FIXME: this works only within a reasonable time after booting + # but I don't know any alternative method for querying the speed! + my $out = $self->{-ctx}->{-sys}->run("/sbin/dmesg", "forever"); + if ($out->{-stdout} =~ m|(\d+)(\.\d+)?[ -]*MHz|si) { + $obj->{-value} = $1; } } - elsif ($obj->{-name} =~ m|\.hwCpuSpeed$|) { - if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) { - # query dmesg(8) - # FIXME: this works only within a reasonable time after booting - # but I don't know any alternative method for querying the speed! - my $out = $self->{-ctx}->{-sys}->run("/sbin/dmesg", "forever"); - if ($out->{-stdout} =~ m|(\d+)(\.\d+)?[ -]*MHz|si) { - $obj->{-value} = $1; + elsif($self->{-ctx}->{-platform}->id() =~ m/SunOS/i) { + my $hwCpuNum = undef; + # $hwCpuSpeed see @dat[]->{hwCpuSpeed} + # $hwCpuTemp see @dat[]->{hwCpuTemp} + + # local workspace + my $out; my $raw; my @dat; my $arch; + + # initialize arch + $arch = $self->{-ctx}->{-platform}->arch(); + + # hwCpuSpeed + $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m"); + $raw = $out->{-stdout}; + if ($raw =~ m/\n=+ CPUs =+\n.*?\n---[ -]+\n(.*?)\n=+/s) { + $raw = $1; + foreach $line (split "\n", $raw) { + my ($brd,$cpu,$module,$mhz,$mb,$impl,$mask) = split(" ", $line); + if ($cpu =~ m/^\d+$/) { + @dat[$cpu] = {} if (not defined @dat[$cpu]); + @dat[$cpu]->{hwCpuSpeed} = $mhz; + } } } - } - elsif ($obj->{-name} =~ m|\.hwCpuTemp$|) { - if ($self->{-ctx}->{-platform}->id() =~ m/FreeBSD/i) { + + # hwCpuTemp + $out = $self->{-ctx}->{-sys}->run("/usr/platform/$arch/sbin/prtdiag -v", "1m"); + $raw = $out->{-stdout}; + if ($raw =~ m/\n=+ Environmental Status =+\n\nSystem Temperatures \(Celsius\):\n-+\n(.*?)\n=+/s) { + $raw = $1; + foreach $line (split "\n", $raw) { + my ($cpu,$temp) = split(" ", $line); + if ($cpu =~ m/CPU(\d+)/) { + $cpu = $1; + @dat[$cpu] = {} if (not defined @dat[$cpu]); + @dat[$cpu]->{hwCpuTemp} = $temp; + } + } + } + + # hwCpuNum + $hwCpuNum = $#{@dat} + 1; + + $obj->{-value} = $hwCpuNum if ($obj->{-name} =~ m/\.hwCpuNum$/); + if ($obj->{-name} =~ m/\.hwCpuInfoENTRY\.([^.]+)\.(\d+)$/) { + my $col = $1; + my $row = ($2 > 0 ? $2 - 1 : 0); + $self->{-ctx}->{-log}->printf(4, "col=%s row=%s", $col, $row); + $obj->{-value} = @dat[$row]->{$col} if (defined @dat[$row]->{$col}); } } return; Index: ossp-pkg/snmpdx/snmpdx.mib/snmpdx.mib RCS File: /v/ossp/cvs/ossp-pkg/snmpdx/snmpdx.mib/snmpdx.mib,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/snmpdx/snmpdx.mib/snmpdx.mib,v' 2>/dev/null --- snmpdx.mib 2003/09/04 12:36:36 1.3 +++ snmpdx.mib 2003/09/08 10:49:36 1.4 @@ -18,7 +18,7 @@ enterprises OBJECT IDENTIFIER ::= { private 1 } cw OBJECT IDENTIFIER ::= { enterprises 4007 } -snmpdx OBJECT IDENTIFIER ::= { cw 42 } +snmpdx OBJECT IDENTIFIER ::= { cw 43 } host OBJECT IDENTIFIER ::= { snmpdx 1 } hardware OBJECT IDENTIFIER ::= { host 1 } @@ -224,19 +224,39 @@ DESCRIPTION "number of CPUs" ::= { hwCpu 1 } -hwCpuSpeed OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only +hwCpuInfoTABLE OBJECT-TYPE + SYNTAX SEQUENCE OF HwCpuIndexENTRY + MAX-ACCESS not-accessible STATUS current - DESCRIPTION "number of CPUs" + DESCRIPTION "FIXME Table description!?" ::= { hwCpu 2 } +hwCpuInfoENTRY OBJECT-TYPE + SYNTAX HwCpuIndexENTRY + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION "FIXME Row description!?" + INDEX { hwCpuInfoIndex } + ::= { hwCpuInfoTABLE 1 } + +HwCpuIndexENTRY ::= SEQUENCE { + hwCpuSpeed Integer32, + hwCpuTemp Integer32 +} + +hwCpuSpeed OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS read-only + STATUS current + DESCRIPTION "CPU speed [MHz]" + ::= { hwCpuInfoENTRY 1 } + hwCpuTemp OBJECT-TYPE - SYNTAX Gauge32 + SYNTAX Integer32 MAX-ACCESS read-only STATUS current - DESCRIPTION "temperature of CPU" - ::= { hwCpu 3 } + DESCRIPTION "CPU temperature [Celsius]" + ::= { hwCpuInfoENTRY 3 } -- -- Hardware: RAM