X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffrontend%2Fgrammar.y;h=58363df01dbebe37b861394f09632d47397b850a;hb=265c305ba8a591217a2c54673c40a3e28665a5b9;hp=3ece01a9bddc708285789cf2ab59c3c756419908;hpb=8014e0bb085059cc026a129fc9f09de8435f17ed;p=sysdb.git diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 3ece01a..58363df 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -33,6 +33,7 @@ #include "core/store.h" #include "core/store-private.h" +#include "core/time.h" #include "utils/error.h" #include "utils/llist.h" @@ -70,6 +71,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); char *str; sdb_data_t data; + sdb_time_t datetime; sdb_llist_t *list; sdb_conn_node_t *node; @@ -87,15 +89,19 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %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 IDENTIFIER STRING %token INTEGER FLOAT +%token DATE TIME + /* Precedence (lowest first): */ %left OR %left AND @@ -115,6 +121,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); fetch_statement list_statement lookup_statement + timeseries_statement matching_clause filter_clause condition @@ -129,6 +136,9 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %type data interval interval_elem +%type datetime + start_clause end_clause + %destructor { free($$); } %destructor { sdb_object_deref(SDB_OBJ($$)); } @@ -194,6 +204,8 @@ statement: | lookup_statement | + timeseries_statement + | /* empty */ { $$ = NULL; @@ -201,17 +213,29 @@ statement: ; /* - * FETCH [FILTER ]; + * FETCH [FILTER ]; * * Retrieve detailed information about a single host. */ fetch_statement: - FETCH STRING filter_clause + FETCH IDENTIFIER STRING filter_clause { + /* TODO: support other types as well */ + if (strcasecmp($2, "host")) { + char errmsg[strlen($2) + 32]; + snprintf(errmsg, sizeof(errmsg), + YY_("unknown data-source %s"), $2); + sdb_fe_yyerror(&yylloc, scanner, errmsg); + free($2); $2 = NULL; + free($3); $3 = NULL; + sdb_object_deref(SDB_OBJ($4)); + YYABORT; + } + $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, conn_fetch_t, conn_fetch_destroy)); - CONN_FETCH($$)->name = strdup($2); - CONN_FETCH($$)->filter = CONN_MATCHER($3); + CONN_FETCH($$)->name = $3; + CONN_FETCH($$)->filter = CONN_MATCHER($4); $$->cmd = CONNECTION_FETCH; free($2); $2 = NULL; } @@ -283,6 +307,34 @@ filter_clause: | /* empty */ { $$ = NULL; } +/* + * TIMESERIES . [START ] [END ]; + * + * 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. */ @@ -464,9 +516,19 @@ data: | 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 {