# Getting APM metrics using the/an API

**URL:** <https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614>\
**Category:** APM\
**Tags:** python, ruby\
**Created:** [December 21, 2021, 9:12pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614 "2021-12-21T21:12:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxi\_Donadio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxi_donadio/32/97686_2.png) [@Maxi\_Donadio](https://discuss.elastic.co/u/Maxi_Donadio)\
**Post date:** [December 21, 2021, 9:12pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/1 "2021-12-21T21:12:21Z")

</div>

Hi!  
I'm have the elastic APM set up on some machines. It's working quite well and all the stats are showing perfectly fine, but I don't want to use _just_ the GUI. I'd like to get metrics (CPU Usage, Disk Usage, etc) for each machine using the/an API. Is there any way to do this? I've looked into the docs and the only similar thing that I can find are node/cluster metrics.

Thanks

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 21, 2021, 9:13pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/2 "2021-12-21T21:13:15Z")

</div>

Welcome to our community! 😃

Are you talking about Elasticsearch host stats, or something else?

---

<div class="post-metadata">

**Author:** ![Maxi\_Donadio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxi_donadio/32/97686_2.png) [@Maxi\_Donadio](https://discuss.elastic.co/u/Maxi_Donadio)\
**Post date:** [December 21, 2021, 9:27pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/3 "2021-12-21T21:27:51Z")

</div>

Thanks!

Something like that, for example:  
I have the APM installed on 4 machines and they're all configured to have SERVICE\_NAME as let's say: "SERV\_1". I can see the 4 machines under the instance section on SERV\_1, the APM shows their CPU Usage, Memory Usage, etc on the GUI. Is there an API to get the CPU Usage of these machines as shown on the APM?

Sorry if I don't explain myself correctly, english is my second language 😅

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 22, 2021, 1:09am UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/4 "2021-12-22T01:09:53Z")

</div>

Different APM agents collect different metrics. Which language are you using??

Also the APM agent is not going to collect as detailed infrastructure metrics as metricbeat or the elastic agent which collect Up to literally hundreds of infrastructure metrics.

So the question is what are you looking for to do?.

Also, all this information is simply stored in elastic indexes so you will be able to get to that data through the rest API. But let's figure out what you want to do first

---

<div class="post-metadata">

**Author:** ![Maxi\_Donadio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxi_donadio/32/97686_2.png) [@Maxi\_Donadio](https://discuss.elastic.co/u/Maxi_Donadio)\
**Post date:** [December 22, 2021, 4:50am UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/5 "2021-12-22T04:50:25Z")

</div>

I'm looking to get infrastructure data, such as CPU Usage, System Memory Usage and Disk Space. I want to create a script that gets this data given a time period and stores it in some file(Like a CSV). I'm using Python for some machines, Javascript for some other machines and Ruby as well. The language for the script is going to be python.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 22, 2021, 4:51am UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/6 "2021-12-22T04:51:28Z")

</div>

You're better off using Metricbeat, it can handle this all by default and give you dashboards in Kibana alongside your APM data.

---

<div class="post-metadata">

**Author:** ![Maxi\_Donadio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxi_donadio/32/97686_2.png) [@Maxi\_Donadio](https://discuss.elastic.co/u/Maxi_Donadio)\
**Post date:** [December 22, 2021, 1:18pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/7 "2021-12-22T13:18:34Z")

</div>

Does the Elasticsearch API support this? Do you have an example of it? Thanks!

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 22, 2021, 3:28pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/8 "2021-12-22T15:28:06Z")

</div>

I would take these steps. And no, I don't have a simple example for you.

Install metricbeat and collect system metrics. Send them to Elasticsearch It's very easy to do this as system metrics are the default collection meaning CPU, RAM disk, etc .

> **[Metricbeat quick start: installation and configuration | Metricbeat Reference...](https://www.elastic.co/guide/en/beats/metricbeat/current/metricbeat-installation-configuration.html)**

Then you can use the Python client to extract the data the way you like through the elastic API using the query DSL.

> **[Elasticsearch Python Client \[7.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/index.html)**

---

<div class="post-metadata">

**Author:** ![Maxi\_Donadio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxi_donadio/32/97686_2.png) [@Maxi\_Donadio](https://discuss.elastic.co/u/Maxi_Donadio)\
**Post date:** [December 22, 2021, 7:12pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/9 "2021-12-22T19:12:28Z")

</div>

Ok, so here's my question: Which endpoint do I have to send a request to in order to get the metrics? I've been trying GET /metricbeat-_/ with many options and GET /apm_/ and nothing gives me what I need. I'm testing all this stuff with the dev tools console.

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [December 22, 2021, 7:21pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/10 "2021-12-22T19:21:32Z")

</div>

`GET /metricbeat-*/_search`

That is a generic search

Then if you want documents say just from 1 host it would be like

```auto
GET /metricbeat-*/_search
{
  "query": {
    "term": {
      "host.name": {
        "value": "my-hostname"
      }
    }
  }
}

```

You are going to need to read a bit about the query DSL

> **[Query DSL | Elasticsearch Guide \[7.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html)**

> **[Query and filter context | Elasticsearch Guide \[7.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html)**

Most the time for search on data like metrics you will use a query + a time range filter

Get the metrics for host my-hostname for the last 15m

```auto
GET /metricbeat-*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "host.name": {
              "value": "my-hostname"
            }
          }
        }
      ],
      "filter": [
        {
          "range": {
            "@timestamp": {
              "gte": "now-15m/m"
            }
          }
        }
      ]
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Maxi\_Donadio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxi_donadio/32/97686_2.png) [@Maxi\_Donadio](https://discuss.elastic.co/u/Maxi_Donadio)\
**Post date:** [December 22, 2021, 8:15pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/11 "2021-12-22T20:15:19Z")

</div>

This worked! Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 12, 2022, 4:16pm UTC](https://discuss.elastic.co/t/getting-apm-metrics-using-the-an-api/292614/12 "2022-01-12T16:16:18Z")

</div>

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