Skip to content

Commit

Permalink
Implement QUARTERHOUR
Browse files Browse the repository at this point in the history
* Fix #1
  • Loading branch information
sip2thefuture authored and tinpotnick committed Oct 18, 2024
1 parent b278c68 commit 3a59023
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
25 changes: 25 additions & 0 deletions rrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
and the time spans are:
FIVEMINUTE
QUARTERHOUR
ONEHOUR
SIXHOUR
TWELVEHOUR
Expand Down Expand Up @@ -265,6 +266,10 @@ int printRRDBTouchFile(int pfd, char * path, char * period)
{
iperiod = FIVEMINUTE;
}
else if ( 0 == strcmp( period, "QUARTERHOUR" ) )
{
iperiod = QUARTERHOUR;
}
else if ( 0 == strcmp( period, "ONEHOUR" ) )
{
iperiod = ONEHOUR;
Expand Down Expand Up @@ -454,6 +459,8 @@ int initRRDBFile(char *filename, unsigned int setCount, unsigned int sampleCount

if ( 0 == strcmp("FIVEMINUTE", result)) {
fileData.xforms[i].period = FIVEMINUTE;
} else if ( 0 == strcmp("QUARTERHOUR", result)) {
fileData.xforms[i].period = QUARTERHOUR;
} else if ( 0 == strcmp("ONEHOUR", result)) {
fileData.xforms[i].period = ONEHOUR;
} else if ( 0 == strcmp("SIXHOUR", result)) {
Expand Down Expand Up @@ -747,6 +754,10 @@ int printRRDBFileInfo(char *filename)
printf("FIVEMINUTE\n");
break;

case QUARTERHOUR:
printf("QUARTERHOUR\n");
break;

case ONEHOUR:
printf("ONEHOUR\n");
break;
Expand Down Expand Up @@ -964,6 +975,14 @@ int updateRRDBFile(char *filename, char* vals) {
current_tm->tm_min = ((int)(current_tm->tm_min/5))*5;


xformstart.tv_sec = mktime(current_tm);
xformstart.tv_usec = 0;
break;

case QUARTERHOUR:
current_tm->tm_sec = 0;
current_tm->tm_min = ((int)(current_tm->tm_min/15))*15;;

xformstart.tv_sec = mktime(current_tm);
xformstart.tv_usec = 0;
break;
Expand Down Expand Up @@ -1130,6 +1149,10 @@ unsigned int getTimePerSample(unsigned int period)
return 60 * 5;
break;

case QUARTERHOUR:
return 60 * 15;
break;

case ONEHOUR:
return 60 * 60;
break;
Expand Down Expand Up @@ -1431,6 +1454,8 @@ int touchRRDBFile(char *filename, char *path, char * period, unsigned int maxset
while( NULL != perioditem ) {
if ( 0 == strcmp( perioditem, "FIVEMINUTE" ) ) {
iperiod = FIVEMINUTE;
} else if ( 0 == strcmp( perioditem, "QUARTERHOUR" ) ) {
iperiod = QUARTERHOUR;
} else if ( 0 == strcmp( perioditem, "ONEHOUR" ) ) {
iperiod = ONEHOUR;
} else if ( 0 == strcmp( perioditem, "SIXHOUR" ) ) {
Expand Down
2 changes: 1 addition & 1 deletion rrdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typedef struct rrdbTimePoint {
rrdbValid valid;
} rrdbTimePoint;

typedef enum {FIVEMINUTE = 0, ONEHOUR = 1, SIXHOUR = 2, TWELVEHOUR = 3, ONEDAY = 4} RRDBTimePeriods;
typedef enum {FIVEMINUTE = 0, ONEHOUR = 1, SIXHOUR = 2, TWELVEHOUR = 3, ONEDAY = 4, QUARTERHOUR = 5} RRDBTimePeriods;
typedef enum {RRDBMAX = 0, RRDBMIN = 1, RRDBCOUNT = 2, RRDBMEAN = 3, RRDBSUM = 4} RRDBCalculation;

typedef struct rrdbTouchHeader {
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
xforms = xforms + "RRDBMEAN:ONEDAY:0:"
xforms = xforms + "RRDBMEAN:FIVEMINUTE:1:"
xforms = xforms + "RRDBMEAN:ONEDAY:1"
xforms = xforms + "RRDBMAX:QUARTERHOUR:0"
os.system( "./rrdb --command=create --dir=./ --filename=test.rrdb --setcount=2 --samplecount=500 --xform=" + xforms )

totalsum = 0
Expand Down Expand Up @@ -81,6 +82,12 @@

print( "Xform 7 read a mean of {meanval}, expecting {ourcalcmean} ({totalsum}/{totalcount})".format( meanval=meanval, ourcalcmean=(secondtotalsum/totalcount), totalsum=secondtotalsum, totalcount=totalcount ) )

# Check xform 8 - RRDBMAX:QUARTERHOUR:0
readoutput = os.popen( "./rrdb --command=fetch --dir=./ --filename=test.rrdb --xform=8" ).read()
firstmax = float( timevalue.search( readoutput ).group( 2 ).strip() )

print( "Xform 8 - read a max of {max}, expecting {ourmax}".format( max=firstmax, ourmax=ourmax ) )

print( "Will sleep for 5 minutes to ensure windowing is correct" )
time.sleep( 60 * 5 )

Expand Down

0 comments on commit 3a59023

Please sign in to comment.