# Pushing custom metrics to Dynatrace using OneAgent extension

**URL:** <https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462>\
**Category:** Extensions\
**Tags:** dynatrace-managed, extensions, oneagent-sdk\
**Created:** [September 7, 2022, 5:47am UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462 "2022-09-07T05:47:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mayank\_Sh](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mayank\_Sh](https://community.dynatrace.com/u/Mayank_Sh)\
**Post date:** [September 7, 2022, 5:47am UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462/1 "2022-09-07T05:47:51Z")

</div>

In my use case, I am retrieving metrics from endpoint and trying to push to Dynatrace SaaS using OneAgent SDK (ie.. plugin.py and plugin.json).

1. Plugin.json:

- As endpoint contains varied kind of metrics. So, I considered hardcoding each of the metrics under metrics sections along with their respective dimensions.

- I have not used config-ui and ui section.

- For all other fields, kindly have a look at attached screenshot.

 ![Plugin_json.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/9/795df1f3db1670aad85de668bd08f9cd19a33b2f.png)

Similarly, there are 40 more metrics.

2. Plugin.py:

I am retrieving metrics from endpoint using prometheus\_client.parser :

_from prometheus\_client.parser import text\_string\_to\_metric\_families_

For transformation of metrics in Dynatrace-supported format , I am using this part of code:

 ![Metric_insertion.png](https://global.discourse-cdn.com/dynatrace/original/2X/f/ff80481bbffed5ce3867ebec98f2b61b18161eea.png)

- “metric-server” I have kept as Process group for now. But, not sure whether it is right or wrong ?

For pushing metrics to Dynatrace , this is used:

 ![plugin_dimension.png](https://global.discourse-cdn.com/dynatrace/original/3X/7/a/7a9978506b97b85dd04e0e5135a5069ad64b23e5.png)

**Issues faced by :**

**-** On uploading of SDK in Dynatrace SaaS, though dimensions are being created on Dynatrace with respective metric name but, **data is not coming.**

- Is there any alternative way from **hardcoding metrics in plugin.json** and keep it more dynamic?

---

<div class="post-metadata">

**Author:** ![Mike\_L](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/mike_l/32/11717_2.png) [@Mike\_L](https://community.dynatrace.com/u/Mike_L)\
**Post date:** [September 7, 2022, 8:18pm UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462/2 "2022-09-07T20:18:31Z")

</div>

Hi,

if I were you I’d definitely use extension framework 2.0 instead. It comes with a declarative framework for Prometheus so you don’t have to write any code.

You can find more details here:

> **[Prometheus data source](https://docs.dynatrace.com/docs/ingest-from/extensions/develop-your-extensions/data-sources/prometheus-extensions)**
>
> Learn how to create a Prometheus extension using the Extensions framework.

Mike

---

<div class="post-metadata">

**Author:** ![Mayank\_Sh](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mayank\_Sh](https://community.dynatrace.com/u/Mayank_Sh)\
**Post date:** [September 14, 2022, 1:29pm UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462/3 "2022-09-14T13:29:50Z")

</div>

Thanks for reply Mike,

We are looking into the extension framework 2.0. But, meanwhile, can you tell me any remedy associated with the above followed procedure to get metrics in Dynatrace ?

Also, to avoid hardcoding of plugin.json file.

Thanks.

---

<div class="post-metadata">

**Author:** ![Julius\_Loman](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/julius_loman/32/51_2.png) [@Julius\_Loman](https://community.dynatrace.com/u/Julius_Loman)\
**Post date:** [September 14, 2022, 2:10pm UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462/4 "2022-09-14T14:10:09Z")

</div>

[@Mayank\_Sh](https://community.dynatrace.com/user/54732)&nbsp; Extensions 1.0 require metrics specified in the plugin.json. The only way to get around it is to send the metrics using by calling the Metric API from the code instead of the SDK methods. The [ingest data point Metric API](https://www.dynatrace.com/support/help/shortlink/api-metrics-v2-post-datapoints)  
You can use the [Python API client](https://github.com/dynatrace-oss/api-client-python) for that. So you will use the extension code just to fetch and process the metric, but the sending will be using the API. Not ideal, but it will work.

If it’s only prometheus as the source, definitely use Extension 2.0 for that.

---

<div class="post-metadata">

**Author:** ![Mayank\_Sh](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@Mayank\_Sh](https://community.dynatrace.com/u/Mayank_Sh)\
**Post date:** [September 16, 2022, 9:15am UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462/5 "2022-09-16T09:15:33Z")

</div>

Hi [@Mike\_L](https://community.dynatrace.com/user/11520)&nbsp; and [@Julius\_Loman](https://community.dynatrace.com/user/3364)&nbsp; , Thanks for reply.

We are trying Prometheus extension 2.0 now.

We are monitoring an application which has been deployed on Kubernetes cluster(GKE). We have oneagent running as a container inside the pods. As a part of extension 2.0 process , we are required to upload root certificate(ca.pem) in each Oneagent host.

Challenge which are being faced:

1. We are not able to copy root certificate file inside the pod.
  - Command used by us is :&nbsp;kubectl cp ca.pem dynatrace-oneagent-bk6ns:/var/lib/dynatrace/oneagent/agent/config/certificates -n dynatrace
  - Error observed is :error: Internal error occurred: error executing command in container: failed to exec in container: failed to start exec “25efd997d58778142223f246292fd80171dfc99aea1a3531c9ded878ddba9380”: OCI runtime exec failed: exec failed: unable to start container process: exec: “tar”: executable file not found in $PATH: unknown

2. Even though we resolve the first issue, if pod is getting restarted then, we will lose root&nbsp;certificate again&nbsp;because pod is not persisting data. What is the remedy for it ?

Also, we are not allowed to create custom OneAgent image.

 ![Screenshot 2022-09-16 at 2.42.07 PM.png](https://global.discourse-cdn.com/dynatrace/original/1X/6526a656fbad5fe55fd360b3af818cd01aad96ca.png)

---

<div class="post-metadata">

**Author:** ![Mike\_L](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/mike_l/32/11717_2.png) [@Mike\_L](https://community.dynatrace.com/u/Mike_L)\
**Post date:** [September 16, 2022, 10:54am UTC](https://community.dynatrace.com/t/pushing-custom-metrics-to-dynatrace-using-oneagent-extension/36462/6 "2022-09-16T10:54:10Z")

</div>

The remedy from our services team would be to sign it with the Dynatrace cert, but that’s not possible for you of course. Looking at the error there are some solutions described here:&nbsp;[https://stackoverflow.com/questions/67087858/why-does-kubectl-cp-command-terminates-with-exit-code-126](https://stackoverflow.com/questions/67087858/why-does-kubectl-cp-command-terminates-with-exit-code-126)
