# Metrics API v2 - unit State in Extension

**URL:** <https://community.dynatrace.com/t/metrics-api-v2-unit-state-in-extension/48115>\
**Category:** Extensions\
**Tags:** extensions\
**Created:** [October 3, 2024, 8:34am UTC](https://community.dynatrace.com/t/metrics-api-v2-unit-state-in-extension/48115 "2024-10-03T08:34:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![guptasahil942](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@guptasahil942](https://community.dynatrace.com/u/guptasahil942)\
**Post date:** [October 3, 2024, 8:34am UTC](https://community.dynatrace.com/t/metrics-api-v2-unit-state-in-extension/48115/1 "2024-10-03T08:34:27Z")

</div>

In extension 1.0 , I had a statetimeseries&nbsp;metric as below:

{ “statetimeseries”: { “key”: “host\_state”, “states”: [“UNHEALTHY”, “HEALTHY”, “INPROCESS”], “displayname”: “Host State” }}For migration to extension 2.0 , I am unable determine that how to define/map the states in yaml&nbsp; since there seems to be no&nbsp;“states” option under metadata :- key: host\_state&nbsp; &nbsp; metadata:&nbsp; &nbsp; &nbsp; displayName: Node State&nbsp; &nbsp; &nbsp; unit: State

---

<div class="post-metadata">

**Author:** ![florent\_duchate](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/florent_duchate/32/12258_2.png) [@florent\_duchate](https://community.dynatrace.com/u/florent_duchate)\
**Post date:** [October 3, 2024, 9:49am UTC](https://community.dynatrace.com/t/metrics-api-v2-unit-state-in-extension/48115/2 "2024-10-03T09:49:53Z")

</div>

State metrics no longer exist. The best solution is to use dimension values to indicate the state. For instance if it is&nbsp; INPROCESS, we set the dimension to inprocess and the value to 1 (true), we can either not set the other values or set them to 0 (false).

mymetric, metricstate=“INPROCESS” 1

mymetric, metricstate=“HEALTHY” 0

mymetric, metricstate=“UNHEALTHY” 0

---

<div class="post-metadata">

**Author:** ![guptasahil942](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@guptasahil942](https://community.dynatrace.com/u/guptasahil942)\
**Post date:** [October 3, 2024, 10:11am UTC](https://community.dynatrace.com/t/metrics-api-v2-unit-state-in-extension/48115/3 "2024-10-03T10:11:04Z")

</div>

By using below way , isn’t it that both HEALTHY and UNHEALTHY will both get same values.

mymetric, metricstate=“INPROCESS” 1

mymetric, metricstate=“HEALTHY” 0

mymetric, metricstate=“UNHEALTHY” 0

For the above metric solution , should we report metric in below way:

self.report\_metric(“mymetric”, metricstate=“INPROCESS” 1&nbsp;,{“host”:host\_entity.id})Or is it that dimension value needs to be set in YAML:- key: host\_state&nbsp; &nbsp; metadata:&nbsp; &nbsp; &nbsp; displayName: Node State&nbsp; &nbsp; &nbsp; unit: State&nbsp; &nbsp; &nbsp; dimensions:&nbsp; &nbsp; &nbsp; &nbsp; - key: host&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; displayName: Host

---

<div class="post-metadata">

**Author:** ![florent\_duchate](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/florent_duchate/32/12258_2.png) [@florent\_duchate](https://community.dynatrace.com/u/florent_duchate)\
**Post date:** [October 3, 2024, 12:31pm UTC](https://community.dynatrace.com/t/metrics-api-v2-unit-state-in-extension/48115/4 "2024-10-03T12:31:25Z")

</div>

yes they can have the same value. With dimensions it is almost like having 3 separate metrics. It is best to set them all because when charting it will look better as all 3 values will show.

You don’t need to set the host in the dimension as it will be done automatically for you if your extension is local. You should add the metricstatus dimension in the definition too.
