# Database Query Extension

**URL:** <https://community.dynatrace.com/t/database-query-extension/32862>\
**Category:** Extensions\
**Tags:** databases, sql, extensions\
**Created:** [September 30, 2021, 11:22pm UTC](https://community.dynatrace.com/t/database-query-extension/32862 "2021-09-30T23:22:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![RodrigoBiaggio](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rodrigobiaggio/32/39343_2.png) [@RodrigoBiaggio](https://community.dynatrace.com/u/RodrigoBiaggio)\
**Post date:** [September 30, 2021, 11:22pm UTC](https://community.dynatrace.com/t/database-query-extension/32862/1 "2021-09-30T23:22:04Z")

</div>

Guys, please, I need some help on an extension. I need to create a plugin that executes a query against a MySQL database. Should I create an ActiveGate Extension or Oneagent extension? Does anyone have an example or any documentation that shows a model?

---

<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:** [October 1, 2021, 5:13am UTC](https://community.dynatrace.com/t/database-query-extension/32862/2 "2021-10-01T05:13:13Z")

</div>

The answer is - it depends on the requirements. If it’s for a single purpose, I’d consider writing a simple script that will execute queries using MySQL command line client and push the metrics using metric ingestion or events using API. This is much simpler than the writing extension.

If you still need to create an extension, keep in mind:

- OneAgent extensions can only push data to process groups residing on the same host where they run. (so you must have Oneagent on the DB host).
- ActiveGate extension creates new entities (custom devices). You can somehow also push data to existing entities based on metadata.

For samples see [here in the docs](https://www.dynatrace.com/support/help/extend-dynatrace/extensions/)&nbsp;and for inspiration, you can look into the code of the MySQL extension that is shipped with the OneAgent itself.

---

<div class="post-metadata">

**Author:** ![RodrigoBiaggio](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/rodrigobiaggio/32/39343_2.png) [@RodrigoBiaggio](https://community.dynatrace.com/u/RodrigoBiaggio)\
**Post date:** [October 1, 2021, 12:36pm UTC](https://community.dynatrace.com/t/database-query-extension/32862/3 "2021-10-01T12:36:43Z")

</div>

Julius, sorry, but just a question. To run the first option you mentioned, I would need the agent installed on the database servers, right? My question is how I would schedule this script execution and sending the metrics, which makes me wonder.

---

<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:** [October 1, 2021, 1:24pm UTC](https://community.dynatrace.com/t/database-query-extension/32862/4 "2021-10-01T13:24:52Z")

</div>

[@RodrigoBiaggio](https://community.dynatrace.com/user/44799)&nbsp; you have actually two options here for sending.

- You have OneAgent on the host from where you will send the metrics → send them using [local ingestion interface](https://www.dynatrace.com/support/help/shortlink/metric-ingestion#anchor_local)
- You don’t have OneAgent on the host → send them [using API](https://www.dynatrace.com/support/help/how-to-use-dynatrace/metrics/metric-ingestion/#anchor_api)&nbsp;You will need to have an API token created in this case and typically you will want to set the dt.entity in the output.

Depending on your DB you can execute it remotely.  
Regarding scheduling - use cron or systemd on Linux for example, Windows scheduler on windows. It’s really up to you. You can also run a daemon in and process it in a loop.

---

<div class="post-metadata">

**Author:** ![Enrico\_F](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/enrico_f/32/23774_2.png) [@Enrico\_F](https://community.dynatrace.com/u/Enrico_F)\
**Post date:** [June 10, 2022, 6:07am UTC](https://community.dynatrace.com/t/database-query-extension/32862/5 "2022-06-10T06:07:14Z")

</div>

FYI: There is an officially supported plugin providing that functionality: [Custom Database Queries](https://www.dynatrace.com/hub/detail/custom-database-queries/).

---

<div class="post-metadata">

**Author:** ![GaryB](https://avatars.discourse-cdn.com/v4/letter/g/ee59a6/32.png) [@GaryB](https://community.dynatrace.com/u/GaryB)\
**Post date:** [June 20, 2022, 5:10pm UTC](https://community.dynatrace.com/t/database-query-extension/32862/6 "2022-06-20T17:10:35Z")

</div>

How are database credentials stored and maintained with this plugin?

---

<div class="post-metadata">

**Author:** ![Enrico\_F](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/enrico_f/32/23774_2.png) [@Enrico\_F](https://community.dynatrace.com/u/Enrico_F)\
**Post date:** [June 21, 2022, 6:02pm UTC](https://community.dynatrace.com/t/database-query-extension/32862/7 "2022-06-21T18:02:31Z")

</div>

As with any custom extension that implements the Extensions SDK the instance config (including DB credentials in this case) can be managed either via the UI (via “endpoint config” in the custom extension settings) or programmatically via the config API (via GET/PUT/DELETE /api/config/v1/extensions/{id}/instances/{configurationId}).

---

<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:** [June 21, 2022, 6:19pm UTC](https://community.dynatrace.com/t/database-query-extension/32862/8 "2022-06-21T18:19:01Z")

</div>

They are stored encrypted in the Dynatrace database. It is then transferred in a secure way to the ActiveGate and never leave the ActiveGate’s memory.
