I used the following. May not be pretty but it seems to wrk.
sub get_kstats { ####################################################### # Desctiption: Collects stats from Solaris::Kstat # Arguments: NONE # RETURNS: @KSTAT_DATA ######################################################## my $date = &get_date(); my $COLUMNS = "hostname, pdate, kstat_module, kstat_inst, kstat_name, kstat_key, kstat_value" ; my $QHEAD = "INSERT into solaris2_kstat ($COLUMNS) VALUES('$host','$date'"; my $kstat = Solaris::Kstat->new(); my $cpu_count = --($kstat->{unix}{0}{system_misc}{"ncpus"}); for (my $i = 0 ; $i <= $cpu_count; $i++) { my ($usr1, $sys1, $wio1, $idle1 ) = @{$kstat->{cpu_stat}{$i}{"cpu_stat"."$i"}}{qw(user kernel wait idle)};; push(@KSTAT_DATA, "$QHEAD,'cpu_stat','$i','cpu_stat$i','user','$usr1')\n"); push(@KSTAT_DATA, "$QHEAD,'cpu_stat','$i','cpu_stat$i','kernel','$sys1')\n"); push(@KSTAT_DATA, "$QHEAD,'cpu_stat','$i','cpu_stat$i','wait','$wio1')\n"); push(@KSTAT_DATA, "$QHEAD,'cpu_stat','$i','cpu_stat$i','idle','$idle1')\n"); } my ( $freemem,$swap_alloc,$swap_avail,$swap_free,$swap_resv ) = @{$kstat->{unix}{0}{vminfo}}{qw(freemem swap_alloc swap_avail swap_free swap_resv)};; push(@KSTAT_DATA, "$QHEAD,'unix','0','vminfo','freemem','$freemem')\n"); push(@KSTAT_DATA, "$QHEAD,'unix','0','vminfo','swap_alloc','$swap_alloc')\n"); push(@KSTAT_DATA, "$QHEAD,'unix','0','vminfo','swap_avail','$swap_avail')\n"); push(@KSTAT_DATA, "$QHEAD,'unix','0','vminfo','swap_free','$swap_free')\n"); push(@KSTAT_DATA, "$QHEAD,'unix','0','vminfo','swap_resv','$swap_resv')\n"); return ( @KSTAT_DATA ); } On Thu, 2002-05-23 at 21:55, Scot Needy wrote: > Hi again all; > > Man this list is busy.... > > OK I am back to Solaris::Kstat > Kstat is a Nested hash which can be displayed something like this > foreach my $m (sort(keys(%$ks))) > { > foreach my $i (sort(keys(%{$ks->{$m}}))) > { > foreach my $n (sort(keys(%{$ks->{$m}->{$i}}))) > { > foreach my $k (sort(keys(%{$ks->{$m}->{$i}->{$n}}))) > { > print("$m.$i.$n $k = $ks->{$m}->{$i}->{$n}->{$k}\n"); > } > print("\n"); > } > } > } > > But I dont want to loop through the thing. I already know what I want > and am trying to insert the key value pairs into mysql but am running > into a bit of a problem escaping quotes. Soo .... > > How would one turn this into an @rray of SQL which is returned from a > subroutine. Sorry for the long post but here is where I am stuck > > sub get_kstats { > ####################################################### > # Desctiption: Collects stats from Solaris::Kstat > # Arguments: NONE > # RETURNS: @KSTAT_DATA > # module.instance#.name key = value > # print("$m.$i.$n $k = $ks->{$m}->{$i}->{$n}->{$k}\n"); > # table solaris2_kstat ( > # hostname char(50) not null, > # pdate datetime not null, > # kstat_module char(50) not null, > # kstat_inst int default 0 not null, > # kstat_name char(25) not null, > # kstat_key char(25) not null, > # kstat_value char(25) not null, > ####################################################### > use Solaris::Kstat; > my $date = &get_date(); > my $COLUMNS = "hostname, pdate, kstat_module, kstat_inst, > kstat_name, kstat_key, kstat_value"; > my $QHEAD = "INSERT into solaris2_kstat ($COLUMNS) VALUES("; > my $kstat = Solaris::Kstat->new(); > my $cpu_count = --($kstat->{unix}{0}{system_misc}{"ncpus"})|| > die "You Have No CPU's!\n"; > for (my $i = 0 ; $i <= $cpu_count; $i++) { > my ($usr1, $sys1, $wio1, $idle1 ) = > @{$kstat->{cpu_stat}{$i}{"cpu_stat"."$i"}} > {qw(user kernel wait idle)};; > my K_VALUES="'cpu_stat','$i','cpu_stat$i',THIS ISN'T PRETTY > push (@KSTAT_DATA, "$QHEAD"."$KVALUES\n"); > undef $KVALUES; > > > } > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]