[rrd-users] "rrdtool last-ds" and "rrdtool last-values"

steve rader rader at teak.wiscnet.net
Mon Oct 4 20:40:39 MEST 1999


The "rrdtool last" patches I posted on Sep 13th 1999 broke
RRDs.pm.  So I fixed that by adding the functionality as
two entirely new rrdtool "commands":

 bash% rrdtool last-ds fu.rrd input 3684419523 output
 input 3684419523
 output 1069641428

 bash% rrdtool last-values fu.rrd
 input 90857.20
 output 59031.76

See (mangled) MIME attachment "rrd-1.0.8-last.path" or [1].

These patches use call by reference so they can be (easly?) added
to RRDs.pm.  (Sorry: I made an attempt to wedge these into
RRDs.pm but got in way over my head.)

later
steve
- - -
systems guy
wiscnet.net

 [1] ftp://teak.wiscnet.net/pub/src/rrd-1.0.8-last.patch



-- Attached file included as plaintext by Listar --
-- Desc: rrd-1.0.8-last.patch

--- rrdtool-1.0.8.orig/src/rrd_tool.h	Fri Aug 27 14:20:05 1999
+++ rrdtool-1.0.8/src/rrd_tool.h	Mon Oct  4 08:42:30 1999
@@ -104,6 +104,10 @@
 int    rrd_tune(int argc, char **argv);
 time_t rrd_last(int argc, char **argv);
 int    rrd_resize(int argc, char **argv);
+int    rrd_last_ds(int argc, char **argv, 
+		long *ds_cnt, char ***ds_namv, char ***datav);
+int    rrd_last_values(int argc, char **argv, 
+		long *ds_cnt, char ***ds_namv, rrd_value_t **data);
 
 /* HELPER FUNCTIONS */
 void rrd_set_error(char *fmt,...);
--- rrdtool-1.0.8.orig/src/rrd_tool.c	Fri Aug 27 14:20:05 1999
+++ rrdtool-1.0.8/src/rrd_tool.c	Mon Oct  4 08:53:27 1999
@@ -3,8 +3,7 @@
  *****************************************************************************
  * rrd_tool.c  Startup wrapper
  *****************************************************************************
- * $Id: rrd_tool.c,v 1.8 1998/03/08 12:35:11 oetiker Exp oetiker $
- * $Log: rrd_tool.c,v $
+ * $Id: rrd_tool.c,v 1.6 1999/10/04 13:53:25 rader Exp $
  *****************************************************************************/
 
 #include "rrd_tool.h"
@@ -38,6 +37,12 @@
 
            "* last - show last update time for RRD\n\n"
            "\trrdtool last filename.rrd\n\n"
+           
+           "* last-ds - show the <last_ds></last_ds> values for an RRD\n\n"
+           "\trrdtool last-ds filename.rrd\n\n"
+
+           "* last-value - show the <value></value> for an RRD\n\n"
+           "\trrdtool last-value filename.rrd\n\n"
 
 	   "* update - update an RRD\n\n"
 	   "\trrdtool update filename\n"
@@ -191,6 +196,31 @@
 	rrd_resize(argc-1, &argv[1]);
     else if (strcmp("last", argv[1]) == 0)
         printf("%ld\n",rrd_last(argc-1, &argv[1]));
+    else if ( (strcmp("last-ds", argv[1]) == 0) || 
+              (strcmp("last-dss", argv[1]) == 0) ) {  
+        long ds_cnt;
+        char **ds_namv, **data_vec;
+        int i;
+        if (rrd_last_ds(argc-1, &argv[1], &ds_cnt, &ds_namv, &data_vec) != -1) {
+	  for (i = 0; i<ds_cnt;i++)
+	    printf("%s %s\n",ds_namv[i], data_vec[i]);
+          free(ds_namv);
+          free(data_vec);
+        }
+    }
+    else if ( (strcmp("last-value", argv[1]) == 0) ||
+              (strcmp("last-values", argv[1]) == 0) ) {  
+        long ds_cnt;
+        char **ds_namv;
+        rrd_value_t *data;
+        int i;
+        if (rrd_last_values(argc-1,&argv[1],&ds_cnt,&ds_namv,&data) != -1) {
+	  for (i = 0; i<ds_cnt; i++)
+	    printf("%s %.2f\n",ds_namv[i], data[i]);
+          free(ds_namv);
+          free(data);
+        }
+    }
     else if (strcmp("update", argv[1]) == 0)
 	rrd_update(argc-1, &argv[1]);
     else if (strcmp("fetch", argv[1]) == 0) {
--- rrdtool-1.0.8.orig/src/rrd_last.c	Fri Aug 27 14:20:05 1999
+++ rrdtool-1.0.8/src/rrd_last.c	Mon Oct  4 08:50:17 1999
@@ -4,6 +4,8 @@
  * rrd_last.c
  *****************************************************************************
  * Initial version by Russ Wright, @Home Network, 9/28/98
+ * rrd_last_ds() added by steve rader <rader at wiscnet.net> 9/11/99
+ * rrd_last_values() added by steve rader <rader at wiscnet.net> 10/2/99
  *****************************************************************************/
 
 #include "rrd_tool.h"
@@ -30,5 +32,63 @@
 }
  
 
+int
+rrd_last_ds(int argc, char **argv, long *ds_cnt, char ***ds_namv, char ***datav)
+{
+    FILE	 *in_file;
+    rrd_t	 rrd;
+    int          i;
+
+    if(argc < 2){
+        rrd_set_error("please specify an rrd");
+        return(-1);
+    }
+    if(rrd_open(argv[1], &in_file, &rrd, RRD_READONLY)==-1){
+        return(-1);
+    }
+    *ds_namv = (char **)malloc(rrd.stat_head->ds_cnt * sizeof(char*));
+    *datav = (char **)malloc(rrd.stat_head->ds_cnt * sizeof(char*));
+    for(i=0;i<rrd.stat_head->ds_cnt;i++){
+        (*ds_namv)[i] = malloc(DS_NAM_SIZE+1);
+        sprintf((*ds_namv)[i],"%s", rrd.ds_def[i].ds_nam);
+        (*datav)[i] = malloc(LAST_DS_LEN+1);
+        sprintf((*datav)[i],"%s", rrd.pdp_prep[i].last_ds);
+    }
+    *ds_cnt = rrd.stat_head->ds_cnt;
+    rrd_free(&rrd);
+    fclose(in_file);
+    return(1);
+}
 
+int
+rrd_last_values(
+    int          argc, 
+    char         **argv, 
+    long         *ds_cnt, 
+    char         ***ds_namv, 
+    rrd_value_t  **data)
+{
+    FILE	 *in_file;
+    rrd_t	 rrd;
+    int          i;
+
+    if(argc < 2){
+        rrd_set_error("please specify an rrd");
+        return(-1);
+    }
+    if(rrd_open(argv[1], &in_file, &rrd, RRD_READONLY)==-1){
+        return(-1);
+    }
+    *ds_namv = (char **)malloc(rrd.stat_head->ds_cnt * sizeof(char*));
+    *data = malloc(rrd.stat_head->ds_cnt * sizeof(rrd_value_t));
+    for(i=0;i<rrd.stat_head->ds_cnt;i++){
+        (*ds_namv)[i] = malloc(DS_NAM_SIZE+1);
+        sprintf((*ds_namv)[i],"%s", rrd.ds_def[i].ds_nam);
+        (*data)[i] = rrd.pdp_prep[i].scratch[PDP_val].u_val;
+    }
+    *ds_cnt = rrd.stat_head->ds_cnt;
+    rrd_free(&rrd);
+    fclose(in_file);
+    return(1);
+}
 


--
* To unsubscribe from the rrd-users mailing list, send a message with the
  subject: unsubscribe to rrd-users-request at list.ee.ethz.ch



More information about the rrd-users mailing list