# Getting metrics via API

**URL:** <https://community.dynatrace.com/t/getting-metrics-via-api/33037>\
**Category:** Dynatrace API\
**Tags:** dynatrace-managed, dynatrace-api\
**Created:** [October 19, 2021, 4:22pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037 "2021-10-19T16:22:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [October 19, 2021, 4:22pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/1 "2021-10-19T16:22:05Z")

</div>

Hi, I want to get some metrics from the dynatrace but I’m not sure they belong to which version V1 or V2? Can anyone help me with finding the correct address for getting the following metrics:

memory usage(service and process), CPU usage(service and process), throughput, network traffic, responsiveness, network connectivity and data round trip time

---

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [October 20, 2021, 7:35am UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/2 "2021-10-20T07:35:30Z")

</div>

Hi&nbsp;[@infotech](https://community.dynatrace.com/user/44951)&nbsp;,

it’s not relevant if you use APIv1 or APIv2. All metrics are available on both API versions, just in a different way and possibilities how to get them.

You can use the “Metric” browser in Dynatrace to find the metric IDs for the ones you want to query. For example a generic memory usage of processes can be found with this ID:

 ![r_weber_0-1634715317013.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/0/f00f5a08b49d659243b6a4f18a147a72b2f75a2b.png)

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [November 20, 2021, 8:16pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/3 "2021-11-20T20:16:49Z")

</div>

Hi&nbsp;[@r\_weber](https://community.dynatrace.com/user/35901)

https://“mine”.live.dynatrace.com/api/v1/timeseries/com.dynatrace.builtin:tech.generic.cpu.usage?api…&nbsp;&nbsp;token"&includeData=true&aggregationType=avg&entity=PROCESS\_GROUP\_INSTANCE-BD475E0A43F03373

I entered the above URL but it returned:

```auto
{"error":{"code":404,"message":"Timeseries id com.dynatrace.builtin:tech.generic.cpu.usage is not valid"}}  

```

I got the same error for:

https://“mine”.live.dynatrace.com/api/v1/timeseries/com.dynatrace.builtin:tech.generic.mem.usage?api…&nbsp;&nbsp;token"&includeData=true&aggregationType=avg&entity=PROCESS\_GROUP\_INSTANCE-BD475E0A43F03373

I can also see throughput for a service in Dynatrace but when I enter its entity, again I receive the same error!

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [November 22, 2021, 9:10am UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/4 "2021-11-22T09:10:30Z")

</div>

[@infotech](https://community.dynatrace.com/user/44951),

If you try it out from the web interface:

[https://mine.live.dynatrace.com/rest-api-doc/index.jsp?urls.primaryName=Environment](https://mine.live.dynatrace.com/rest-api-doc/index.jsp?urls.primaryName=Environment)&nbsp; API v1

It will generate the curl command from the selections that you make, so it will be easier to figure out what is wrong.

---

<div class="post-metadata">

**Author:** ![r\_weber](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/r_weber/32/24884_2.png) [@r\_weber](https://community.dynatrace.com/u/r_weber)\
**Post date:** [November 22, 2021, 11:57am UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/5 "2021-11-22T11:57:23Z")

</div>

Hi&nbsp;[@infotech](https://community.dynatrace.com/user/44951)&nbsp;,

the metric ID is “builtin:tech.generic.cpu.usage” not “com.dynatrace.builtin:…”  
With that it should work. But I also recommend to using the V2 API for anything new you design, it provides some more nice features.

kr,

Reinhard

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [November 22, 2021, 4:04pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/6 "2021-11-22T16:04:33Z")

</div>

For response time , the only metric that I could successfully receive from the API, I entered “com.dynatrace…” and it worked so I thought maybe I need to enter that part for all of the metrics. I just deleted that part and still got the same error!

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [November 22, 2021, 4:21pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/7 "2021-11-22T16:21:20Z")

</div>

Thank you, I went to that page and under “​/metrics​/{metricKey} Gets the descriptor of the specified metric” entered “tech.generic.mem.usage” but it returned a 404 error! Do I need to add anything else in that input box?

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [November 22, 2021, 7:05pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/8 "2021-11-22T19:05:23Z")

</div>

If you are using /metrics you are using APIv2. Beware that the synthax for v1 & v2 differ for metrics.

Now, if you want the values from the metrics, you should use /metrics/query

Then, you should enter builtin:tech.generic.mem.usage in metricSelector

 ![AntonioSousa_0-1637607845293.png](https://global.discourse-cdn.com/dynatrace/original/2X/7/7da800874a7bfba723da93a18c5ee01228ee8867.png)

Then click Execute, and you should get the values, and some curl like:  
curl -X GET “[https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Atech.generic.mem.usage](https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Atech.generic.mem.usage)” -H “accept: application/json; charset=utf-8” -H “Authorization: Api-Token YOUR\_API\_TOKEN”

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [November 23, 2021, 5:51pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/9 "2021-11-23T17:51:35Z")

</div>

Hi again,

I could get the data from V2 but unfortunately, it lacks information such as display name, aggregation types and I need them as well. Also, I cannot get the values for only one specific entity although I added the entity id for my process.

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [November 29, 2021, 4:14pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/10 "2021-11-29T16:14:38Z")

</div>

Hi&nbsp;[@AntonioSousa](https://community.dynatrace.com/user/17213)

Can you help me with the above problem?

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [December 9, 2021, 12:31am UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/11 "2021-12-09T00:31:45Z")

</div>

Hi,

Can anyone help me with this issue?

[@AntonioSousa](https://community.dynatrace.com/user/17213)&nbsp;[@r\_weber](https://community.dynatrace.com/user/35901)

---

<div class="post-metadata">

**Author:** ![AntonioSousa](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/antoniosousa/32/50_2.png) [@AntonioSousa](https://community.dynatrace.com/u/AntonioSousa)\
**Post date:** [December 9, 2021, 10:03am UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/12 "2021-12-09T10:03:00Z")

</div>

[@infotech](https://community.dynatrace.com/user/44951),

Regarding the information that you are lacking, you might need to make other API calls. That is typically the case when you get Entity codes in the JSON replies, and you want to get detailed information about those entities.

Regarding the second part of your question, it would be important for you to post here the API call you are invoking (please do not include sensitive information, eg. url & API token).

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [December 12, 2021, 2:00pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/13 "2021-12-12T14:00:53Z")

</div>

So do you know which API I should call?

this is what works but I need to get the specific entity information not all of them, I entered the entity id but still get the same values!

[https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:tech.generic.cpu.usage&api-token=mytoken](https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:tech.generic.cpu.usage&api-token=mytoken)

Thank you

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [December 12, 2021, 3:05pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/14 "2021-12-12T15:05:17Z")

</div>

Hi&nbsp;[@infotech](https://community.dynatrace.com/user/44951)

You need to add the process name you are looking for to the enttitySelector.

In order to do taht you can go to the data explorer select **Process CPU usage** &nbsp;metric, split by **process** and in the filter pick the&nbsp; process.name you are looking for.

 ![Yosi_Neuman_0-1639321111174.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/f/ff0e7aee35856ed88df817a69e4a8d458c1a11ab.png)

Then go to the code tab and copy the&nbsp;entitySelector part:

 ![Yosi_Neuman_2-1639321439255.png](https://global.discourse-cdn.com/dynatrace/original/2X/e/e6dadc16ba2effa47edfd01211b25d0609ee0f7a.png)

HTH

Yos

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [December 12, 2021, 4:32pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/15 "2021-12-12T16:32:01Z")

</div>

If you mean something like this:

[https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:tech.generic.cpu.usage&api-token=mine&entitySelector=PROCESS\_GROUP\_INSTANCE-BD475E0A43F03373](https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:tech.generic.cpu.usage&api-token=mine&entitySelector=PROCESS%5C_GROUP%5C_INSTANCE-BD475E0A43F03373)

I did add the entity selector as well before replying to the above post but it returns error code 400

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [December 12, 2021, 5:06pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/16 "2021-12-12T17:06:26Z")

</div>

Go to the rest api explorer, under Environment API v2 find metric/query entry and add your metric:&nbsp;_ **builtin:tech.generic.cpu.usage** _

 ![Yosi_Neuman_1-1639328325127.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/5/e5c5b80b1e2807254bcc67ab3b00b266ecd96d22.png)

go to the selector filed and add _type_ and _your process ID_ as&nbsp;_**type(“PROCESS\_GROUP\_INSTANCE”),entityId(“PROCESS\_GROUP\_INSTANCE-XXXXXXXXX”)**_

 ![Yosi_Neuman_0-1639328270920.png](https://global.discourse-cdn.com/dynatrace/original/3X/d/2/d270b0aa4da4862df740c4b922de154cc32f5d3a.png)

click on the execute button and you will get the response.

Then copy from the curl or url fields the whole request and paste it where you need it, this should work as a charm.

HTH

Yos

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [December 12, 2021, 5:27pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/17 "2021-12-12T17:27:53Z")

</div>

Still got the same error!

 ![infotech_0-1639330026403.png](https://global.discourse-cdn.com/dynatrace/original/2X/2/227285597517b36419106195a69ac3d53164bb28.png)

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [December 12, 2021, 5:33pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/18 "2021-12-12T17:33:21Z")

</div>

What did you put in selector filed? can you paste it here please?

---

<div class="post-metadata">

**Author:** ![infotech](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/infotech/32/23966_2.png) [@infotech](https://community.dynatrace.com/u/infotech)\
**Post date:** [December 12, 2021, 5:37pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/19 "2021-12-12T17:37:22Z")

</div>

What I got from data explorer:

type(process\_group\_instance),entityId(~“PROCESS\_GROUP\_INSTANCE-BD475E0A43F03373~”)

---

<div class="post-metadata">

**Author:** ![Yosi\_Neuman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/yosi_neuman/32/9845_2.png) [@Yosi\_Neuman](https://community.dynatrace.com/u/Yosi_Neuman)\
**Post date:** [December 12, 2021, 5:40pm UTC](https://community.dynatrace.com/t/getting-metrics-via-api/33037/20 "2021-12-12T17:40:09Z")

</div>

Try this please:

type(“PROCESS\_GROUP\_INSTANCE”),entityId(“PROCESS\_GROUP\_INSTANCE-BD475E0A43F03373”)

Yos

[Next page](https://community.dynatrace.com/t/getting-metrics-via-api/33037.md?page=2)
