OneAgent and ActiveGate version 1.299 are the last versions supporting OneAgent and ActiveGate Extensions 1.0 framework. You can continue using Extensions 1.0 if you stay at OneAgent or ActiveGate version 1.299. Note that this means you'll be using an unsupported Python version 3.8. We strongly recommend migrating your extensions to the latest Extensions 2.0 framework.
For more information, see General guidance and how to migrate.
Let’s learn by example. In this tutorial, we’ll walk you through the creation of a basic OneAgent extension. Your extension will enable monitoring of the demo application that's bundled with the extension SDK.
To run extensions with OneAgent installed on Amazon Linux 2022, you need to install the libxcrypt-compat
library.
whl
file that you'll use to install the SDK.examples
directory. In this tutorial, we'll use the extension located in the demo_oneagent_plugin
directory.We recommend that you install the Extensions SDK using Python Virtual Environment. For guidance, see Virtual Environments and Packages in Python documentation.
whl
file in it and run the following command:pip3 install plugin_sdk-[sdk version number]-py3-none-any.whl
pip3 install plugin_sdk-1.189.0.20200213.160436-py3-none-any.whl
plugin_sdk --help
to verify the Extensions SDK installation. For more information, see Install Extensions SDK.build_plugin
command will take care of OneAgent for you./opt/dynatrace/oneagent/plugin_deployment
directory.
During the development stage, we recommend that you install Extensions SDK on the OneAgent-monitored host to make your development process easier.version
property in the metadata section of your JSON definition.Navigate to the Extensions SDK \examples\demo_oneagent_plugin
directory and run the plugin_sdk build_plugin --no_upload
command. This will build the extension package from the current directory and copy the extension to the plugin_deployment folder
OneAgent directory.
Starting build_pluginValidating plugin.json against schemaPlugin data: Plugin name=custom.python.demo_plugin, version=1.0...========================================Plugin deployed successfully into /opt/dynatrace/oneagent/plugin_deployment/custom.python.demo_pluginPlugin archive available at /opt/dynatrace/oneagent/plugin_deployment/custom.python.demo_plugin.zip========================================
Running the command requires write privileges for the target directory, usually /opt/dynatrace/oneagent
on Linux and %PROGRAMFILES%\dynatrace\oneagent
on Windows.
See build_plugin for more information.
Go to Settings > Monitoring > Monitored technologies.
Select Add new technology monitoring.
In the Monitor any technology section, select Add OneAgent extension.
You'll see a high-level overview of the steps required to develop your extension, along with the Upload extension button.
Upload the custom.python.demo_plugin.zip
package you've just built.
After successful upload, you should find the extension on the Monitored technologies page in the Dynatrace web UI, on the Custom extensions tab.
Congratulations, you've successfully deployed your first OneAgent extension.
Note that you can automate the upload to the Dynatrace Cluster using the Extensions SDK or the Dynatrace API.
Your first OneAgent extension will monitor the demo application that's bundled with the Extensions SDK.
Start the demo application. Navigate to the directory where you extracted the SDK and run the following command:
plugin_sdk start_demo_app
Verify that your application is up and running. Go to http://127.0.0.1:8769/
and check that the application is responding.
When run without parameters, the application listens on localhost:8769
and responds to HTTP requests with the following JSON:
{"version": "1.001","random": 907,"counter": 116,"state": "ERROR","stat_counter": [6,10,12,],"battery_level": 88.4}
The counter
value increases with each hit to the page, while random
is a random number generated with each hit.
You can list the parameters of the demo application using:
plugin_sdk start_demo_app --help
These include the parameters for changing the default port and enabling authentication.
Wait patiently. It can take up to 2 minutes for the first data to be collected.
Navigate to the Host overview and select the plugin_sdk.demo_app
process.
The Process overview page appears. Select Further details.
The Process metrics page is displayed.
The OneAgent extension consists of two key files, one Python file and one JSON file. The JSON file defines the presentation of your data on various Dynatrace pages. With the Python file, you can define additional events and create custom properties. Play around with the files to see how the data presentation is affected.
The extension JSON file consists of the following four main elements:
The metadata contains a list of properties that are used to identify your extension.
{"name": "custom.remote.python.example_multi","version": "1.18","productiveMinVersion": "1.000","requiredAgentVersion": "1.000","type": "python","entity": "CUSTOM_DEVICE","metricGroup": "tech.Example_Service","technologies": ["EXAMPLE_SERVICE"],"source": {"package": "demo_activegate_plugin_multi","className": "RemoteExamplePlugin","install_requires": ["requests>=2.6.0"]}}
The extension name should follow ^custom.python(\.[a-zA-Z0-9_]+)+$
regex. For example, custom.python.my_plugin_2
. The name of each extension must be unique.
The technologies
and favicon
properties determine how your technology is presented on the Technology overview page in the Dynatrace web UI.
To have data from your extension displayed on an existing technology tile, specify a matching technology name. You can look up supported technology names in the JSON file or you can find them in the UI as the Main technology
process property.
To make an extension independent from a process, do not define the technologies
property.
The package name and class that is to be imported and executed by OneAgent correspond to the name of the Python file that contains the code and the name of the class that’s defined in it.
The metrics section describes the data gathered by the extension. This section provides two metrics that mirror both what our demo application serves, and what the Python code collects.
ConfigUI and the properties sections define the user interface elements used for extension configuration.
This part of the JSON file defines how metrics are charted. The key metrics section allows you to select the most important metrics and present them in the infographic and on the metric group page. You'll find charts on the Further details tab.
The Python code is stored in the demo_plugin.py
file.
import requestsfrom ruxit.api.base_plugin import BasePluginfrom ruxit.api.data import MEAttributefrom ruxit.api.snapshot import pgi_nameclass DemoPlugin(BasePlugin):def query(self, **kwargs):pgi = self.find_single_process_group(pgi_name('plugin_sdk.demo_app'))pgi_id = pgi.group_instance_idstats_url = "http://localhost:8769"stats = requests.get(stats_url).json()self.results_builder.absolute(key='random', value=stats['random'], entity_id=pgi_id)self.results_builder.relative(key='counter', value=stats['counter'], entity_id=pgi_id)self.results_builder.state_metric(key="state", value=stats['state'], dimensions={'app': 'demo'}, entity_id=pgi_id)self.results_builder.report_property(key="version", value=stats['version'],me_attribute=MEAttribute.CUSTOM_PG_METADATA, entity_id=pgi_id)
The file defines one class DemoPlugin
, which in turn defines one method query. When your plugin runs, this method is called once each minute to collect and send data to Dynatrace Cluster.
The demo application returns the JSON response as in the example below.
{"counter": 147, "random": 907}
The query method gathers some data from the demo application. The query method uses the HTTP request to receive the JSON response:
stats_url = "http://localhost:8769"stats = requests.get(stats_url).json()
Now it's time to report the stats to the Dynatrace Cluster. To do that, define the entity that measurements are associated with. The entity consists of: ID, type, name, and process snapshot, which is a data structure that contains all information about processes related to the entity discovered by OneAgent. To get the list of all entities related to the extension defined by the activation context, use the following method:
entities = self.get_monitored_entities()
This method returns the list of entities that represent all the currently running Python processes.
You can report the data on three levels: the monitored host EntityType.HOST
, the monitored process EntityType.PROCESS_GROUP_INSTANCE
, or the process group EntityType.PROCESS_GROUP
. Pass the EntityType
argument to the get_monitored_entities
method. If no argument is given, the entity property of plugin.json
will be taken.
This is just the beginning. Check out other example extensions that are delivered with the SDK and get to know which (technologies are supported using extensions forum.