[pve-devel] Count monthly traffic

Stefan Priebe - Profihost AG s.priebe at profihost.ag
Wed Apr 17 14:29:02 CEST 2013


Am 17.04.2013 14:17, schrieb Dietmar Maurer:
>> Nowhere ;-) how about just return the counter values for the correct tap device
>> through API?
>>
>> So it is basically:
>> 1.) a wrapper from netX to correct tap
>> 2.) query tap counter inout / output values
>> 3.) allow to query this through API
>>
>> So it is at least possible to implement traffic account in external software. You
>> jsut have to query the API every X seconds and detect resets yourself. It acts
>> than basically like SNMP traffic counters in switches.
> 
> sounds reasonable.

Then let's go this way. It's much simpler than adding RRD.

So the question is should this be a completely new call or do you want
to add a new hash key to  sub vmstatus { ?

this could be

    my $netdev = PVE::ProcFSTools::read_proc_net_dev();
    foreach my $dev (keys %$netdev) {
        next if $dev !~ m/^tap([1-9]\d*)i/;
        my $vmid = $1;
        my $d = $res->{$vmid};
        next if !$d;

        $d->{netout} += $netdev->{$dev}->{receive};
        $d->{netin} += $netdev->{$dev}->{transmit};
    }

converted to:

    my $netdev = PVE::ProcFSTools::read_proc_net_dev();
    foreach my $dev (keys %$netdev) {
        next if $dev !~ m/^tap([1-9]\d*)i(\d+)/;
        my $vmid = $1;
        my $netid = $2;
        my $d = $res->{$vmid};
        next if !$d;

        $d->{netout} += $netdev->{$dev}->{receive};
        $d->{netin} += $netdev->{$dev}->{transmit};
        $d->{traffic}{'net'.$netid}{netout} = $netdev->{$dev}{receive};
        $d->{traffic}{'net'.$netid}{netin} = $netdev->{$dev}{transmit};
    }


Stefan



More information about the pve-devel mailing list