Hi all,
I'm trying to create a query that gets the number of occurrences of certain Event per month. For that i get the number of elements with the following query:
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month
This will return only the months where there is actual data. For adding the months that are not in there since one year ago i thought that i can use gentimes. To do so I've tried to add :
|append [| gentimes start=08/24/2014 increment=28d|convert timeformat="%Y-%m" ctime(starttime) AS year_month|table year_month|dedup year_month]|fillnull
resulting in
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month|append [| gentimes start=08/24/2014 increment=28d|convert timeformat="%Y-%m" ctime(starttime) AS year_month|table year_month|dedup year_month]|fillnull
But now i want to add the start dynamically out of a subquery. I thought doing:
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month|append [| gentimes start=[search index="notexisting"|stats count|eval time=relative_time(now(),"-1y")|convert ctime(time) as time timeformat="\"%m/%d/%Y\"" |return $time] increment=28d|convert timeformat="%Y-%m" ctime(starttime) AS year_month|table year_month|dedup year_month]|fillnull
But I receive the following error:
[subsearch]: command="gentimes", generatetimestamps requires start=mm/dd/yyyy:hh:mm:ss and optional takes 'end' and 'increment' values.
Even using as the error suggest
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month|append [| gentimes start=[search index="notexisting"|stats count|eval time=relative_time(now(),"-1y")|convert ctime(time) as time timeformat="\"%m/%d/%Y:%H:%M:%S\"" |return $time] increment=28d|convert timeformat="%Y-%m" ctime(starttime) AS year_month|table year_month|dedup year_month]|fillnull
that is expected to return "08/21/2014:16:34:18" as the error indicates it still fails with
[subsearch]: command="gentimes", generatetimestamps requires start=mm/dd/yyyy:hh:mm:ss and optional takes 'end' and 'increment' values.
Even if i remove the quotes:
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month|append [| gentimes start=[search index="notexisting"|stats count|eval time=relative_time(now(),"-1y")|convert ctime(time) as time timeformat="%m/%d/%Y:%H:%M:%S" |return $time] increment=28d|convert timeformat="%Y-%m" ctime(starttime) AS year_month|table year_month|dedup year_month]|fillnull
The error is the same.
Is there a way to pass a relative time to gentimes? and append it to the query?
Try something like this
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month|append [| gentimes start=-1 |eval temp=mvrange(relative_time(now(),"-1y"),now(),28*86400) | table temp | mvexpand temp | eval year_month=strftime(temp,"%y-%m") |table year_month|dedup year_month]|fillnull
Try something like this
index=kpis|convert timeformat="%Y-%m" ctime(_time) AS year_month|chart count(Event) as events over year_month|append [| gentimes start=-1 |eval temp=mvrange(relative_time(now(),"-1y"),now(),28*86400) | table temp | mvexpand temp | eval year_month=strftime(temp,"%y-%m") |table year_month|dedup year_month]|fillnull
Why not use something like?
index=kpis | timechart span=1mon count(Event)
While the answer solves the problem of the months that we have data, does not do the same for the months that we don't have. I'm trying to use gentimes to fill the gaps and to ensure that each month there is data on it.
For instance if i do that that you suggest. The query returns 2015-01 and 2015-02 but not the rest of the months, even if the range i'm using is year to date.