diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index a297714c074f20a22690245c5c51a8ab1f6d89bb..289d357f9239000dd6b099a58d80c9818b6b6f02 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
#include "core/store.h"
#include "core/store-private.h"
+#include "core/time.h"
#include "utils/error.h"
#include "utils/llist.h"
char *str;
sdb_data_t data;
+ sdb_time_t datetime;
sdb_llist_t *list;
sdb_conn_node_t *node;
%token CMP_LT CMP_LE CMP_GE CMP_GT
%token CONCAT
+%token START END
+
/* NULL token */
%token NULL_T
-%token FETCH LIST LOOKUP
+%token FETCH LIST LOOKUP TIMESERIES
%token <str> IDENTIFIER STRING
%token <data> INTEGER FLOAT
+%token <datetime> DATE TIME
+
/* Precedence (lowest first): */
%left OR
%left AND
fetch_statement
list_statement
lookup_statement
+ timeseries_statement
matching_clause
filter_clause
condition
%type <data> data
interval interval_elem
+%type <datetime> datetime
+ start_clause end_clause
+
%destructor { free($$); } <str>
%destructor { sdb_object_deref(SDB_OBJ($$)); } <node> <m> <expr>
|
lookup_statement
|
+ timeseries_statement
+ |
/* empty */
{
$$ = NULL;
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_list_t, conn_list_destroy));
+ CONN_LIST($$)->type = SDB_HOST;
CONN_LIST($$)->filter = CONN_MATCHER($3);
$$->cmd = CONNECTION_LIST;
free($2); $2 = NULL;
|
/* empty */ { $$ = NULL; }
+/*
+ * TIMESERIES <host>.<metric> [START <datetime>] [END <datetime>];
+ *
+ * Returns a time-series for the specified host's metric.
+ */
+timeseries_statement:
+ TIMESERIES STRING '.' STRING start_clause end_clause
+ {
+ $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
+ conn_ts_t, conn_ts_destroy));
+ CONN_TS($$)->hostname = $2;
+ CONN_TS($$)->metric = $4;
+ CONN_TS($$)->opts.start = $5;
+ CONN_TS($$)->opts.end = $6;
+ $$->cmd = CONNECTION_TIMESERIES;
+ }
+ ;
+
+start_clause:
+ START datetime { $$ = $2; }
+ |
+ /* empty */ { $$ = sdb_gettime() - SDB_INTERVAL_HOUR; }
+
+end_clause:
+ END datetime { $$ = $2; }
+ |
+ /* empty */ { $$ = sdb_gettime(); }
+
/*
* Basic expressions.
*/
|
FLOAT { $$ = $1; }
|
+ datetime { $$.type = SDB_TYPE_DATETIME; $$.data.datetime = $1; }
+ |
interval { $$ = $1; }
;
+datetime:
+ DATE TIME { $$ = $1 + $2; }
+ |
+ DATE { $$ = $1; }
+ |
+ TIME { $$ = $1; }
+ ;
+
interval:
interval interval_elem
{