Cacti & FreeBSD Jail CPU & RAM monitoring

Philippe Lang philippe.lang at attiksystem.ch
Tue Aug 15 15:16:39 UTC 2006


Hi,

Based on answers of my first post, I wrote a small perl script in order to find out the CPU and MEMORY used by each jail.
Here it is:

------------------------------------------------------
- jls.ps
------------------------------------------------------
#!/usr/bin/perl
@jails = `jls`;
$title = shift @jails;
chomp $title;
print $title . "\t\t%CPU\t%MEM\n";
foreach (@jails)
{
  my ($jid) = /\s+(\S+)\s/;
  @jexec = `jexec $jid ps -afxu`;

  @mem = map {/\S+\s+\S+\s+\S+\s+(\S+)\s/} @jexec;
  shift @mem;
  $tot_mem = 0;
  foreach (@mem) { $tot_mem = $tot_mem + $_; }

  @cpu = map {/\S+\s+\S+\s+(\S+)\s/} @jexec;
  shift @cpu;
  $tot_cpu = 0;
  foreach (@cpu) { $tot_cpu = $tot_cpu + $_; }

  chomp $_;
  print $_ . "\t$tot_cpu\t$tot_mem\n";
}
------------------------------------------------------

I still haven't connected anything to cacti yet, but I wanted to share that. I think it can be quite useful.

Cheers,

----------------------------------
Philippe Lang, Ing. Dipl. EPFL
Attik System
rte de la Fonderie 2
1700 Fribourg
Switzerland
http://www.attiksystem.ch

Tel:  +41 (26) 422 13 75
Fax:  +41 (26) 422 13 76  


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3125 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20060815/554d4125/smime.bin


More information about the freebsd-questions mailing list