cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

New to the V2 Metrics API - Limiting fields in Response

louis_gallo
Participant

This command works great, and I get CPU stats for my server.

 

https://********.live.dynatrace.com/api/v2/metrics/query?metricSelector=

builtin:host.cpu(system)&resolution=1m&from=now1h

&to=now&entitySelector=type(HOST),tag(server:myserver.example.com)

 

I am now trying to dress that up. How can I limit or add fields in the response?

 

QUESTION 1 - If I try limiting the fields by removing one, it errors out. What am I doing wrong, or is this not allowed?

 

https://********.live.dynatrace.com/api/v2/metrics/query?fields=-metricId?

metricSelector=builtin:host.cpu.(system)&resolution=1m&from=now-1h

&to=now&entitySelector=type(HOST),tag(server:myserver.example.com)

 

QUESTION 2 - What if I want to have the server tag name in the CSV output? Is that possible. I can always add it after the API query if I have to.

 

I'm really trying to dress up the CSV extract to feed into a statistical engine like R.

 

Any advice is appreciated.

 

Thanks,

 

Lou (API V2 Newbie)

 

 

 

3 REPLIES 3

louis_gallo
Participant

Okay, partial success. I can get the server name in the names transformation. Yea!!!

 

https://xxxxxxxx.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:host.cpu.(system):na... 

y_buccellato
Helper

oi @louis_gallo  about question one something isn't right because "field=" is not included directly in an Api v2 call like you are using "api/v2/metrics/query?"

you can find "field=" in this kind of api:

/api/v2/entities?entitySelector=type%28%22HOST%22%29&from=now-1h&fields=%2Bproperties.osType

Plus the api call in question 1 seems to contain different error since you have at least two (?):

/api/v2/metrics/query?fields=-metricId?

If you go on more detail maybe we can help you out 🙂

Let us know how it went!


Radu
Dynatrace Pro
Dynatrace Pro

Hi Lou,

 

Question 1 - the "fields" parameter is not valid for the /metrics/query API endpoint. This is why it errors out. The "fields" parameter can be used instead with the /metrics endpoint which is used to retrieve information about the metric definition itslef. You can use this endpoint for example to find out what dimensions can a metric be split by (this is done by adding fields=+dimensionDefinitions).

 

Question2 - names of entities and dimensions returned by the /metrics/query API calls can be added in using the :names: transformation. Tags cannot be added as dimensions, but they can be used for filtering out entities that are returned in the result set. You can do that within the entitySelector parameter (e.g. entitySelector=type(service),tag(Environment:Staging) for including only services tagged with Environment=Staging)

 

I hope this helps.

 

Best regards,

Radu