[pve-devel] r5640 - in pve-manager/pve2: bin debian lib/PVE/API2
svn-commits at proxmox.com
svn-commits at proxmox.com
Thu Mar 3 09:15:26 CET 2011
Author: dietmar
Date: 2011-03-03 09:15:26 +0100 (Thu, 03 Mar 2011)
New Revision: 5640
Modified:
pve-manager/pve2/bin/pvestatd
pve-manager/pve2/debian/control.in
pve-manager/pve2/lib/PVE/API2/Nodes.pm
Log:
add some RRD test code
Modified: pve-manager/pve2/bin/pvestatd
===================================================================
--- pve-manager/pve2/bin/pvestatd 2011-03-03 07:14:23 UTC (rev 5639)
+++ pve-manager/pve2/bin/pvestatd 2011-03-03 08:15:26 UTC (rev 5640)
@@ -8,9 +8,19 @@
use Time::HiRes qw (gettimeofday);
use PVE::Tools;
use PVE::ProcFSTools;
+use Filesys::Df;
+use PVE::INotify;
initlog('pvestatd');
+$ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
+
+die "please run as root\n" if $> != 0;
+
+PVE::INotify::inotify_init();
+
+my $nodename = PVE::INotify::nodename();
+
my $opt_debug;
if (!GetOptions ('debug' => \$opt_debug)) {
@@ -107,9 +117,83 @@
$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 $start = $ctime - 60*10;
+
+ RRDs::create ($filename,
+ "-b" => $start,
+ "--step" => 60,
+ "DS:loadagv:GAUGE:300:0:U",
+ "DS:cpu:GAUGE:300:0:U",
+ "DS:iowait:GAUGE:300:0:U",
+ "DS:memtotal:GAUGE:300:0:U",
+ "DS:memused:GAUGE:300:0:U",
+ "DS:swaptotal:GAUGE:300:0:U",
+ "DS:swapused:GAUGE:300:0:U",
+ "DS:roottotal:GAUGE:300:0:U",
+ "DS:rootused:GAUGE:300:0:U",
+ "RRA:AVERAGE:0.5:1:60", # hourly - 1 min avg
+ "RRA:AVERAGE:0.5:5:288", # daily - 5 min avg
+ "RRA:AVERAGE:0.5:30:336", # 7 days - 30 min avg
+ "RRA:AVERAGE:0.5:120:420", # 5 weeks - 2 hour avg
+ "RRA:AVERAGE:0.5:1440:366", # yearly - 1 day avg
+ );
+ 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 $meminfo = PVE::ProcFSTools::read_meminfo();
+
+ my $dinfo = df('/', 1); # output is bytes
+
+ my $ctime = time();
+
+ my $data = "$ctime:$avg1:$stat->{cpu}:$stat->{wait}:" .
+ "$meminfo->{memtotal}:$meminfo->{memused}:" .
+ "$meminfo->{swaptotal}:$meminfo->{swapused}:" .
+ "$dinfo->{bavail}:$dinfo->{used}";
+
+ cond_create_node_rrd($nodename);
+
+ syslog("info", "node:$data");
+
+ my $filename = "$rrddir/pve-nodes/$nodename";
+ RRDs::update($filename, $data);
+
}
sub update_qemu_status {
@@ -146,7 +230,7 @@
# do not update directly after startup, because install scripts
# have a problem with that
my $cycle = 0;
-my $updatetime = 60;
+my $updatetime = 10;
my $commandline = [$0, @ARGV];
@@ -170,22 +254,24 @@
eval {
$next_update = time() + $updatetime;
- my ($ccsec, $cusec) = gettimeofday ();
- eval {
- $reload_config = 0;
- syslog('info', "start status update");
- update_status() if $cycle;
- };
- my $err = $@;
+ if ($cycle) {
+ my ($ccsec, $cusec) = gettimeofday ();
+ eval {
+ $reload_config = 0;
+ syslog('info', "start status update");
+ update_status();
+ };
+ my $err = $@;
- if ($err) {
- syslog('err', "status update error: $err");
- }
+ if ($err) {
+ syslog('err', "status update error: $err");
+ }
- my ($ccsec_end, $cusec_end) = gettimeofday ();
- my $cptime = ($ccsec_end-$ccsec) + ($cusec_end - $cusec)/1000000;
+ my ($ccsec_end, $cusec_end) = gettimeofday ();
+ my $cptime = ($ccsec_end-$ccsec) + ($cusec_end - $cusec)/1000000;
- syslog('info', sprintf("status update finished (%.2f seconds)", $cptime));
+ syslog('info', sprintf("status update finished (%.2f seconds)", $cptime));
+ }
$cycle++;
Modified: pve-manager/pve2/debian/control.in
===================================================================
--- pve-manager/pve2/debian/control.in 2011-03-03 07:14:23 UTC (rev 5639)
+++ pve-manager/pve2/debian/control.in 2011-03-03 08:15:26 UTC (rev 5640)
@@ -3,7 +3,7 @@
Section: admin
Priority: optional
Architecture: all
-Depends: perl5, libtimedate-perl, apache2-mpm-prefork, libauthen-pam-perl, libintl-perl, rsync, libapache2-request-perl, libjson-perl, libdigest-sha1-perl, vncterm, qemu-server (>= 1.1-1), libwww-perl, wget, libnet-dns-perl, vlan, ifenslave-2.6 (>= 1.1.0-10), liblinux-inotify2-perl, debconf (>= 0.5) | debconf-2.0, libjs-prototype (>= 1.6.0.3-1), netcat-traditional, pve-cluster, libpve-common-perl, libpve-storage-perl, libterm-readline-gnu-perl, libhttp-request-params-perl, libpve-access-control, libio-socket-ssl-perl, libfilesys-df-perl
+Depends: perl5, libtimedate-perl, apache2-mpm-prefork, libauthen-pam-perl, libintl-perl, rsync, libapache2-request-perl, libjson-perl, libdigest-sha1-perl, vncterm, qemu-server (>= 1.1-1), libwww-perl, wget, libnet-dns-perl, vlan, ifenslave-2.6 (>= 1.1.0-10), liblinux-inotify2-perl, debconf (>= 0.5) | debconf-2.0, libjs-prototype (>= 1.6.0.3-1), netcat-traditional, pve-cluster, libpve-common-perl, libpve-storage-perl, libterm-readline-gnu-perl, libhttp-request-params-perl, libpve-access-control, libio-socket-ssl-perl, libfilesys-df-perl, librrds-perl, rrdcached
Conflicts: netcat-openbsd
Maintainer: Proxmox Support Team <support at proxmox.com>
Description: The Proxmox Virtual Environment
Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm 2011-03-03 07:14:23 UTC (rev 5639)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm 2011-03-03 08:15:26 UTC (rev 5640)
@@ -137,7 +137,7 @@
$res->{swap} = {
free => $meminfo->{swapfree},
total => $meminfo->{swaptotal},
- used => $meminfo->{spawused},
+ used => $meminfo->{swapused},
};
$res->{pveversion} = PVE::pvecfg::package() . "/" .
More information about the pve-devel
mailing list