[pve-devel] r5683 - in pve-manager/pve2: bin lib/PVE/API2

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Mar 11 08:04:24 CET 2011


Author: dietmar
Date: 2011-03-11 08:04:24 +0100 (Fri, 11 Mar 2011)
New Revision: 5683

Modified:
   pve-manager/pve2/bin/pvestatd
   pve-manager/pve2/lib/PVE/API2/Cluster.pm
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
Log:
use RRD data


Modified: pve-manager/pve2/bin/pvestatd
===================================================================
--- pve-manager/pve2/bin/pvestatd	2011-03-11 06:49:59 UTC (rev 5682)
+++ pve-manager/pve2/bin/pvestatd	2011-03-11 07:04:24 UTC (rev 5683)
@@ -128,13 +128,21 @@
     $reload_config = 1;
 };
 
-sub update_host_status {
+sub update_node_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 ($uptime) = PVE::ProcFSTools::read_proc_uptime();
+
+    my $cpuinfo = PVE::ProcFSTools::read_cpuinfo();
+
+    my $maxcpu = $cpuinfo->{cpus}; 
+
+    # traffic from/to physical interface cards
     my $netin = 0;
     my $netout = 0;
     foreach my $dev (keys %$netdev) {
@@ -152,12 +160,12 @@
     # everything not free is considered to be used
     my $dused = $dinfo->{blocks} - $dinfo->{bfree};
 
-    my $data = "$ctime:$avg1:$stat->{cpu}:$stat->{wait}:" .
+    my $data = "$uptime:$ctime:$avg1:$maxcpu:$stat->{cpu}:$stat->{wait}:" .
 	"$meminfo->{memtotal}:$meminfo->{memused}:" .
 	"$meminfo->{swaptotal}:$meminfo->{swapused}:" .
 	"$dinfo->{blocks}:$dused:$netin:$netout";
 
-    PVE::Cluster::broadcast_rrd("pve-node/$nodename", $data);
+    PVE::Cluster::broadcast_rrd("pve2-node/$nodename", $data);
 }
 
 sub update_qemu_status {
@@ -170,12 +178,12 @@
 	my $d = $vmstatus->{$vmid};
 	next if !$d->{pid}; # not running
 
-	my $data = "$ctime:$d->{cpus}:$d->{cpu}:" .
+	my $data = "$d->{uptime}:$d->{name}:$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);
+	PVE::Cluster::broadcast_rrd("pve2-vm/$vmid", $data);
     }
 }
 
@@ -196,7 +204,7 @@
 
 	my $data = "$ctime:$d->{total}:$realused";
 
-	my $key = "pve-storage/${nodename}/$storeid";
+	my $key = "pve2-storage/${nodename}/$storeid";
 	PVE::Cluster::broadcast_rrd($key, $data);
     }
 }
@@ -204,10 +212,10 @@
 sub update_status {
 
     eval {
-	update_host_status();
+	update_node_status();
     };
     my $err = $@;
-    syslog('err', "host status update error: $err") if $err;
+    syslog('err', "node status update error: $err") if $err;
 
     eval {
 	update_qemu_status();

Modified: pve-manager/pve2/lib/PVE/API2/Cluster.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Cluster.pm	2011-03-11 06:49:59 UTC (rev 5682)
+++ pve-manager/pve2/lib/PVE/API2/Cluster.pm	2011-03-11 07:04:24 UTC (rev 5683)
@@ -116,33 +116,33 @@
 
 	my @sids =  PVE::Storage::storage_ids ($cfg);
 
-	# fixme: add storage status ('disk', 'maxdisk')
- 
+	my $rrd = PVE::Cluster::rrd_dump();
+
 	my $res = [];
 	foreach my $storeid (@sids) {
 	    my $scfg =  PVE::Storage::storage_config ($cfg, $storeid);
 
 	    next if !$rpcenv->check($user, "/storage/$storeid", [ 'Datastore.Audit' ]);
 
-	    if ($scfg->{shared}) {
-		push @$res,{ 
-		    name => $storeid, 
+	    # we create a entry for each node
+	    foreach my $nd (@$nodes) {
+		my $node = $nd->{node};
+		# fixme: check if storage is available on this node
+		my $entry = { 
+		    name => "$storeid ($node)", 
 		    storage => $storeid, 
+		    node => $node, 
 		    type => $scfg->{type}, 
-		    shared => 1
+		    shared => $scfg->{shared},
 		}; 
-	    } else {
-		# we create a entry for each node
-		foreach my $nd (@$nodes) {
-		    my $node = $nd->{node};
-		    push @$res, { 
-			name => "$storeid ($node)", 
-			storage => $storeid, 
-			node => $node, 
-			type => $scfg->{type}, 
-			shared => 0
-		    }; 
+
+		if (my $d = $rrd->{"pve-storage/$node/$storeid"}) {
+		    $entry->{maxdisk} = $d->[1];
+		    $entry->{disk} = $d->[2];
 		}
+
+		push @$res, $entry;
+
 	    }
 	}
 
@@ -175,34 +175,52 @@
 	my $user = $rpcenv->get_user();
 
 	my $vmlist = PVE::Cluster::get_vmlist();
-	my $result = [];
+	my $res = [];
 
-	return $result if !$vmlist;
+	return $res if !$vmlist;
 
+	my $rrd = PVE::Cluster::rrd_dump();
+
 	my $idlist = $vmlist->{ids};
-	return $result if !$idlist;
+	return $res if !$idlist;
 
 	foreach my $vmid (keys %$idlist) {
 	    my $data = $idlist->{$vmid};
 
 	    next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
 
-	    push @$result, { 
+	    my $entry = {
 		id => $vmid, 
 		name => "VM $vmid", 
 		node => $data->{node},
 		type => $data->{type},
-		cpu => 0, 
-		maxcpu => 1, 
-		mem => 1024*1024*1024*6, 
-		maxmem => 1024*1024*1024*24, 
-		disk => 1024*1024*1024*1024*6, 
-		maxdisk => 1024*1024*1024*1024*32, 
-		uptime => 2*3600 
+#		cpu => 0, 
+#		maxcpu => 1, 
+#		mem => 1024*1024*1024*6, 
+#		maxmem => 1024*1024*1024*24, 
+#		disk => 1024*1024*1024*1024*6, 
+#		maxdisk => 1024*1024*1024*1024*32, 
+#		uptime => 2*3600 
 	    };
+
+	    if (my $d = $rrd->{"pve-vm/$vmid"}) {
+
+		$entry->{uptime} = $d->[0];
+		$entry->{name} = $d->[1];
+
+		$entry->{maxcpu} = $d->[3];
+		$entry->{cpu} = $d->[4];
+		$entry->{maxmem} = $d->[5];
+		$entry->{mem} = $d->[6];
+		$entry->{maxdisk} = $d->[7];
+		$entry->{disk} = $d->[8];
+	    }
+
+	    push @$res, $entry;
+
 	}
    
-	return $result;
+	return $res;
     }});
 
 1;

Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-11 06:49:59 UTC (rev 5682)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-03-11 07:04:24 UTC (rev 5683)
@@ -163,6 +163,7 @@
     name => 'rrd', 
     path => 'rrd', 
     method => 'GET',
+    protected => 1, # fixme: can we avoid that?
     permissions => {
 	path => '/nodes/{node}',
 	privs => [ 'Sys.Audit' ],
@@ -192,12 +193,13 @@
 
 	my $rrddir = "/var/lib/rrdcached/db";
 
-	my $rrd = "$rrddir/pve-nodes/$param->{node}";
+	my $rrd = "$rrddir/pve2-node/$param->{node}";
 
 	# fixme: use cache daemon ?
 
 	RRDs::graph(
 	    $filename,
+	    "--daemon" => "unix:/var/run/rrdcached.sock",	    
 	    "--imgformat" => "PNG",
 	    "--border" => 0,
 	    "--height" => 200,
@@ -213,6 +215,9 @@
 	    "LINE2:iowaitper#ff0000:io delay",
 	    );
 
+	my $err = RRDs::error;
+	die "RRD error: $err\n" if $err;
+
 	return { filename => $filename };
     }});
 
@@ -249,7 +254,7 @@
 	my ($param) = @_;
 
 	my $rrddir = "/var/lib/rrdcached/db";
-	my $filename = "$rrddir/pve-nodes/$param->{node}";
+	my $filename = "$rrddir/pve2-node/$param->{node}";
 
 	my $setup = {
 	    hour =>  [ 60, 70 ],
@@ -263,6 +268,8 @@
 	my $ctime  = $reso*int(time()/$reso);
 	my $req_start = $ctime - $reso*$count;
 
+	print "TEST $filename\n";
+
 	my ($start, $step, $names, $data) = 
 	    RRDs::fetch($filename, 'AVERAGE',
 			"-s" => $req_start,
@@ -270,11 +277,12 @@
 			"-r" => $reso,
 			"--daemon" => "unix:/var/run/rrdcached.sock");
 
+	my $err = RRDs::error;
+	die "RRD error: $err\n" if $err;
+
 	die "got wrong time resolution ($step != $reso)\n" 
 	    if $step != $reso;
 
-	my $err = RRDs::error;
-	die "RRD error: $err\n" if $err;
 
 	my $res = [];
 	my $fields = scalar(@$names);
@@ -717,35 +725,32 @@
 	my ($param) = @_;
  
 	my $clinfo = PVE::Cluster::get_clinfo();
-	my $result = [];
+	my $res = [];
 
 	my $nodename = PVE::INotify::nodename();
 	my $nodelist = $clinfo->{nodelist};
 
-	if (!$nodelist) {
-	    push @$result, { 
-		name => $nodename,
-		cpu => 0.5,
-		maxcpu => 16,
-		uptime => 20*3600*24,
-		mem => 0,
-		maxmem => 10
-	    };
-	    return $result;
-	}
+	my $rrd = PVE::Cluster::rrd_dump();
 
-	foreach my $node (keys %$nodelist) {
-	    push @$result, { 
-		name => $node,
-		cpu => 0.1,
-		maxcpu => 8,
-		uptime => 10*3600*24,
-		mem => 0,
-		maxmem => 10
-	    };
+	my @nodes = $nodelist ? (keys %$nodelist) : $nodename;
+
+	foreach my $node (@nodes) {
+	    my $entry = { name => $node };
+	    if (my $d = $rrd->{"pve2-node/$node"}) {
+
+		$entry->{uptime} = $d->[0];
+		$entry->{maxcpu} = $d->[3];
+		$entry->{cpu} = $d->[4];
+		$entry->{maxmem} = $d->[6];
+		$entry->{mem} = $d->[7];
+		$entry->{maxdisk} = $d->[10];
+		$entry->{disk} = $d->[11];
+	    }
+
+	    push @$res, $entry;
 	}
 
-	return $result;
+	return $res;
     }});
 
 1;




More information about the pve-devel mailing list