Пример #1
0
/* A summary RRD has a "num" and a "sum" DS (datasource) whereas the
   host rrds only have "sum" (since num is always 1) */
static int
push_data_to_rrd( char *rrd, const char *sum, const char *num,
                  unsigned int step, unsigned int process_time,
                  ganglia_slope_t slope)
{
    int rval;
    int summary;
    struct stat st;

    /*  if process_time is undefined, we set it to the current time */
    if (!process_time)
        process_time = time(0);

    if (num)
        summary=1;
    else
        summary=0;

    if( stat(rrd, &st) )
    {
        rval = RRD_create( rrd, summary, step, process_time, slope);
        if( rval )
            return rval;
    }
    return RRD_update( rrd, sum, num, process_time );
}
Пример #2
0
static int
append_record_rrd(const char *dbpath, struct record_data *rec)
{
	time_t epoch;
	struct tm *time_utc;

	epoch = mktime(&(rec->date));
	if (epoch == -1) {
		fprintf(stderr, "ERROR: mktime detected an error.\n");
		return -1;
	}

	/* Convert to UTC (That's what RRD eats, it will convert to local
	 * timezone using tz env variable) */
	time_utc = gmtime(&epoch);
	epoch = mktime(time_utc);
	if (epoch == -1) {
		fprintf(stderr, "ERROR: mktime detected an error.\n");
		return -1;
	}

	/* We don't really care if it fails, we'll try again and that's it */
	RRD_update(dbpath, rec->watts, epoch);
	return 0;
}
Пример #3
0
/** 
* @brief   写数据到RRD数据库中
* @param   host    host名字
* @param   metric  metric的名字
* @param   value   数值
* @param   num     个数
* @param   step    抽取间隔
* @return  成功返回0,失败返回-1
*/
int c_rrd_handler::write_data_to_rrd(
        const char *host,
        const char *metric,
        const char *value, 
        const char *num,
        unsigned int step)
{
    if (!m_inited)
    {
        ERROR_LOG("c_rrd_handler has not been inited.");
        return -1;
    }

    if (NULL == host || NULL == metric || NULL == value) {
        ERROR_LOG("Parameter ERROR: host[%s], metric[%s], value[%s]",
                NULL == host ? "NULL" : host,
                NULL == metric ? "NULL" : metric,
                NULL == value ? "NULL" : value);
        return -1;
    }

    char rrd_file_path[PATH_MAX] = {'\0'};
    int len = 0;
    int remain_len = PATH_MAX - 1;
    char *write_pos = rrd_file_path;

    //先把根目录拷进来
    len = snprintf(write_pos, remain_len, "%s", m_rrd_base_dir);
    write_pos += len;
    remain_len -= len;
    // char * relative_name = write_pos - 1;

    //len = snprintf(write_pos, remain_len, "/clusters-data");
    //write_pos += len;
    //remain_len -= len;
    //rrd_mkdir(rrd_file_path);

    len = snprintf(write_pos, remain_len, "/%s", host);
    write_pos += len;
    remain_len -= len;
    rrd_mkdir(rrd_file_path);

    snprintf(write_pos, remain_len, "/%s.rrd", metric);

    if(0 != access(rrd_file_path, F_OK))
    {
        bool summary = (num != NULL) ? true : false;
        if(0 != RRD_create(rrd_file_path, summary, step))
        {
            return -1;
        }
    }

    // *relative_name = '.';

    // return RRD_update(relative_name, value, num);
    return RRD_update(rrd_file_path, value, num);
}
Пример #4
0
/* A summary RRD has a "num" and a "sum" DS (datasource) whereas the
   host rrds only have "sum" (since num is always 1) */
static int
push_data_to_rrd( char *rrd, const char *sum, const char *num,
                  unsigned int step, unsigned int process_time,
                  ganglia_slope_t slope)
{
   int rval;
   int summary;
   struct stat st;

   /*  if process_time is undefined, we set it to the current time */
   if (!process_time)
      process_time = time(0);

   if (num)
      summary=1;
   else
      summary=0;

   /* XXX: cache the results of the stat once hash table is fixed. */
   if( stat(rrd, &st) )
      {
         rval = RRD_create( rrd, summary, step, process_time, slope);
         if( rval )
            return rval;
      }
   if (gmetad_config.rrdcached_addrstr != NULL)
      {
         ganglia_scoreboard_inc(METS_SENT_RRDCACHED);
         ganglia_scoreboard_inc(METS_SENT_ALL);
         last_rrdcached = apr_time_now();  //Updating global variable
         return RRD_update_cached( rrd, sum, num, process_time );
      }
   else
      {
         ganglia_scoreboard_inc(METS_SENT_RRDTOOL);
         ganglia_scoreboard_inc(METS_SENT_ALL);
         last_rrdtool = apr_time_now();  //Updating global variable
         return RRD_update( rrd, sum, num, process_time );
      }
}