Mercurial > openvz
changeset 5:464dea07deb8 default tip
Add vzps replacements.
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Wed, 07 May 2014 16:23:45 +0200 |
parents | c2cff30df6dc |
children | |
files | add_vzps.pl vz_ps.pl |
diffstat | 2 files changed, 70 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_vzps.pl Wed May 07 16:23:45 2014 +0200 @@ -0,0 +1,20 @@ +#!/usr/bin/perl +# +# (c)Peter Gervai, 2013 +# +# use: ps awxuf | add_vzps.pl +# + +while( <> ) { + my @cmd = split /\s+/; + my $pid = $cmd[1]; + if( -r "/proc/$pid/status" ) { + my $veid_line = qx( /bin/grep 'envID:' /proc/$pid/status ); + if( $veid_line =~ /envID:\s+(\d+)/ ) { + print $1, '; ', $_; + + } else { + print "SKIP $veid_line "; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vz_ps.pl Wed May 07 16:23:45 2014 +0200 @@ -0,0 +1,50 @@ +#!/usr/bin/perl +# $Id: vz_ps.pl,v a19295214a68 2013/10/29 15:31:42 grin $ +# (c) Petre Gervai, 2011-2013 +# Released under CreativeCommons Attribution-ShareAlike v3.0 unported +# CC-BY-SA-3.0-unp +# +# Show OpenVZ info using stock ps output instead of hacking it in +# + +use warnings; +use strict; +use IO::File; + +my $ps = "/bin/ps"; + +my $f; + +if( $#ARGV == 0 ) { + # use 'spawn ps' mode + $f = new IO::File 'ps ' . join(' ', @ARGV) . " |" or die $!; + +} else { + # get data on stdin + $f = IO::Handle->new_from_fd( fileno(STDIN), 'r' ); +} + +# get header +my $hdr = <$f>; +if( $hdr !~ /PID/ ) { + print "Error: ps header doesn't contain PID, it's something I cannot accept. I'm going.\n"; + exit 1; +} + +my $pos; +$hdr =~ s/^\s*(.+?)\s*$/$1/; # remove head/trail spc +my @head = split /\s+/, $hdr; +while( my ($i,$val) = each @head ) { + if( $val=~ /^PID$/ ) { + $pos = $i; + last; + } +} + +use Data::Dumper; +print Dumper( \@head, $pos ); +die; + +while( <$f> ) { + +}