D.1. A Simple Kstat Walker#!/usr/bin/perl -w # # kgrep - walk the Kstat tree, grepping names. # # This is a simple demo of walking the Kstat tree in Perl. The output # is similar to a "kstat -p", however an argument can be provided to # grep the full statistic name (joined by ":"). # # USAGE: kgrep [pattern] # eg, kgrep hme0 use strict; use Sun::Solaris::Kstat; my $Kstat = Sun::Solaris::Kstat->new(); my $pattern = defined $ARGV[0] ? $ARGV[0] : "."; die "USAGE: kgrep [pattern]\n" if $pattern eq "-h"; # loop over all kstats foreach my $module (keys(%$Kstat)) { my $Modules = $Kstat->{$module}; foreach my $instance (keys(%$Modules)) { my $Instances = $Modules->{$instance}; foreach my $name (keys(%$Instances)) { my $Names = $Instances->{$name}; foreach my $stat (keys(%$Names)) { my $value = $$Names{$stat}; # print kstat name and value printf "%-50s %s\n", "$module:$instance:$name:$stat", $value if "$module:$instance:$name:$stat" =~ /$pattern/; } } } } |