Created
November 7, 2022 14:40
-
-
Save labbati/307e752656c18f5e60bde32e9657d002 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datadog import initialize, statsd | |
import datetime | |
import time | |
import random | |
ENV = "demo" | |
SERVICE = "inventory-api" | |
# Was not able to get it to work from MAC to containerized agent | |
initialize(statsd_host='agent', statsd_port=8125) | |
plugins = ('commentor', 'ssl_prot', 'anti_span', | |
'in_page_search', 'cors_filter') | |
durations = (0.7, 0.3, 0.1, 0.9, 0.1) | |
resources = ('GET /', 'GET /some-page', 'POST /comment') | |
while (1): | |
number_of_plugins = random.randint(0, 4) | |
print("{} Sending metrics...".format(datetime.datetime.now().isoformat())) | |
for i in range(number_of_plugins): | |
plugin = plugins[i] | |
resource = resources[random.randint(0, 2)] | |
duration = random.random() * durations[i] | |
status_code = 200 if random.randint(1, 10) > 1 else 400 | |
statsd.gauge('wordpress.plugin.duration', duration, tags=[ | |
"environment:{}".format(ENV), "service:{}".format(SERVICE), "resource_name:{}".format(resource), "http.status_code:{}".format(status_code), "wp_plugin:{}".format(plugin)]) | |
print("{} Waiting...".format(datetime.datetime.now().isoformat())) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment