示例#1
0
static int srrd_create(const char *filename, /* {{{ */
                       unsigned long pdp_step, time_t last_up, int argc,
                       const char **argv) {
  int status;
  char *filename_copy;

  if ((filename == NULL) || (argv == NULL))
    return -EINVAL;

  /* Some versions of librrd don't have the `const' qualifier for the first
   * argument, so we have to copy the pointer here to avoid warnings. It sucks,
   * but what else can we do? :(  -octo */
  filename_copy = strdup(filename);
  if (filename_copy == NULL) {
    ERROR("srrd_create: strdup failed.");
    return -ENOMEM;
  }

  optind = 0; /* bug in librrd? */
  rrd_clear_error();

  status = rrd_create_r(filename_copy, pdp_step, last_up, argc, (void *)argv);

  if (status != 0) {
    P_WARNING("srrd_create: rrd_create_r (%s) failed: %s", filename,
              rrd_get_error());
  }

  sfree(filename_copy);

  return status;
} /* }}} int srrd_create */
示例#2
0
void temperhum_rrd_create(char *fname) {
	struct stat buf;

	if (stat(fname, &buf) != 0) {
		const char *args[21] = {
			"DS:tc:GAUGE:60:U:U",
			"DS:rh:GAUGE:60:U:U",
			"DS:dp:GAUGE:60:U:U",

			"RRA:HWPREDICT:86400:0.75:0.75:86400", /* daily */
			"RRA:HWPREDICT:86400:0.75:0.75:31449600", /* yearly */

			"RRA:AVERAGE:0:1:604800",        /* avg  1s for  1w */

			"RRA:MIN:0.5:30:1051920",        /* min             */
			"RRA:AVERAGE:0.5:30:1051920",    /* avg 30s for  1y */
			"RRA:MAX:0.5:30:1051920",        /* max             */

			"RRA:MIN:0.5:600:1051920",       /* min             */
			"RRA:AVERAGE:0.5:600:1051920",   /* avg 10m for 20y */
			"RRA:MAX:0.5:600:1051920",       /* max             */

			"RRA:MIN:0.5:3600:175320",       /* min             */
			"RRA:AVERAGE:0.5:3600:175320",   /* avg  1h for 20y */
			"RRA:MAX:0.5:3600:175320",       /* max             */

			"RRA:MIN:0.5:21600:29220",       /* min             */
			"RRA:AVERAGE:0.5:21600:29220",   /* avg  6h for 20y */
			"RRA:MAX:0.5:21600:29220",       /* max             */

			"RRA:MIN:0.5:86400:7305",        /* min             */
			"RRA:AVERAGE:0.5:86400:7305",    /* avg  1h for 20y */
			"RRA:MAX:0.5:86400:7305",        /* max             */
		};
		rrd_clear_error();
		if (rrd_create_r(fname, 1, time(NULL) - 1, 21, args) != 0) {
			fprintf(stderr, "%s: %s\n", fname, rrd_get_error());
			exit(EXIT_FAILURE);
		}
	}
}
示例#3
0
int rrd_create(
    int argc,
    char **argv)
{
    struct option long_options[] = {
        {"start", required_argument, 0, 'b'},
        {"step", required_argument, 0, 's'},
        {"no-overwrite", no_argument, 0, 'O'},
        {0, 0, 0, 0}
    };
    int       option_index = 0;
    int       opt;
    time_t    last_up = time(NULL) - 10;
    unsigned long pdp_step = 300;
    rrd_time_value_t last_up_tv;
    char     *parsetime_error = NULL;
    long      long_tmp;
    int       rc;

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

    while (1) {
        opt = getopt_long(argc, argv, "Ob:s:", long_options, &option_index);

        if (opt == EOF)
            break;

        switch (opt) {
        case 'b':
            if ((parsetime_error = rrd_parsetime(optarg, &last_up_tv))) {
                rrd_set_error("start time: %s", parsetime_error);
                return (-1);
            }
            if (last_up_tv.type == RELATIVE_TO_END_TIME ||
                last_up_tv.type == RELATIVE_TO_START_TIME) {
                rrd_set_error("specifying time relative to the 'start' "
                              "or 'end' makes no sense here");
                return (-1);
            }

            last_up = mktime(&last_up_tv.tm) +last_up_tv.offset;

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

        case 's':
            long_tmp = atol(optarg);
            if (long_tmp < 1) {
                rrd_set_error("step size should be no less than one second");
                return (-1);
            }
            pdp_step = long_tmp;
            break;

        case 'O':
            opt_no_overwrite = 1;
	    break;

        case '?':
            if (optopt != 0)
                rrd_set_error("unknown option '%c'", optopt);
            else
                rrd_set_error("unknown option '%s'", argv[optind - 1]);
            return (-1);
        }
    }
    if (optind == argc) {
        rrd_set_error("need name of an rrd file to create");
        return -1;
    }
    rc = rrd_create_r(argv[optind],
                      pdp_step, last_up,
                      argc - optind - 1, (const char **) (argv + optind + 1));

    return rc;
}
示例#4
0
char *rrdCreate(const char *filename, unsigned long step, time_t start, int argc, const char **argv) {
	rrd_clear_error();
	rrd_create_r(filename, step, start, argc, argv);
	return rrdError();
}
示例#5
0
文件: rrdfunc.c 项目: yubo/rrdlite
const char *rrdCreate(const char *filename, unsigned long step, 
		time_t start, int argc, const char **argv) {
	int ret;
	ret = rrd_create_r(filename, step, start, argc, argv);
	return rrd_strerror(ret);
}