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

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Mar 10 08:28:47 CET 2011


Author: dietmar
Date: 2011-03-10 08:28:47 +0100 (Thu, 10 Mar 2011)
New Revision: 5673

Modified:
   pve-cluster/trunk/data/ChangeLog
   pve-cluster/trunk/data/src/status.c
Log:
add RRD definition for VMs 


Modified: pve-cluster/trunk/data/ChangeLog
===================================================================
--- pve-cluster/trunk/data/ChangeLog	2011-03-10 06:13:54 UTC (rev 5672)
+++ pve-cluster/trunk/data/ChangeLog	2011-03-10 07:28:47 UTC (rev 5673)
@@ -1,5 +1,7 @@
 2011-03-10  Proxmox Support Team  <support at proxmox.com>
 
+	* src/status.c (update_rrd_data): add RRD definition for VMs 
+
 	* src/dfsm.c (dfsm_send_message_full): limit to 100 retries (max
 	10 seconds delay).
 

Modified: pve-cluster/trunk/data/src/status.c
===================================================================
--- pve-cluster/trunk/data/src/status.c	2011-03-10 06:13:54 UTC (rev 5672)
+++ pve-cluster/trunk/data/src/status.c	2011-03-10 07:28:47 UTC (rev 5673)
@@ -811,9 +811,64 @@
 	NULL,
 };
 
+static char *rrd_def_vm[] = {
+	"create",
+	NULL, /* filename */
+	"-b",
+	NULL, /* starttime */
+	"--step", "60",
+	"DS:maxcpu:GAUGE:120:0:U",
+	"DS:cpu:GAUGE:120:0:1",
+	"DS:maxmem:GAUGE:120:0:U",
+	"DS:mem:GAUGE:120:0:U",
+	"DS:maxdisk:GAUGE:120:0:U",
+	"DS:disk:GAUGE:120:0:U",
+	"DS:netin:COUNTER:120:0:U",
+	"DS:netout:COUNTER: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
+	NULL,
+};
+
+
 #define RRDDIR "/var/lib/rrdcached/db"
 
+static void
+create_rrd_file(
+	char *filename,
+	int argcount,
+	char *rrddef[])
+{
+	/* start at day boundary */
+	time_t ctime;
+	time(&ctime);
+	struct tm *ltm = localtime(&ctime);
+	ltm->tm_sec = 0;
+	ltm->tm_min = 0;
+	ltm->tm_hour = 0;
+
+	char *start = g_strdup_printf("%lu", timelocal(ltm));
+
+	rrddef[1] = filename;
+	rrddef[3] = start;
+
+	if (rrd_create(argcount, rrddef) != 0) {
+		cfs_message("RRD create error %s: %s", filename, rrd_get_error());
+	}
+
+	g_free(start);
+}
+
 static void 
 update_rrd_data(
 	const char *key,
@@ -827,48 +882,42 @@
 
 	// fixme: when do we remove old entries ?
 
+	char *filename = g_strdup_printf(RRDDIR "/%s", key);
+
 	if (strncmp(key, "pve-nodes/", 10) == 0) {
 		const char *node = key + 10;
 		g_return_if_fail(strchr(node, '/') == NULL);
 		
-		char *filename = g_strdup_printf(RRDDIR "/pve-nodes/%s", node);
-
 		if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 
-			/* start at day boundary */
-			time_t ctime;
-			time(&ctime);
-			struct tm *ltm = localtime(&ctime);
-			ltm->tm_sec = 0;
-			ltm->tm_min = 0;
-			ltm->tm_hour = 0;
-
-			char *start = g_strdup_printf("%lu", timelocal(ltm));
-
+			mkdir(RRDDIR "/pve-nodes", 0755);
 			int argcount = sizeof(rrd_def_node)/sizeof(void*) - 1;
-
-			rrd_def_node[1] = filename;
-			rrd_def_node[3] = start;
-
-			mkdir(RRDDIR "/pve-nodes", 0755);
-			if (rrd_create(argcount, rrd_def_node) != 0) {
-				cfs_message("RRD create error %s: %s", filename, rrd_get_error());
-			}
-
-			g_free(start);
+			create_rrd_file(filename, argcount, rrd_def_node);
 		}
+		
+	} else if (strncmp(key, "pve-vms/", 8) == 0) {
+		const char *vmid = key + 10;
+		g_return_if_fail(strchr(vmid, '/') == NULL);
+		
+		if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
 
-		char *update_args[] = {
-			"update", filename, data, 
-			NULL,
-		};
-
-		if (rrd_update(3, update_args) != 0) {
-			cfs_message("RRD update error %s: %s", filename, rrd_get_error());
+			mkdir(RRDDIR "/pve-vms", 0755);
+			int argcount = sizeof(rrd_def_vm)/sizeof(void*) - 1;
+			create_rrd_file(filename, argcount, rrd_def_vm);
 		}
 		
-		g_free(filename);
+	} else {
+		cfs_critical("RRD update error: unknown key %s", key);
+		return;
 	}
+
+	char *update_args[] = { "update", filename, (char*)data, NULL };
+
+	if (rrd_update(3, update_args) != 0) {
+		cfs_message("RRD update error %s: %s", filename, rrd_get_error());
+	}
+
+	g_free(filename);
 }
 
 void



More information about the pve-devel mailing list