Extension simulator
To facilitate extension development, the SDK comes with a tool that can execute your extension without the need for you to run an ActiveGate, OneAgent, or connect to Dynatrace Server. This extension simulator is a pure Python solution that's designed to mimic an ActiveGate or OneAgent with only a few limitations:
Extension configuration (if any) needs to be provided manually in the form of a JSON file.
No data is sent to or received from Dynatrace Server.
The Python environment contains the libraries required by the extension.
A typical extension simulator workflow is as follows:
- Write the extension code and
plugin.json
. - Create a
simulator_snapshot.json
file with the minimum data required to trigger extension activation. - Create a
properties.json
file with the configuration properties required by your extension. Run the extension simulator and observe the reported results. Address any identified errors.
Run the simulator
To start the simulator, use the following command:
oneagent_simulate_plugin
Or shorter:
oneagent_sim
No additional arguments are needed if the command is executed from the directory that contains the extension. For other options, see below.
1(sdk) c:\work\plugin_development\custom.remote.python.stress>oneagent_sim --help2usage: oneagent_sim [-h] [-p PLUGIN_DIR] [-v] [-n SNAPSHOT] [-r PROPERTIES]3 [-i INTERVAL] [--version]45optional arguments:6 -h, --help show this help message and exit7 -p PLUGIN_DIR, --plugin_dir PLUGIN_DIR8 plugin directory path9 -v, --verbose increase verbosity10 -n SNAPSHOT, --snapshot SNAPSHOT11 path to snapshot file12 (PLUGIN_DIR/simulator_snapshot.json by default)13 -r PROPERTIES, --properties PROPERTIES14 path to properties file (PLUGIN_DIR/properties.json by15 default)16 -i INTERVAL, --interval INTERVAL17 set the interval between plugin measurements (default:18 60 seconds)19 --version show program's version and exit
Extension directory
To point to the extension directory, use the -p
or --plugin_dir
parameters. This is the path to the directory that contains the extension you're testing. The extension directory path must contain the plugin.json
file, which will be added to the Python module search path. You can set this to the path where you're developing your extension, or you can set it to the output of the oneagent_build_plugin
command. The latter approach has the advantage of immediately providing the libraries that your extension depends on. However, it also requires that you run the build command for syncing.
Properties file
If your extension requires configuration, use a JSON file that contains a dictionary of properties and their values. See an example of the properties.json
that must be saved in the directory that contains the developed extension:
1{2 "url": "http://localhost:8769",3 "user": "ruxit",4 "password": "ruxit"5}
The configuration corresponds to the properties
section in plugin.json
(see Extensions reference).
Interval
The extension simulator can also change the interval between measurements. This can be useful for calling methods at a higher frequency, or when your extension requires multiple measurements to send the results. For example, if it computes differences or averages between consecutive measurements.
Analyze the extension simulator screen output
The simulator runs until it is stopped manually (usually by pressing Ctrl-C
). The output is written to the terminal and log file, and a short summary of operations is provided upon completion, which should look similar to:
1INFO:plugin_development.global:{('custom.remote.python.demo', '123'): (PluginState(pluginName='custom.remote.python.demo', pluginVersion='1.0', state='OK', description='', monitoredEntityId='123', stacktrace=''), 242022.234)}2WARNING:plugin_sdk.plugin_simulator:Plugin simulator was stopped with a Keyboard interrupt3Plugin simulator summary:4At 10:03:30 reported measurements:5[WrappedPluginMeasurement(monitoredEntityId=8410346495561112286, tsIdentifier='custom.remote.python.demo:countercd', dimensions=[], value=2.0, aggregation=1, isV3=False, isStatetimeseries=False, isStatCounter=False),6 WrappedPluginMeasurement(monitoredEntityId=837416055638757496, tsIdentifier='custom.remote.python.demo:countercd', dimensions=[], value=2.0, aggregation=1, isV3=False, isStatetimeseries=False, isStatCounter=False)]7At 10:03:30 reported status: OK
If an error occurs, the summary may offer a hint as to why:
1Plugin simulator summary:2At 10:05:17 reported status: UNINITIALIZED3At 10:05:17 reported status: ERROR_UNKNOWN4Status details:5HTTPConnectionPool(host='localhost', port=8769): Max retries exceeded with url: /topology (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000275168A3E48>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))
In this example, the error was caused by the absence of a running oneagent_sdk.demo_app
process. So the extension was unable to gather data.
The report at the end of the simulator run isn't the only source of information. You can also analyze log messages that are sent while the simulator runs.