Snippets

RuWeb.net kvm iotop

Created by Andrey Chesnakov last modified
#!/usr/bin/env perl
use strict;
#use warnings;

my (%names,%read,%write,%rcount,%wcount,%rmax,%wmax,$ww,$rr);

while (<STDIN>) {
    chomp;
    if (/root\s+(\S+)\s+(\w)\s+(\S+)\s+(\w).*name\s(\S+)$/) {
        $rr=$1;
        if ($2 eq 'G') { $rr*=1024; }
        if ($2 eq 'M' || $2 eq 'G') {
            $read{$5}+=$rr;
            $rcount{$5}++;
            if ($rmax{$5}<$rr) { $rmax{$5}=$rr }
            $names{$5}=1;
        }
        $ww=$3;
        if ($4 eq 'G') { $ww*=1024; }
        if ($4 eq 'M' || $4 eq 'G') {
            $write{$5}+=$ww;
            $wcount{$5}++;
            if ($wmax{$5}<$ww) { $wmax{$5}=$ww }
            $names{$5}=1;
        }
    }
}
print "READ_SUM;READ_COUNT;READ_AVG;READ_MAX WRITE_SUM;WRITE_COUNT;WRITE_AVG;WRITE_MAX NAME\n";
foreach (keys %names) {
    printf ("%.0f;%d;%.0f;%.0f %.0f;%d;%.0f;%.0f %s\n",$read{$_},$rcount{$_},($rcount{$_}?$read{$_}/$rcount{$_}:0),$rmax{$_},$write{$_},$wcount{$_},($wcount{$_}?$write{$_}/$wcount{$_}:0),$wmax{$_},$_);
}
1
2
3
4
5
6
7
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

[ -n "$1" ] && delay=$1 || delay=60

pidof kvm | sed 's/ / -p/g' | xargs iotop -o -P -d "$delay" -n 2 -a -b -p \
    | perl -pe 's/(.* % kvm -id \d+).*(-name \S+).*/$1 $2/' >/var/lib/vz/iotop/`date '+%d.%H:%M:%S'`

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.