diff --git a/program/src/rrd_tool.c b/program/src/rrd_tool.c
index d1be8be8951fbce855d7ad123e35a19acf0ba589..2cad365e32374d034cc8a224b5ff47eb02002e80 100644 (file)
--- a/program/src/rrd_tool.c
+++ b/program/src/rrd_tool.c
/*****************************************************************************
/*****************************************************************************
- * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2001
+ * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002
*****************************************************************************
* rrd_tool.c Startup wrapper
*****************************************************************************/
#include "rrd_tool.h"
*****************************************************************************
* rrd_tool.c Startup wrapper
*****************************************************************************/
#include "rrd_tool.h"
+#include "rrd_xport.h"
void PrintUsage(char *cmd);
int CountArgs(char *aLine);
int CreateArgs(char *, char *, int, char **);
int HandleInputLine(int, char **, FILE*);
void PrintUsage(char *cmd);
int CountArgs(char *aLine);
int CreateArgs(char *, char *, int, char **);
int HandleInputLine(int, char **, FILE*);
+int RemoteMode=0;
+int ChangeRoot=0;
#define TRUE 1
#define FALSE 0
#define MAX_LENGTH 10000
#define TRUE 1
#define FALSE 0
#define MAX_LENGTH 10000
{
char help_main[] =
{
char help_main[] =
- "RRDtool 1.0.33 Copyright 1997-2001 by Tobias Oetiker <tobi@oetiker.ch>\n\n"
+ "RRDtool 1.1.x Copyright 1997-2003 by Tobias Oetiker <tobi@oetiker.ch>\n"
+#ifndef WIN32
+ " Compiled " MAKE_TIMESTAMP "\n\n"
+#else
+ " Compiled " __DATE__ " " __TIME__ "\n\n"
+#endif
"Usage: rrdtool [options] command command_options\n\n";
char help_list[] =
"Usage: rrdtool [options] command command_options\n\n";
char help_list[] =
- "Valid commands: create, update, graph, dump, restore,\n"
- "\t\tlast, info, fetch, tune, resize\n\n";
+ "Valid commands: create, update, updatev, graph, dump, restore,\n"
+ "\t\tlast, info, fetch, tune, resize, xport\n\n";
+
+ char help_listremote[] =
+ "Valid remote commands: quit, ls, cd, mkdir\n\n";
+
char help_create[] =
"* create - create a new RRD\n\n"
char help_create[] =
"* create - create a new RRD\n\n"
char help_restore[] =
"* restore - restore an RRD file from its XML form\n\n"
char help_restore[] =
"* restore - restore an RRD file from its XML form\n\n"
- "\trrdtool restore [--range-check|-r] filename.xml filename.rrd\n\n";
+ "\trrdtool restore [--range-check|-r] [--force-overwrite|-f] filename.xml filename.rrd\n\n";
char help_last[] =
"* last - show last update time for RRD\n\n"
char help_last[] =
"* last - show last update time for RRD\n\n"
"\t\ttime|N:value[:value...]\n\n"
"\t\tat-time@value[:value...]\n\n"
"\t\t[ time:value[:value...] ..]\n\n";
"\t\ttime|N:value[:value...]\n\n"
"\t\tat-time@value[:value...]\n\n"
"\t\t[ time:value[:value...] ..]\n\n";
+
+ char help_updatev[] =
+ "* updatev - a verbose verion of update\n"
+ "\treturns information about values, RRAs, and datasources updated\n\n"
+ "\trrdtool updatev filename\n"
+ "\t\t--template|-t ds-name:ds-name:...\n"
+ "\t\ttime|N:value[:value...]\n\n"
+ "\t\tat-time@value[:value...]\n\n"
+ "\t\t[ time:value[:value...] ..]\n\n";
char help_fetch[] =
"* fetch - fetch data out of an RRD\n\n"
char help_fetch[] =
"* fetch - fetch data out of an RRD\n\n"
"\t\t[-u|--upper-limit value] [-z|--lazy]\n"
"\t\t[-l|--lower-limit value] [-r|--rigid]\n"
"\t\t[-g|--no-legend]\n"
"\t\t[-u|--upper-limit value] [-z|--lazy]\n"
"\t\t[-l|--lower-limit value] [-r|--rigid]\n"
"\t\t[-g|--no-legend]\n"
+ "\t\t[-j|--only-graph]\n"
+ "\t\t[--font FONTTAG:size:font]\n"
+ "\t\t[--zoom factor]\n"
"\t\t[--alt-autoscale]\n"
"\t\t[--alt-autoscale-max]\n"
"\t\t[--units-exponent value]\n"
"\t\t[--step seconds]\n"
"\t\t[-f|--imginfo printfstr]\n"
"\t\t[--alt-autoscale]\n"
"\t\t[--alt-autoscale-max]\n"
"\t\t[--units-exponent value]\n"
"\t\t[--step seconds]\n"
"\t\t[-f|--imginfo printfstr]\n"
- "\t\t[-a|--imgformat GIF|PNG]\n"
- "\t\t[-c|--color COLORTAG#rrggbb] [-t|--title string]\n"
+ "\t\t[-a|--imgformat PNG]\n"
+ "\t\t[-c|--color COLORTAG#rrggbb[aa]] [-t|--title string]\n"
"\t\t[DEF:vname=rrd:ds-name:CF]\n"
"\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[PRINT:vname:CF:format]\n"
"\t\t[GPRINT:vname:CF:format]\n"
"\t\t[DEF:vname=rrd:ds-name:CF]\n"
"\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[PRINT:vname:CF:format]\n"
"\t\t[GPRINT:vname:CF:format]\n"
- "\t\t[HRULE:value#rrggbb[:legend]]\n"
- "\t\t[VRULE:value#rrggbb[:legend]]\n"
- "\t\t[LINE{1|2|3}:vname[#rrggbb[:legend]]]\n"
- "\t\t[AREA:vname[#rrggbb[:legend]]]\n"
- "\t\t[STACK:vname[#rrggbb[:legend]]]\n\n";
+ "\t\t[HRULE:value#rrggbb[aa][:legend]]\n"
+ "\t\t[VRULE:value#rrggbb[aa][:legend]]\n"
+ "\t\t[LINE{1|2|3}:vname[#rrggbb[aa][:legend]]]\n"
+ "\t\t[AREA:vname[#rrggbb[aa][:legend]]]\n"
+ "\t\t[STACK:vname[#rrggbb[aa][:legend]]]\n\n";
char help_tune[] =
" * tune - Modify some basic properties of an RRD\n\n"
char help_tune[] =
" * tune - Modify some basic properties of an RRD\n\n"
" * resize - alter the lenght of one of the RRAs in an RRD\n\n"
"\trrdtool resize filename rranum GROW|SHRINK rows\n\n";
" * resize - alter the lenght of one of the RRAs in an RRD\n\n"
"\trrdtool resize filename rranum GROW|SHRINK rows\n\n";
+ char help_xport[] =
+ "* xport - generate XML dump from one or several RRD\n\n"
+ "\trrdtool xport [-s|--start seconds] [-e|--end seconds]\n"
+ "\t\t[-m|--maxrows rows]\n"
+ "\t\t[--step seconds]\n"
+ "\t\t[DEF:vname=rrd:ds-name:CF]\n"
+ "\t\t[CDEF:vname=rpn-expression]\n"
+ "\t\t[XPORT:vname:legend]\n\n";
+
+ char help_quit[] =
+ " * quit - closeing a session in remote mode\n\n"
+ "\trrdtool quit\n\n";
+
+ char help_ls[] =
+ " * ls - lists all *.rrd files in current directory\n\n"
+ "\trrdtool ls\n\n";
+
+ char help_cd[] =
+ " * cd - changes the current directory\n\n"
+ "\trrdtool cd new direcotry\n\n";
+
+ char help_mkdir[] =
+ " * mkdir - creates a new direcotry\n\n"
+ "\trrdtool mkdir newdirecotryname\n\n";
+
char help_lic[] =
"RRDtool is distributed under the Terms of the GNU General\n"
"Public License Version 2. (www.gnu.org/copyleft/gpl.html)\n\n"
char help_lic[] =
"RRDtool is distributed under the Terms of the GNU General\n"
"Public License Version 2. (www.gnu.org/copyleft/gpl.html)\n\n"
"For more information read the RRD manpages\n\n";
enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST,
"For more information read the RRD manpages\n\n";
enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST,
- C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE };
+ C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT,
+ C_QUIT, C_LS, C_CD, C_MKDIR, C_UPDATEV };
int help_cmd = C_NONE;
int help_cmd = C_NONE;
help_cmd = C_LAST;
else if (!strcmp(cmd,"update"))
help_cmd = C_UPDATE;
help_cmd = C_LAST;
else if (!strcmp(cmd,"update"))
help_cmd = C_UPDATE;
+ else if (!strcmp(cmd,"updatev"))
+ help_cmd = C_UPDATEV;
else if (!strcmp(cmd,"fetch"))
help_cmd = C_FETCH;
else if (!strcmp(cmd,"graph"))
else if (!strcmp(cmd,"fetch"))
help_cmd = C_FETCH;
else if (!strcmp(cmd,"graph"))
help_cmd = C_TUNE;
else if (!strcmp(cmd,"resize"))
help_cmd = C_RESIZE;
help_cmd = C_TUNE;
else if (!strcmp(cmd,"resize"))
help_cmd = C_RESIZE;
+ else if (!strcmp(cmd,"xport"))
+ help_cmd = C_XPORT;
+ else if (!strcmp(cmd,"quit"))
+ help_cmd = C_QUIT;
+ else if (!strcmp(cmd,"ls"))
+ help_cmd = C_LS;
+ else if (!strcmp(cmd,"cd"))
+ help_cmd = C_CD;
+ else if (!strcmp(cmd,"mkdir"))
+ help_cmd = C_MKDIR;
}
fputs(help_main, stdout);
switch (help_cmd)
{
case C_NONE:
fputs(help_list, stdout);
}
fputs(help_main, stdout);
switch (help_cmd)
{
case C_NONE:
fputs(help_list, stdout);
+ if (RemoteMode){
+ fputs(help_listremote, stdout);
+ }
break;
case C_CREATE:
fputs(help_create, stdout);
break;
case C_CREATE:
fputs(help_create, stdout);
case C_UPDATE:
fputs(help_update, stdout);
break;
case C_UPDATE:
fputs(help_update, stdout);
break;
+ case C_UPDATEV:
+ fputs(help_updatev, stdout);
+ break;
case C_FETCH:
fputs(help_fetch, stdout);
break;
case C_FETCH:
fputs(help_fetch, stdout);
break;
case C_RESIZE:
fputs(help_resize, stdout);
break;
case C_RESIZE:
fputs(help_resize, stdout);
break;
+ case C_XPORT:
+ fputs(help_xport, stdout);
+ break;
+ case C_QUIT:
+ fputs(help_quit, stdout);
+ break;
+ case C_LS:
+ fputs(help_ls, stdout);
+ break;
+ case C_CD:
+ fputs(help_cd, stdout);
+ break;
+ case C_MKDIR:
+ fputs(help_mkdir, stdout);
+ break;
}
fputs(help_lic, stdout);
}
}
fputs(help_lic, stdout);
}
{
char **myargv;
char aLine[MAX_LENGTH];
{
char **myargv;
char aLine[MAX_LENGTH];
+#ifdef HAVE_CHROOT
+ char *firstdir="";
+#endif
#ifdef MUST_DISABLE_SIGFPE
signal(SIGFPE,SIG_IGN);
#endif
#ifdef MUST_DISABLE_SIGFPE
signal(SIGFPE,SIG_IGN);
#endif
return 0;
}
return 0;
}
- if ((argc == 2) && !strcmp("-",argv[1]))
+ if (((argc == 2)||(argc == 3)) && !strcmp("-",argv[1]))
{
#if HAVE_GETRUSAGE
struct rusage myusage;
{
#if HAVE_GETRUSAGE
struct rusage myusage;
tz.tz_dsttime=0;
gettimeofday(&starttime,&tz);
#endif
tz.tz_dsttime=0;
gettimeofday(&starttime,&tz);
#endif
+ RemoteMode=1;
+#ifdef HAVE_CHROOT
+ if ((argc == 3) && strcmp("",argv[2])){
+ if (getuid()==0){
+ chroot(argv[2]);
+ if (errno!=0){
+ fprintf(stderr,"ERROR: can't change root to '%s' errno=%d\n",
+ argv[2],errno);
+ exit(errno);
+ }
+ ChangeRoot=1;
+ firstdir="/";
+ }
+ else{
+ firstdir=argv[2];
+ }
+ }
+ if (strcmp(firstdir,"")){
+ chdir(firstdir);
+ if (errno!=0){
+ fprintf(stderr,"ERROR: %s\n",strerror(errno));
+ exit(errno);
+ }
+ }
+#else
+ fprintf(stderr,"ERROR: change root is not supported by your OS "
+ "or at least by this copy of rrdtool\n");
+ exit(1);
+#endif
while (fgets(aLine, sizeof(aLine)-1, stdin)){
if ((argc = CountArgs(aLine)) == 0) {
while (fgets(aLine, sizeof(aLine)-1, stdin)){
if ((argc = CountArgs(aLine)) == 0) {
PrintUsage(argv[1]);
exit(0);
}
PrintUsage(argv[1]);
exit(0);
}
+ else if (argc == 3 && !strcmp(argv[1],"help"))
+ {
+ PrintUsage(argv[2]);
+ exit(0);
+ }
else
HandleInputLine(argc, argv, stderr);
return 0;
}
else
HandleInputLine(argc, argv, stderr);
return 0;
}
+/* HandleInputLine is NOT thread safe - due to readdir issues,
+ resolving them portably is not really simple. */
int HandleInputLine(int argc, char **argv, FILE* out)
{
int HandleInputLine(int argc, char **argv, FILE* out)
{
+#if defined(HAVE_OPENDIR) && defined (HAVE_READDIR)
+ DIR *curdir; /* to read current dir with ls */
+ struct dirent *dent;
+#endif
+#if defined(HAVE_SYS_STAT_H)
+ struct stat st;
+#endif
optind=0; /* reset gnu getopt */
opterr=0; /* no error messages */
optind=0; /* reset gnu getopt */
opterr=0; /* no error messages */
+ if (RemoteMode){
+ if (argc>1 && strcmp("quit", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for quit\n");
+ return(0);
+ }
+ exit(0);
+ }
+#if defined(HAVE_OPENDIR) && defined(HAVE_READDIR) && defined(HAVE_CHDIR)
+ if (argc>1 && strcmp("cd", argv[1]) == 0){
+ if (argc>3){
+ printf("ERROR: invalid parameter count for cd\n");
+ return(0);
+ }
+#if ! defined(HAVE_CHROOT) || ! defined(HAVE_GETUID)
+ if (getuid()==0 && ! ChangeRoot){
+ printf("ERROR: chdir security problem - rrdtool is runnig as "
+ "root an no chroot!\n");
+ return(0);
+ }
+#endif
+ chdir(argv[2]);
+ if (errno!=0){
+ printf("ERROR: %s\n",strerror(errno));
+ }
+ return(0);
+ }
+ if (argc>1 && strcmp("mkdir", argv[1]) == 0){
+ if (argc>3){
+ printf("ERROR: invalid parameter count for mkdir\n");
+ return(0);
+ }
+#if ! defined(HAVE_CHROOT) || ! defined(HAVE_GETUID)
+ if (getuid()==0 && ! ChangeRoot){
+ printf("ERROR: mkdir security problem - rrdtool is runnig as "
+ "root an no chroot!\n");
+ return(0);
+ }
+#endif
+ mkdir(argv[2],0777);
+ if (errno!=0){
+ printf("ERROR: %s\n",strerror(errno));
+ }
+ return(0);
+ }
+ if (argc>1 && strcmp("ls", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for ls\n");
+ return(0);
+ }
+ if ((curdir=opendir("."))!=NULL){
+ while((dent=readdir(curdir))!=NULL){
+ if (!stat(dent->d_name,&st)){
+ if (S_ISDIR(st.st_mode)){
+ printf("d %s\n",dent->d_name);
+ }
+ if (strlen(dent->d_name)>4 && S_ISREG(st.st_mode)){
+ if (!strcmp(dent->d_name+NAMLEN(dent)-4,".rrd") ||
+ !strcmp(dent->d_name+NAMLEN(dent)-4,".RRD")){
+ printf("- %s\n",dent->d_name);
+ }
+ }
+ }
+ }
+ }
+ else{
+ printf("ERROR: %s\n",strerror(errno));
+ return(errno);
+ }
+ return(0);
+ }
+#endif /* opendir and readdir */
+
+ }
if (argc < 3
|| strcmp("help", argv[1]) == 0
|| strcmp("--help", argv[1]) == 0
if (argc < 3
|| strcmp("help", argv[1]) == 0
|| strcmp("--help", argv[1]) == 0
rrd_create(argc-1, &argv[1]);
else if (strcmp("dump", argv[1]) == 0)
rrd_dump(argc-1, &argv[1]);
rrd_create(argc-1, &argv[1]);
else if (strcmp("dump", argv[1]) == 0)
rrd_dump(argc-1, &argv[1]);
- else if (strcmp("info", argv[1]) == 0){
+ else if (strcmp("info", argv[1]) == 0
+ || strcmp("updatev", argv[1]) == 0){
info_t *data,*save;
info_t *data,*save;
- data=rrd_info(argc-1, &argv[1]);
+ if (strcmp("info",argv[1]) == 0)
+ data=rrd_info(argc-1, &argv[1]);
+ else
+ data=rrd_update_v(argc-1, &argv[1]);
while (data) {
save=data;
printf ("%s = ", data->key);
while (data) {
save=data;
printf ("%s = ", data->key);
case RD_I_CNT:
printf ("%lu", data->value.u_cnt);
break;
case RD_I_CNT:
printf ("%lu", data->value.u_cnt);
break;
+ case RD_I_INT:
+ printf ("%d", data->value.u_int);
+ break;
case RD_I_STR:
printf ("\"%s\"", data->value.u_str);
free(data->value.u_str);
case RD_I_STR:
printf ("\"%s\"", data->value.u_str);
free(data->value.u_str);
strcmp("v", argv[1]) == 0 ||
strcmp("-v", argv[1]) == 0 ||
strcmp("-version", argv[1]) == 0 )
strcmp("v", argv[1]) == 0 ||
strcmp("-v", argv[1]) == 0 ||
strcmp("-version", argv[1]) == 0 )
- printf("RRDtool 1.0.33 Copyright (C) 1997-2001 by Tobias Oetiker <tobi@oetiker.ch>\n");
+ printf("RRDtool 1.1.x Copyright (C) 1997-2003 by Tobias Oetiker <tobi@oetiker.ch>\n");
else if (strcmp("restore", argv[1]) == 0)
rrd_restore(argc-1, &argv[1]);
else if (strcmp("resize", argv[1]) == 0)
else if (strcmp("restore", argv[1]) == 0)
rrd_restore(argc-1, &argv[1]);
else if (strcmp("resize", argv[1]) == 0)
else if (strcmp("update", argv[1]) == 0)
rrd_update(argc-1, &argv[1]);
else if (strcmp("fetch", argv[1]) == 0) {
else if (strcmp("update", argv[1]) == 0)
rrd_update(argc-1, &argv[1]);
else if (strcmp("fetch", argv[1]) == 0) {
- time_t start,end;
+ time_t start,end, ti;
unsigned long step, ds_cnt,i,ii;
rrd_value_t *data,*datai;
char **ds_namv;
unsigned long step, ds_cnt,i,ii;
rrd_value_t *data,*datai;
char **ds_namv;
datai=data;
printf(" ");
for (i = 0; i<ds_cnt;i++)
datai=data;
printf(" ");
for (i = 0; i<ds_cnt;i++)
- printf("%14s",ds_namv[i]);
+ printf("%20s",ds_namv[i]);
printf ("\n\n");
printf ("\n\n");
- for (i = start+step; i <= end; i += step){
- printf("%10lu:", i);
+ for (ti = start+step; ti <= end; ti += step){
+ printf("%10lu:", ti);
for (ii = 0; ii < ds_cnt; ii++)
printf(" %0.10e", *(datai++));
printf("\n");
for (ii = 0; ii < ds_cnt; ii++)
printf(" %0.10e", *(datai++));
printf("\n");
free(ds_namv);
free (data);
}
free(ds_namv);
free (data);
}
+ } else if (strcmp("xport", argv[1]) == 0) {
+ int xxsize;
+ unsigned long int j = 0;
+ time_t start,end, ti;
+ unsigned long step, col_cnt,row_cnt;
+ rrd_value_t *data,*ptr;
+ char **legend_v;
+ if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
+ row_cnt = (end-start)/step;
+ ptr = data;
+ printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n", XML_ENCODING);
+ printf("<%s>\n", ROOT_TAG);
+ printf(" <%s>\n", META_TAG);
+ printf(" <%s>%lu</%s>\n", META_START_TAG, start+step, META_START_TAG);
+ printf(" <%s>%lu</%s>\n", META_STEP_TAG, step, META_STEP_TAG);
+ printf(" <%s>%lu</%s>\n", META_END_TAG, end, META_END_TAG);
+ printf(" <%s>%lu</%s>\n", META_ROWS_TAG, row_cnt, META_ROWS_TAG);
+ printf(" <%s>%lu</%s>\n", META_COLS_TAG, col_cnt, META_COLS_TAG);
+ printf(" <%s>\n", LEGEND_TAG);
+ for (j = 0; j < col_cnt; j++) {
+ char *entry = NULL;
+ entry = legend_v[j];
+ printf(" <%s>%s</%s>\n", LEGEND_ENTRY_TAG, entry, LEGEND_ENTRY_TAG);
+ free(entry);
+ }
+ free(legend_v);
+ printf(" </%s>\n", LEGEND_TAG);
+ printf(" </%s>\n", META_TAG);
+ printf(" <%s>\n", DATA_TAG);
+ for (ti = start+step; ti <= end; ti += step) {
+ printf (" <%s>", DATA_ROW_TAG);
+ printf ("<%s>%lu</%s>", COL_TIME_TAG, ti, COL_TIME_TAG);
+ for (j = 0; j < col_cnt; j++) {
+ rrd_value_t newval = DNAN;
+ newval = *ptr;
+ if(isnan(newval)){
+ printf("<%s>NaN</%s>", COL_DATA_TAG, COL_DATA_TAG);
+ } else {
+ printf("<%s>%0.10e</%s>", COL_DATA_TAG, newval, COL_DATA_TAG);
+ };
+ ptr++;
+ }
+ printf("</%s>\n", DATA_ROW_TAG);
+ }
+ free(data);
+ printf(" </%s>\n", DATA_TAG);
+ printf("</%s>\n", ROOT_TAG);
+ }
}
else if (strcmp("graph", argv[1]) == 0) {
char **calcpr;
}
else if (strcmp("graph", argv[1]) == 0) {
char **calcpr;
+ const char *imgfile = argv[2]; /* rrd_graph changes argv pointer */
int xsize, ysize;
int i;
int xsize, ysize;
int i;
- if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize) != -1 ) {
- if (strcmp(argv[2],"-") != 0)
+ int tostdout = (strcmp(argv[2],"-") == 0);
+ if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize, NULL) != -1 ) {
+ if (!tostdout)
printf ("%dx%d\n",xsize,ysize);
if (calcpr) {
for(i=0;calcpr[i];i++){
printf ("%dx%d\n",xsize,ysize);
if (calcpr) {
for(i=0;calcpr[i];i++){
- if (strcmp(argv[2],"-") != 0)
+ if (!tostdout)
printf("%s\n",calcpr[i]);
free(calcpr[i]);
}
printf("%s\n",calcpr[i]);
free(calcpr[i]);
}