# Which API to use to query the number of logs from a host?

**URL:** <https://community.graylog.org/t/which-api-to-use-to-query-the-number-of-logs-from-a-host/24516>\
**Category:** Graylog Central (peer support)\
**Created:** [June 28, 2022, 7:23am UTC](https://community.graylog.org/t/which-api-to-use-to-query-the-number-of-logs-from-a-host/24516 "2022-06-28T07:23:40Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gsmith](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gsmith/32/1222_2.png) [@gsmith](https://community.graylog.org/u/gsmith)\
**Post date:** [June 28, 2022, 10:09pm UTC](https://community.graylog.org/t/which-api-to-use-to-query-the-number-of-logs-from-a-host/24516/2 "2022-06-28T22:09:04Z")

</div>

Hello,

Correct me if I’m wrong , but this looks like the same post/question?

> [@Which API query to use to count logs](https://community.graylog.org/t/which-api-query-to-use-to-count-logs/24495):
>
> Hello, everyone, I haven't been using Graylog for longPreformatted text. Now I have it set up and can monitor four servers. I would now like to use the API to query whether a server has written log files in the last few hours. Not more. I'm currently trying the "views/search" query. I have already shortened the code to the bare essentials. Now I have a few questions. Can I even use the query for this? How do I enter query\_string? for example: "agent\_name:abcd\efgh\-u05". Which IDs do I have to …

If not have you tried to get a single value of a widget in graylog using the api?  
Graylog has a default dashboard called “Sources” within that dashboard is a widget called “Selected Sources”.

Perhaps you can get the for `Dashboard --> Widget --> Source`

Example:

Dashboard Views API

 ![image](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/2X/c/c6d62de1f0db7fad4d3d6cc4ba5191a5af24de3e.png)

Dashboard Sources results /w widget ID’s

```auto
"id": "5e4355886704f1e20679f322",
      "type": "DASHBOARD",
      "title": "Sources",
      "summary": "This is a list of all sources that sent in messages to Graylog.",
      "description": "This is a list of all sources that sent in messages to Graylog. You can narrow the timerange by zooming in on the message histogram, or you can increase the time range by specifying a broader one in the controls at the top. You can also specify filters to limit the results you are seeing. You can also add additional widgets to this dashboard, or adapt the appearance of existing widgets to suit your needs.",
      "search_id": "629834111d8b91a644ae6d9b",
      "properties": [],
      "requires": {},
      "state": {
        "a1647eb6-a064-4fe6-b459-1e4267d3f659": {
          "selected_fields": null,
          "static_message_list_id": null,
          "titles": {
            "tab": {
              "title": "Sources Overview"
            },
            "widget": {
              "6c127c5d-be75-4157-b43f-ac0194ac0586": "Selected sources",     
              "00637e63-d728-4b3e-932b-7c8696b4855d": "Messages over time",
              "9c8c9d14-5c29-4a17-a958-d9ac80eff0a2": "Number of Sources",             
              "92d63811-e4dd-47db-bd3b-db03c8a9bd53": "Messages per Source"
            }
          },

```

Selected Sources Widget information. Noticed the “\_id” matches.

```auto
{
              "id": "6c127c5d-be75-4157-b43f-ac0194ac0586",
              "type": "aggregation",
              "filter": null,
              "timerange": {
                "type": "relative",
                "range": 3600
              },
              "query": {
                "type": "elasticsearch",
                "query_string": ""
              },
              "streams": [],
              "config": {
                "row_pivots": [
                  {
                    "field": "source",
                    "type": "values",
                    "config": {
                      "limit": 60
                    }
                  }
                ],

```

You may want to look at this documentation.

- [Graylog REST API](https://docs.graylog.org/docs/rest-api)

Hope that helps.

---

_[View the full topic](https://community.graylog.org/t/which-api-to-use-to-query-the-number-of-logs-from-a-host/24516)._
