[pve-devel] r5682 - in pve-cluster/trunk/data: . src

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Mar 11 07:49:59 CET 2011


Author: dietmar
Date: 2011-03-11 07:49:59 +0100 (Fri, 11 Mar 2011)
New Revision: 5682

Modified:
   pve-cluster/trunk/data/ChangeLog
   pve-cluster/trunk/data/src/status.c
Log:
rrd improvements


Modified: pve-cluster/trunk/data/ChangeLog
===================================================================
--- pve-cluster/trunk/data/ChangeLog	2011-03-11 06:28:52 UTC (rev 5681)
+++ pve-cluster/trunk/data/ChangeLog	2011-03-11 06:49:59 UTC (rev 5682)
@@ -2,6 +2,7 @@
 
 	* perl/Cluster.pm (rrd_dump): cache RRD data for one second (avoid
 	to many reads from API server)
+	(rrd_dump): parse RRD data
 
 	* src/status.c (update_rrd_data): add RRD definition for VMs 
 	(update_rrd_data): use thread safe API, connect to rrdcached

Modified: pve-cluster/trunk/data/src/status.c
===================================================================
--- pve-cluster/trunk/data/src/status.c	2011-03-11 06:28:52 UTC (rev 5681)
+++ pve-cluster/trunk/data/src/status.c	2011-03-11 06:49:59 UTC (rev 5682)
@@ -782,8 +782,9 @@
 
 static const char *rrd_def_node[] = {
 	"DS:loadavg:GAUGE:120:0:U",
-	"DS:cpu:GAUGE:120:0:1",
-	"DS:iowait:GAUGE:120:0:1",
+	"DS:maxcpu:GAUGE:120:0:U",
+	"DS:cpu:GAUGE:120:0:U",
+	"DS:iowait:GAUGE:120:0:U",
 	"DS:memtotal:GAUGE:120:0:U",
 	"DS:memused:GAUGE:120:0:U",
 	"DS:swaptotal:GAUGE:120:0:U",
@@ -809,7 +810,7 @@
 
 static const char *rrd_def_vm[] = {
 	"DS:maxcpu:GAUGE:120:0:U",
-	"DS:cpu:GAUGE:120:0:1",
+	"DS:cpu:GAUGE:120:0:U",
 	"DS:maxmem:GAUGE:120:0:U",
 	"DS:mem:GAUGE:120:0:U",
 	"DS:maxdisk:GAUGE:120:0:U",
@@ -871,6 +872,19 @@
 	}
 }
 
+static inline const char *
+rrd_skip_data(
+	const char *data,
+	int count)
+{
+	int found = 0;
+	while (*data && found < count) {
+		if (*data++ == ':')
+			found++;
+	}
+	return data;
+}
+
 static void 
 update_rrd_data(
 	const char *key,
@@ -892,9 +906,13 @@
 
 	char *filename = g_strdup_printf(RRDDIR "/%s", key);
 
-	if (strncmp(key, "pve-node/", 9) == 0) {
-		const char *node = key + 9;
+	int skip = 0;
 
+	if (strncmp(key, "pve2-node/", 10) == 0) {
+		const char *node = key + 10;
+
+		skip = 1;
+
 		if (strchr(node, '/') != NULL)
 			goto keyerror;
 
@@ -903,14 +921,16 @@
 		
 		if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 
-			mkdir(RRDDIR "/pve-node", 0755);
+			mkdir(RRDDIR "/pve2-node", 0755);
 			int argcount = sizeof(rrd_def_node)/sizeof(void*) - 1;
 			create_rrd_file(filename, argcount, rrd_def_node);
 		}
 		
-	} else if (strncmp(key, "pve-vm/", 7) == 0) {
-		const char *vmid = key + 7;
+	} else if (strncmp(key, "pve2-vm/", 8) == 0) {
+		const char *vmid = key + 8;
 
+		skip = 2;
+
 		if (strchr(vmid, '/') != NULL)
 			goto keyerror;
 
@@ -919,13 +939,13 @@
 
 		if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 
-			mkdir(RRDDIR "/pve-vm", 0755);
+			mkdir(RRDDIR "/pve2-vm", 0755);
 			int argcount = sizeof(rrd_def_vm)/sizeof(void*) - 1;
 			create_rrd_file(filename, argcount, rrd_def_vm);
 		}
 		
-	} else if (strncmp(key, "pve-storage/", 12) == 0) {
-		const char *node = key + 12;
+	} else if (strncmp(key, "pve2-storage/", 13) == 0) {
+		const char *node = key + 13;
 
 		const char *storage = node;
 		while (*storage && *storage != '/')
@@ -944,7 +964,7 @@
 
 		if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 
-			mkdir(RRDDIR "/pve-storage", 0755);
+			mkdir(RRDDIR "/pve2-storage", 0755);
 
 			char *dir = g_path_get_dirname(filename);
 			mkdir(dir, 0755);
@@ -958,8 +978,10 @@
 		goto keyerror;
 	}
 
-	const char *update_args[] = { data, NULL };
+	const char *dp = skip ? rrd_skip_data(data, skip) : data;
 
+	const char *update_args[] = { dp, NULL };
+
 	if (use_daemon) {
 		int status;
 		if ((status = rrdc_update(filename, 1, update_args)) != 0) {



More information about the pve-devel mailing list