Пример #1
0
rrd_info_t *rrd_info(
    int argc,
    char **argv)
{
    struct optparse_long longopts[] = {
        {"daemon", 'd', OPTPARSE_REQUIRED},
        {"noflush", 'F', OPTPARSE_NONE},
        {0},
    };
    struct    optparse options;
    int       opt;
    rrd_info_t *info;
    char *opt_daemon = NULL;
    int status;
    int flushfirst = 1;

    optparse_init(&options, argc, argv);
    while ((opt = optparse_long(&options, longopts, NULL)) != -1) {
        switch (opt) {
        case 'd':
            if (opt_daemon != NULL)
                free (opt_daemon);
            opt_daemon = strdup(options.optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return NULL;
            }
            break;

        case 'F':
            flushfirst = 0;
            break;

        case '?':
            rrd_set_error("%s", options.errmsg);
            return NULL;
        }
    } /* while (opt != -1) */

    if (options.argc - options.optind != 1) {
        rrd_set_error ("Usage: rrdtool %s [--daemon |-d <addr> [--noflush|-F]] <file>",
                options.argv[0]);
        return NULL;
    }

    if (flushfirst) {
        status = rrdc_flush_if_daemon(opt_daemon, options.argv[options.optind]);
        if (status) return (NULL);
    }

    rrdc_connect (opt_daemon);
    if (rrdc_is_connected (opt_daemon))
        info = rrdc_info(options.argv[options.optind]);
    else
        info = rrd_info_r(options.argv[options.optind]);

    if (opt_daemon) free(opt_daemon);
    return (info);
} /* rrd_info_t *rrd_info */
Пример #2
0
time_t rrd_last(
    int argc,
    char **argv)
{
    char *opt_daemon = NULL;
    int status;

    optind = 0;
    opterr = 0;         /* initialize getopt */

    while (42) {
        int       opt;
        int       option_index = 0;
        static struct option long_options[] = {
            {"daemon", required_argument, 0, 'd'},
            {0, 0, 0, 0}
        };

        opt = getopt_long(argc, argv, "d:", long_options, &option_index);

        if (opt == EOF)
            break;

        switch (opt) {
        case 'd':
            if (opt_daemon != NULL)
                    free (opt_daemon);
            opt_daemon = strdup (optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return (-1);
            }
            break;

        default:
            rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
                    argv[0]);
            return (-1);
            break;
        }
    }                   /* while (42) */

    if ((argc - optind) != 1) {
        rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
                argv[0]);
        return (-1);
    }

    status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
    if (opt_daemon) free(opt_daemon);
    if (status) return (-1);

    return (rrd_last_r (argv[optind]));
}
Пример #3
0
int rrd_dump(
    int argc,
    char **argv)
{
    int       opt;
    struct optparse_long longopts[] = {
        {"daemon",    'd', OPTPARSE_REQUIRED},
        {"header",    'h', OPTPARSE_REQUIRED},
        {"no-header", 'n', OPTPARSE_NONE},
        {0},
    };
    struct optparse options;
    int       rc;
    /** 
     * 0 = no header
     * 1 = dtd header
     * 2 = xsd header
     */
    int       opt_header = 1;
    char     *opt_daemon = NULL;

    /* init rrd clean */

    optparse_init(&options, argc, argv);
    while ((opt = optparse_long(&options, longopts, NULL)) != -1) {
        switch (opt) {
        case 'd':
            if (opt_daemon != NULL)
                    free (opt_daemon);
            opt_daemon = strdup(options.optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return (-1);
            }
            break;

        case 'n':
           opt_header = 0;
           break;

        case 'h':
	   if (strcmp(options.optarg, "dtd") == 0) {
	   	opt_header = 1;
	   } else if (strcmp(options.optarg, "xsd") == 0) {
	   	opt_header = 2;
	   } else if (strcmp(options.optarg, "none") == 0) {
	   	opt_header = 0;
	   }
	   break;

        default:
            rrd_set_error("usage rrdtool %s [--header|-h {none,xsd,dtd}]\n"
                          "[--no-header|-n]\n"
                          "[--daemon|-d address]\n"
                          "file.rrd [file.xml]", options.argv[0]);
            return (-1);
            break;
        }
    } /* while (opt != -1) */

    if ((options.argc - options.optind) < 1 || (options.argc - options.optind) > 2) {
        rrd_set_error("usage rrdtool %s [--header|-h {none,xsd,dtd}]\n"
                      "[--no-header|-n]\n"
                      "[--daemon|-d address]\n"
                       "file.rrd [file.xml]", options.argv[0]);
        return (-1);
    }

    rc = rrdc_flush_if_daemon(opt_daemon, options.argv[options.optind]);
    if (opt_daemon) free(opt_daemon);
    if (rc) return (rc);

    if ((options.argc - options.optind) == 2) {
        rc = rrd_dump_opt_r(options.argv[options.optind], options.argv[options.optind + 1], opt_header);
    } else {
        rc = rrd_dump_opt_r(options.argv[options.optind], NULL, opt_header);
    }

    return rc;
}
Пример #4
0
int rrd_dump(
    int argc,
    char **argv)
{
    int       rc;
    /** 
     * 0 = no header
     * 1 = dtd header
     * 2 = xsd header
     */
    int       opt_header = 1;
    char     *opt_daemon = NULL;

    /* init rrd clean */

    optind = 0;
    opterr = 0;         /* initialize getopt */

    while (42) {/* ha ha */
        int       opt;
        int       option_index = 0;
        static struct option long_options[] = {
            {"daemon", required_argument, 0, 'd'},
            {"header", required_argument, 0, 'h'},
            {"no-header", no_argument, 0, 'n'},
            {0, 0, 0, 0}
        };

        opt = getopt_long(argc, argv, "d:h:n", long_options, &option_index);

        if (opt == EOF)
            break;

        switch (opt) {
        case 'd':
            if (opt_daemon != NULL)
                    free (opt_daemon);
            opt_daemon = strdup (optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return (-1);
            }
            break;

        case 'n':
           opt_header = 0;
           break;

        case 'h':
	   if (strcmp(optarg, "dtd") == 0) {
	   	opt_header = 1;
	   } else if (strcmp(optarg, "xsd") == 0) {
	   	opt_header = 2;
	   } else if (strcmp(optarg, "none") == 0) {
	   	opt_header = 0;
	   }
	   break;

        default:
            rrd_set_error("usage rrdtool %s [--header|-h {none,xsd,dtd}] [--no-header]"
                          "file.rrd [file.xml]", argv[0]);
            return (-1);
            break;
        }
    }                   /* while (42) */

    if ((argc - optind) < 1 || (argc - optind) > 2) {
        rrd_set_error("usage rrdtool %s [--header|-h {none,xsd,dtd}] [--no-header]"
                      "file.rrd [file.xml]", argv[0]);
        return (-1);
    }

    rc = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
    if (opt_daemon) free(opt_daemon);
    if (rc) return (rc);

    if ((argc - optind) == 2) {
        rc = rrd_dump_opt_r(argv[optind], argv[optind + 1], opt_header);
    } else {
        rc = rrd_dump_opt_r(argv[optind], NULL, opt_header);
    }

    return rc;
}
int rrd_lastupdate (int argc, char **argv)
{
    time_t    last_update;
    char    **ds_names;
    char    **last_ds;
    unsigned long ds_count, i;
    int status;

    char *opt_daemon = NULL;

    optind = 0;
    opterr = 0;         /* initialize getopt */

    while (42) {
        int       opt;
        int       option_index = 0;
        static struct option long_options[] = {
            {"daemon", required_argument, 0, 'd'},
            {0, 0, 0, 0}
        };

        opt = getopt_long (argc, argv, "d:", long_options, &option_index);

        if (opt == EOF)
            break;

        switch (opt) {
        case 'd':
            if (opt_daemon != NULL)
                    free (opt_daemon);
            opt_daemon = strdup (optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return (-1);
            }
            break;

        default:
            rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
                    argv[0]);
            return (-1);
            break;
        }
    }                   /* while (42) */

    if ((argc - optind) != 1) {
        rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
                argv[0]);
        return (-1);
    }

    status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
    if (opt_daemon) free (opt_daemon);
    if (status) return (-1);

    status = rrd_lastupdate_r (argv[optind],
            &last_update, &ds_count, &ds_names, &last_ds);
    if (status != 0)
        return (status);

    for (i = 0; i < ds_count; i++)
        printf(" %s", ds_names[i]);
    printf ("\n\n");

    printf ("%10lu:", last_update);
    for (i = 0; i < ds_count; i++) {
        printf(" %s", last_ds[i]);
        free(last_ds[i]);
        free(ds_names[i]);
    }
    printf("\n");

    free(last_ds);
    free(ds_names);

    return (0);
} /* int rrd_lastupdate */
Пример #6
0
int rrd_fetch(
    int argc,
    char **argv,
    time_t *start,
    time_t *end,        /* which time frame do you want ?
                         * will be changed to represent reality */
    unsigned long *step,    /* which stepsize do you want? 
                             * will be changed to represent reality */
    unsigned long *ds_cnt,  /* number of data sources in file */
    char ***ds_namv,    /* names of data sources */
    rrd_value_t **data)
{                       /* two dimensional array containing the data */
    long      step_tmp = 1;
    time_t    start_tmp = 0, end_tmp = 0;
    const char *cf;
    char *opt_daemon = NULL;
    int status;

    rrd_time_value_t start_tv, end_tv;
    char     *parsetime_error = NULL;
    struct option long_options[] = {
        {"resolution", required_argument, 0, 'r'},
        {"start", required_argument, 0, 's'},
        {"end", required_argument, 0, 'e'},
        {"daemon", required_argument, 0, 'd'},
        {0, 0, 0, 0}
    };

    optind = 0;
    opterr = 0;         /* initialize getopt */

    /* init start and end time */
    rrd_parsetime("end-24h", &start_tv);
    rrd_parsetime("now", &end_tv);

    while (1) {
        int       option_index = 0;
        int       opt;

        opt = getopt_long(argc, argv, "r:s:e:d:", long_options, &option_index);

        if (opt == EOF)
            break;

        switch (opt) {
        case 's':
            if ((parsetime_error = rrd_parsetime(optarg, &start_tv))) {
                rrd_set_error("start time: %s", parsetime_error);
                return -1;
            }
            break;
        case 'e':
            if ((parsetime_error = rrd_parsetime(optarg, &end_tv))) {
                rrd_set_error("end time: %s", parsetime_error);
                return -1;
            }
            break;
        case 'r':
            step_tmp = atol(optarg);
            break;

        case 'd':
            if (opt_daemon != NULL)
                    free (opt_daemon);
            opt_daemon = strdup (optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return (-1);
            }
            break;

        case '?':
            rrd_set_error("unknown option '-%c'", optopt);
            return (-1);
        }
    }


    if (rrd_proc_start_end(&start_tv, &end_tv, &start_tmp, &end_tmp) == -1) {
        return -1;
    }


    if (start_tmp < 3600 * 24 * 365 * 10) {
        rrd_set_error("the first entry to fetch should be after 1980");
        return (-1);
    }

    if (end_tmp < start_tmp) {
        rrd_set_error("start (%ld) should be less than end (%ld)", start_tmp,
                      end_tmp);
        return (-1);
    }

    *start = start_tmp;
    *end = end_tmp;

    if (step_tmp < 1) {
        rrd_set_error("step must be >= 1 second");
        return -1;
    }
    *step = step_tmp;

    if (optind + 1 >= argc) {
        rrd_set_error("Usage: rrdtool %s <file> <CF> [options]", argv[0]);
        return -1;
    }

    status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
    if (opt_daemon) free (opt_daemon);
    if (status) return (-1);

    cf = argv[optind + 1];

    status = rrd_fetch_r(argv[optind], cf, start, end, step,
            ds_cnt, ds_namv, data);
    if (status != 0)
        return (-1);
    return (0);
}
Пример #7
0
rrd_info_t *rrd_info(
    int argc,
    char **argv)
{
    rrd_info_t *info;
    char *opt_daemon = NULL;
    int status;
    int flushfirst = 1;

    optind = 0;
    opterr = 0;         /* initialize getopt */

    while (42) {
        int       opt;
        int       option_index = 0;
        static struct option long_options[] = {
            {"daemon", required_argument, 0, 'd'},
            {"noflush", no_argument, 0, 'F'},
            {0, 0, 0, 0}
        };

        opt = getopt_long(argc, argv, "d:F", long_options, &option_index);

        if (opt == EOF)
            break;

        switch (opt) {
        case 'd':
            if (opt_daemon != NULL)
                    free (opt_daemon);
            opt_daemon = strdup (optarg);
            if (opt_daemon == NULL)
            {
                rrd_set_error ("strdup failed.");
                return (NULL);
            }
            break;

        case 'F':
            flushfirst = 0;
            break;

        default:
            rrd_set_error ("Usage: rrdtool %s [--daemon <addr> [--noflush]] <file>",
                    argv[0]);
            return (NULL);
            break;
        }
    }                   /* while (42) */

    if ((argc - optind) != 1) {
        rrd_set_error ("Usage: rrdtool %s [--daemon <addr> [--noflush]] <file>",
                argv[0]);
        return (NULL);
    }

    if( flushfirst ) {
    status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
    if (status) return (NULL);
    }

    rrdc_connect (opt_daemon);
    if (rrdc_is_connected (opt_daemon))
        info = rrdc_info (argv[optind]);
    else
    info = rrd_info_r(argv[optind]);

    if (opt_daemon) free(opt_daemon);
    return (info);
} /* rrd_info_t *rrd_info */