[pve-devel] r5676 - pve-manager/pve2/bin

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Mar 10 12:25:43 CET 2011


Author: dietmar
Date: 2011-03-10 12:25:43 +0100 (Thu, 10 Mar 2011)
New Revision: 5676

Modified:
   pve-manager/pve2/bin/pvestatd
Log:
remove RRDs code in pvestatd


Modified: pve-manager/pve2/bin/pvestatd
===================================================================
--- pve-manager/pve2/bin/pvestatd	2011-03-10 11:21:35 UTC (rev 5675)
+++ pve-manager/pve2/bin/pvestatd	2011-03-10 11:25:43 UTC (rev 5676)
@@ -10,8 +10,9 @@
 use PVE::ProcFSTools;
 use Filesys::Df;
 use PVE::INotify;
-use PVE::Cluster;
-use Time::Local;
+use PVE::Cluster qw(cfs_read_file);
+use PVE::Storage;
+use PVE::QemuServer;
 
 $SIG{'__WARN__'} = sub {
     my $err = $@;
@@ -127,97 +128,77 @@
     $reload_config = 1;
 };
 
-# fixme: remove all RRD related code and move it to pve-cluster
-# Note: we want a distributed RRD database
-# START RRD CODE
-use RRDs;
-
-my $rrddir = "/var/lib/rrdcached/db";
-mkdir $rrddir;
-mkdir "$rrddir/pve-vms";
-mkdir "$rrddir/pve-nodes";
-
-sub check_err {
-    my $ERR=RRDs::error;
-    die "RRD ERROR: $ERR\n" if $ERR;
-}
-my $filename_hash = {};
-
-sub cond_create_node_rrd {
-    my ($node) = @_;
-
-    my $filename = "$rrddir/pve-nodes/$node";
-    return if $filename_hash->{$filename};
-
-    return if -f $filename;
-
-    my $ctime  = 60*int(time/60);
-
-    my (undef, undef, undef, $mday, $mon, $year) = localtime(time);
-    # start at day boundary
-    my $start = timelocal(0,0,0,$mday,$mon,$year);
-
-    RRDs::create ($filename, 
-		  "-b" => $start,
-		  "--step" => 60,
-		  "DS:loadavg:GAUGE:120:0:U",
-		  "DS:cpu:GAUGE:120:0:1",
-		  "DS:iowait:GAUGE:120:0:1",
-		  "DS:memtotal:GAUGE:120:0:U",
-		  "DS:memused:GAUGE:120:0:U",
-		  "DS:swaptotal:GAUGE:120:0:U",
-		  "DS:swapused:GAUGE:120:0:U",
-		  "DS:roottotal:GAUGE:120:0:U",
-		  "DS:rootused:GAUGE:120:0:U",
-
-		  "RRA:AVERAGE:0.5:1:70", # 1 min avg - one hour
-		  "RRA:AVERAGE:0.5:30:70", # 30 min avg - one day
-		  "RRA:AVERAGE:0.5:180:70", # 3 hour avg - one week
-		  "RRA:AVERAGE:0.5:720:70", # 12 hour avg - one month
-		  "RRA:AVERAGE:0.5:10080:70", # 7 day avg - ony year
-
-		  "RRA:MAX:0.5:1:70", # 1 min max - one hour
-		  "RRA:MAX:0.5:30:70", # 30 min max - one day
-		  "RRA:MAX:0.5:180:70", # 3 hour max - one week
-		  "RRA:MAX:0.5:720:70", # 12 hour max - one month
-		  "RRA:MAX:0.5:10080:70", # 7 day max - ony year
-	);
-    check_err();
-
-    $filename_hash->{$filename} = 1;
-
-}
-
-# END RRD CODE
-
 sub update_host_status {
 
     my ($avg1, $avg5, $avg15) = PVE::ProcFSTools::read_loadavg();
 
     my $stat = PVE::ProcFSTools::read_proc_stat();
+
+    my $netdev = PVE::ProcFSTools::read_proc_net_dev();
+    my $netin = 0;
+    my $netout = 0;
+    foreach my $dev (keys %$netdev) {
+	next if $dev !~ m/^eth\d+$/;
+	$netin += $netdev->{$dev}->{receive};
+	$netout += $netdev->{$dev}->{transmit};
+    }
  
     my $meminfo = PVE::ProcFSTools::read_meminfo();
 
     my $dinfo = df('/', 1);     # output is bytes
 
     my $ctime = time();
-    
+
+    # everything not free is considered to be used
+    my $dused = $dinfo->{blocks} - $dinfo->{bfree};
+
     my $data = "$ctime:$avg1:$stat->{cpu}:$stat->{wait}:" .
 	"$meminfo->{memtotal}:$meminfo->{memused}:" .
 	"$meminfo->{swaptotal}:$meminfo->{swapused}:" .
-	"$dinfo->{blocks}:$dinfo->{bfree}";
+	"$dinfo->{blocks}:$dused:$netin:$netout";
 
-    syslog("info", "node:$data");
-
-    PVE::Cluster::broadcast_rrd("pve-nodes/$nodename", $data);
+    PVE::Cluster::broadcast_rrd("pve-node/$nodename", $data);
 }
 
 sub update_qemu_status {
 
+    my $ctime = time();
+
+    my $vmstatus = PVE::QemuServer::vmstatus();
+
+    foreach my $vmid (keys %$vmstatus) {
+	my $d = $vmstatus->{$vmid};
+	next if !$d->{pid}; # not running
+
+	my $data = "$ctime:$d->{cpus}:$d->{cpu}:" .
+	    "$d->{maxmem}:$d->{mem}:" .
+	    "$d->{maxdisk}:$d->{disk}:" .
+	    "$d->{netin}:$d->{netout}";
+
+	PVE::Cluster::broadcast_rrd("pve-vm/$vmid", $data);
+    }
 }
 
 sub update_storage_status {
 
+    my $cfg = cfs_read_file("storage.cfg");
+
+    my $ctime = time();
+
+    my $info = PVE::Storage::storage_info($cfg);
+
+    foreach my $storeid (keys %$info) {
+	my $d = $info->{$storeid};
+	next if !$d->{active};
+
+	# everything not free is considered to be used
+	my $realused = $d->{total} - $d->{avail};
+
+	my $data = "$ctime:$d->{total}:$realused";
+
+	my $key = "pve-storage/${nodename}_$storeid";
+	PVE::Cluster::broadcast_rrd($key, $data);
+    }
 }
 
 sub update_status {




More information about the pve-devel mailing list