Guide to Monitoring URLs with Authentication Using Splunk AppDynamics and Python
Monitoring URLs are an important part of your FullStackMonitoring.
Splunk AppDynamics lets you monitor URLs with...
See more...
Guide to Monitoring URLs with Authentication Using Splunk AppDynamics and Python
Monitoring URLs are an important part of your FullStackMonitoring.
Splunk AppDynamics lets you monitor URLs with different authentication. In this article, we will create a simple URL with a username and password. Afterwards, we will monitor it using AppDynamics Machine Agent.
Create a Simple API with Python (Flask)
Install Flask: pip install flask
Create the API: Save the following Python code to a file, e.g., basic_auth_api.py : from flask import Flask, request, jsonify
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__)
auth = HTTPBasicAuth()
# Dummy users for authentication
users = {
"user1": "password123",
"user2": "securepassword",
}
@auth.get_password
def get_pw(username):
return users.get(username)
@app.route('/api/data', methods=['GET'])
@auth.login_required
def get_data():
return jsonify({"message": f"Hello, {auth.username()}! Here is your data."})
if __name__ == '__main__':
app.run(debug=True, port=5000)
Run the API: Start the server by running: python basic_auth_api.py
Test the API: Use curl to access the API: curl -u user1:password123 http://127.0.0.1:5000/api/data
You should see a response like this: {
"message": "Hello, user1! Here is your data."
}
Install Machine Agent
You can install the Machine agent as recommended here
Setup URL Monitoring Extension
Clone the Github Repo: git clone https://github.com/Appdynamics/url-monitoring-extension.git
cd url-monitoring-extension
Download and install Apache Maven which is configured with Java 8 to build the extension artifact from the source. You can check the Java version used in Maven using command mvn -v or mvn --version . If your maven is using some other Java version then please download Java 8 for your platform and set JAVA_HOME parameter before starting maven. Run below in url-monitoring-extension directory mvn clean install
Go into the target directory and copy the UrlMonitor-2.2.1.zip, Afterwards unzip the content inside <MA-Home>/monitors/folder cd target/
mv UrlMonitor-2.2.1.zip /opt/appdynamics/machine-agent/monitors
unzip UrlMonitor-2.2.1.zip
This will create an UrlMonitor directory inside the Monitors folder.
Monitor the URL
Inside the UrlMonitor folder, edit the config.yml file
Under sites, I have added: sites:
- name: AppDynamics
url: http://127.0.0.1:5000/api/data
username: user1
password: password123
authType: BASIC
Change: metricPrefix: "Custom Metrics|URL Monitor|"
Now, All you need to do is Start your Machine Agent again.
Afterward, you can see this URL monitor in your AppDynamics Controller.