[rrd-developers] Re: RRD Help

majain at hss.hns.com majain at hss.hns.com
Mon Sep 22 09:46:14 MEST 2003






I haven't gone through all of your code....
Pls check....whether rrd updates happened or not ...check it with "rrdtool
fetch ............."

while executing this code whether you got some error while updating RRD ?

subsequent updates in RRD needs at least 1 sec diff...pls check....

Regards,
Manish Jain
Hughes Software System,Gurgaon




Vamsi Mohan Harish <reacharish at yahoo.com>@list.ee.ethz.ch on 09/19/2003
05:13:30 PM

Sent by:    rrd-developers-bounce at list.ee.ethz.ch


To:    rrd-developers at list.ee.ethz.ch
cc:

Subject:    [rrd-developers] RRD Help


Hi,

I have created an RRD file (using C API) and updated it with around 4000
values. But when I am creating graphs using the RRD File, it's showing
nothing. Absolutely balnk graph. Can any one tell me where did I go wrong.
The following is the brief code.


Create RRD: -- SNIP --
-------------------------------------------
STEP : 1800 (30 Minutes)
DIFF_TIME : 2592000  /* No. of seconds in a month = 30 * 24 * 60 * 60 */
HT_BEAT: 600 (10 Minutes)
 if(!Time)
  tm = time(NULL);
 else
  tm = Time;
 strcpy(Args[0], "create");
 sprintf(Args[1],"%s",RRDName);
 strcpy(Args[2],"-b");
 sprintf(Args[3],"%ld", tm - DIFF_TIME);
 strcpy(Args[4],"-s");
 sprintf(Args[5],"%d", STEP);

 //DS : Input
 sprintf(Args[6],"DS:Input:GAUGE:%d:0:U", HT_BEAT);
 strcpy(Args[7],"RRA:AVERAGE:0.5:1:600");
 strcpy(Args[8],"RRA:AVERAGE:0.5:6:700");
 strcpy(Args[9],"RRA:AVERAGE:0.5:24:775");
 strcpy(Args[10],"RRA:AVERAGE:0.5:288:797");
 strcpy(Args[11],"RRA:MAX:0.5:6:700");
 strcpy(Args[12],"RRA:MAX:0.5:24:775");
 strcpy(Args[13],"RRA:MAX:0.5:288:797");
 //DS : Output
 sprintf(Args[14],"DS:Output:GAUGE:%d:0:U", HT_BEAT);
 strcpy(Args[15],"RRA:AVERAGE:0.5:1:600");
 strcpy(Args[16],"RRA:AVERAGE:0.5:6:700");
 strcpy(Args[17],"RRA:AVERAGE:0.5:24:775");
 strcpy(Args[18],"RRA:AVERAGE:0.5:288:797");
 strcpy(Args[19],"RRA:MAX:0.5:6:700");
 strcpy(Args[20],"RRA:MAX:0.5:24:775");
 strcpy(Args[21],"RRA:MAX:0.5:288:797");
 NoArgs=22;

 optind = 0;
 opterr = 0;
 rrd_clear_error();
 rrd_create(NoArgs, Args);
 if(rrd_test_error())
 {
  sprintf(ErrorStr, "%s", rrd_get_error());
  ErrorNo = 1002;
  return -2;
 }
 return 0;
-------------------------------------------
Update RRD - data from database  -- SNIP
fs
//Inserting dummy records in to database
        for(i = 0; i < 10; i++)
        {
                TimeStamp = time(NULL);
                sprintf(UserName,"User%d",i);
                for(j = 0, k = 1; j < 1000; j++, k++)
                {
                        srand(TimeStamp);
                        if(k == 4) k = 1;
                        sprintf(IPAddress,"202.65.%d.%d",i, k);
                        StartTime = (TimeStamp * 1000.0); //Time is in
                        MilliSeconds
                        InputBytes = 1 + (int) (512.0 * rand()/(RAND_MAX +
                        1.0));
                        OutputBytes = 1 + (int) (5120.0 * rand()/(RAND_MAX
                        + 1.0));
                        sprintf(Query, "INSERT INTO rrd_usage_records
                        values('%s', '%s', %.0f, %d, %d)",
                                                                UserName,
                        IPAddress, StartTime, InputBytes, OutputBytes);
                        Res = Execute(Query);
                        if (!Res)
                        {
                                ErrorNo = 103;
                                strcpy(ErrorStr, Error(Res));
      return -1;
                        }
                }
        }
Update_RRD : --SNIP--
-------------------------------------------
      for(i = 0; i < nRecords; i++)
        {
                StrStartTime = RS("Start_Time");
                StartTime = (unsigned long) (strtod(StrStartTime,
                NULL)/1000); //Start_Time is in Milli Seconds
                UserName = RS("User_Name");
                OutputBytes = atol(RS("Output_Bytes");
                sprintf(RRDFileName, "%s.rrd",UserName);
                LastUpdate = _RRDLastUpdate(RRDFileName);
                if(RRDErrorNo != 0) //Create RRD File, if it not existing
                {
                        if(_CreateRRD(RRDFileName, 0) < 0)
                        {
                                printf("Error : %d - %s\n", RRDErrorNo,
                                RRDErrorStr);
                                continue;       //Go to next user
                        }
                }
                printf("%s\t%ld\t%ld\n", UserName, StartTime, OutputBytes);
                /* Update the RRD File Here  */
                if(_UpdateRRD(RRDFileName, OutputBytes, StartTime) < 0)
                {
                                printf("Error : %d - %s\n", RRDErrorNo,
                                RRDErrorStr);
                                continue;
                }
        }
-------------------------------------------
 NoArgs = 3;
 strcpy(Args[0], "update");
 sprintf(Args[1],"%s",RRDName);
 sprintf(Args[2],"%ld:%ld:%ld",SDate, Input, Output);

 optind = 0;
 opterr = 0;
 rrd_clear_error();
 rrd_update(NoArgs, Args);
 if(rrd_test_error())
 {
  sprintf(ErrorStr, "%s", rrd_get_error());
  ErrorNo = 1003;
  return -2;
 }
 return 0;
-------------------------------------------
Graph function : SNIP
 strcpy(Args[0],"graph");
 sprintf(Args[1],"%s\\%s_In.png", RRDDIR, ImgFileName);
 strcpy(Args[2],"-s");
 strcpy(Args[3],STime);
 strcpy(Args[4],"-e");
 strcpy(Args[5],ETime);
 strcpy(Args[6],"-t");
 strcpy(Args[7],"Input Usage Graph");
 strcpy(Args[8],"-v");
 strcpy(Args[9],"Input Usage");
 strcpy(Args[10],"-a");
 strcpy(Args[11],"PNG");
 strcpy(Args[12],"-w");
 strcpy(Args[13],"400");
 strcpy(Args[14],"-h");
 strcpy(Args[15],"100");
 sprintf(Args[16],"DEF:MAXIN=%s:Input:MAX", RRDName);
 sprintf(Args[17],"DEF:AVGIN=%s:Input:AVERAGE", RRDName);
 strcpy(Args[18],"CDEF:CMAXIN=MAXIN,UN,0,MAXIN,IF");
 strcpy(Args[19],"CDEF:CAVGIN=AVGIN,UN,0,AVGIN,IF");
 strcpy(Args[20],"AREA:CAVGIN#00eb0c:AVG Input");
 strcpy(Args[21],"LINE2:CMAXIN#0000ff:MAX Input \\n");
 strcpy(Args[22],"GPRINT:CAVGIN:AVERAGE:Average value \\: %1.2lf\\n");
 strcpy(Args[23],"GPRINT:CMAXIN:MAX:Maximum value \\: %1.2lf\\n");
 NoArgs = 25;
 XSize = 100;
 YSize = 400;
 rrd_clear_error();
 rrd_graph(NoArgs, Args, &PRData,(int *) &XSize,(int *) &YSize);
 if(rrd_test_error())
 {
  sprintf(ErrorStr, "%s", rrd_get_error());
  ErrorNo = 1005;
  return -2;
 }
 return 0;
-------------------------------------------

The code is too big. Pls. bear with me.

Thanks
Harish


---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

--
Unsubscribe
mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list