Populating a Kibana Table with formula

Hi everyone! I searched around on the forum but couldn't find any answer to this question.

I have this data in Kibana:
"startTime": "2018-03-14T15:05:13",
"stopTime": "2018-03-14T15:02:27"

and I created a scripted field that is stopTime minus startTime called Downtime.

Now I want to get an output that calculates availability during one month, e.g. march. The formula would be (downtime/Total_time_in_march) filtered on March.

I can't see how I can acheive this, any hints?

I haven't used the newer Java date time api in anger much so there may be a more elegant way to do this, but here's how I'd try to approach the problem.

  • If you're already calculating downtime, you probably have a LocalDateTime or ZonedDateTime object for startTime and stopTime.
  • You can use the with method on one of those objects, along with the helpers provided in TemporalAdjusters, to get DateTimes representing the first day of the current month and the next month.
  • Make sure to truncate these to DAYS, or you might even be able to use a LocalDate instead of a LocalDateTime. Depends which will work in the next step, I'm not sure off the top of my head.
  • Create a duration object with these two dates. Note the end of the range is exclusive, which is what we want.
  • Get the millis from the Duration, this represents the number of millis in the current month.
  • Use these millis in your availability formula

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.