dynatrace.Dynatrace-Java-Agent
Dynatrace-Java-Agent-Ansible
This Ansible role installs and sets up the Dynatrace AppMon Agent for monitoring Java applications.
Note: This role enables the Dynatrace AppMon Agent for a Java application by adding an -agentpath option to an environment variable (like JAVA_OPTS
) in a file, usually an executable script. This script should either run the Java application directly or be sourced by another script that runs the Java application. You need to restart your application after adding the agent.
Example
Suppose we have a script named run-foo.sh
that runs the main method in the Foo class:
java Foo
When you execute this role, the script will change to look like this:
export JAVA_OPTS="$JAVA_OPTS -agentpath:/opt/dynatrace/agent/lib64/libdtagent.so=name=foo-java-agent,collector=localhost:9998"
java Foo
Download
You can download the role from:
Dependencies
This role requires the following:
Role Variables
Defined in defaults/main.yml
:
Name | Default | Description |
---|---|---|
dynatrace_java_agent_env_var_name | JAVA_OPTS | The environment variable name for Agent injection. |
dynatrace_java_agent_env_var_file_name | required | The file name that needs to be changed. |
dynatrace_java_agent_env_var_file_insert_after | BOF | A regex pattern, BOF (begin-of-file) or EOF (end-of-file). If no regex is matched, the -agentpath option is added to the end of the file. |
dynatrace_java_agent_name | java-agent | The name of the Agent shown in Dynatrace AppMon. |
dynatrace_java_agent_collector_hostname | localhost | The address of the collector the Agent connects to. |
dynatrace_java_agent_collector_port | 9998 | The port on the collector for the Agent connection. |
dynatrace_java_agent_linux_agent_path | /opt/dynatrace/agent/lib64/libdtagent.so | The path to the Agent library. |
dynatrace_java_agent_state | present | If the Agent should be present or absent . |
Example Playbook
- hosts: all
roles:
- role: Dynatrace.Dynatrace-Java-Agent
dynatrace_java_agent_env_var_file_name: /usr/bin/run-foo.sh
dynatrace_java_agent_env_var_file_insert_after: '#!/bin/sh'
Testing
We use Test Kitchen to automatically check our automated setups with Serverspec and RSpec:
- Install Test Kitchen and its needed files from your project directory:
gem install bundler
bundle install
- Run all tests
kitchen test
By default, our tests run inside Docker containers, which speeds up testing (see .kitchen.yml
).
Additional Resources
Blogs
- How to Automate Enterprise Application Monitoring with Ansible
- How to Automate Enterprise Application Monitoring with Ansible - Part II
Presentations
- Automated Deployments (of Dynatrace AppMon) with Ansible
- Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Problems? Questions? Suggestions?
This project is Dynatrace Community Supported. Feel free to raise any problems, questions, or suggestions in the Dynatrace Community's Application Monitoring & UEM Forum.
License
Licensed under the MIT License. See the LICENSE file for more information.
An Ansible role for automated deployments of the Dynatrace Java Agent.
ansible-galaxy install dynatrace.Dynatrace-Java-Agent