# Count events in a relative time frame using graylog api browser

**URL:** <https://community.graylog.org/t/count-events-in-a-relative-time-frame-using-graylog-api-browser/17847>\
**Category:** Graylog Central (peer support)\
**Created:** [November 14, 2020, 5:20am UTC](https://community.graylog.org/t/count-events-in-a-relative-time-frame-using-graylog-api-browser/17847 "2020-11-14T05:20:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diynamix](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@diynamix](https://community.graylog.org/u/diynamix)\
**Post date:** [November 14, 2020, 5:20am UTC](https://community.graylog.org/t/count-events-in-a-relative-time-frame-using-graylog-api-browser/17847/1 "2020-11-14T05:20:42Z")

</div>

Hi there,  
I need a solution about how to count events in a time frame by using graylog api browser.

When I look for a count event option in graylog rest api browser ther is only one option;

 ![image](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/2X/a/aa1add6335d688c5f276273459c7e49d7b147b56.png)  
In this option I can only choose a spesific stream, but I need events count in spesific time frame like last 30 minutes.  
how can I querry this url by adding last 30 min time range?  
[https://graylog](https://graylog).\*\*\*.com:443/api/count/5a9014c6abd9bf096aff683a/total

---

<div class="post-metadata">

**Author:** ![MajesticCo](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@MajesticCo](https://community.graylog.org/u/MajesticCo)\
**Post date:** [November 19, 2020, 7:30am UTC](https://community.graylog.org/t/count-events-in-a-relative-time-frame-using-graylog-api-browser/17847/2 "2020-11-19T07:30:19Z")

</div>

Hey,

This is a bit of a hack that I used for a similar thing in the past, not sure if there is a nicer way of doing it.  
Use the, now legacy, relative search API with `query=*`,` limit=1` and `range=1800`. That way you will get the latest message and also some statistics, those are what you are looking for. In a bash one liner it would be this:  
`curl -s -k -u admin:password -H 'X-Requested-By: cli' "https://GRAYLOG_IP_OR_HOSTNAME/api/search/universal/relative?query=*&limit=1&range=1800&sort=timestamp:desc&pretty=true" -H "Accept: application/jsn" -H "Content-Type: application/json" | jq '.total_results'`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/3X/c/7/c7c09c6b5099570133d6502b83f50ba4430de5b6.png) [@system](https://community.graylog.org/u/system)\
**Post date:** [December 3, 2020, 7:30am UTC](https://community.graylog.org/t/count-events-in-a-relative-time-frame-using-graylog-api-browser/17847/3 "2020-12-03T07:30:24Z")

</div>

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