datadog is a SaaS format server operation monitoring tool By sending each metric to datadog from various servers to be monitored Various analyzes can be performed on the browser.
datadog provides an agent that sends the resources of each server, the number of times the application is executed, and the TAT to datadog, but in this article, I made a script that keeps sending a specific value to datadog with python. I will try it.
I think there are many possible uses, such as sending the amount of data in a specific table in the database or sending the number of times a shell script is executed.
Use python3
I will try sending Metrics via the DogStats D server
pip3 install datadog
sample.py
import random
from datadog import initialize
from datadog import statsd
#First initialization
options = {
'statsd_host':'127.0.0.1',
'statsd_port':8125
}
initialize(**options)
#Create tag and value
tags = ['version:1', 'application:web']
value=random.randint(0, 100)
#metric set
metric="myapp.testdata.set"
statsd.set(metric, value, tags=tags)
#metric gauge
metric="myapp.testdata.gauge"
statsd.gauge(metric, value, tags=tags)
sample first half.py
options = {
'statsd_host':'127.0.0.1',
'statsd_port':8125
}
initialize(**options)
First is initialization. Specify the address and port of the DogStatsD server. The default is UDP: 8125.
Second half of sample.py
#Create tag and value
tags = ['version:1', 'application:web']
value=random.randint(0, 100)
#metric set
metric="myapp.testdata.set"
statsd.set(metric, value, tags=tags)
#metric gauge
metric="myapp.testdata.gauge"
statsd.gauge(metric, value, tags=tags)
You must use one of the following methods when submitting Metrics.
Method name | Commentary |
---|---|
set() | The number of times the method is called is sent |
gauge() | Send the value in the method |
Please choose according to your application. If you don't understand at first glance, we will explain it in the next section so that you can understand it sensuously.
The sample script calls both the set and gauge methods. Let's display the result of calling this script every minute with datadog.
Since the set method counts that it is called once a minute, the value 1 continues every minute, and the gauge method keeps sending random values (0 to 100). think.
--The set () method is used for the number of times the script is executed, etc. --The gauge () method is used to record changes in the amount of data, etc.
Wouldn't it be possible to visualize the data more if we could use it properly?
Recommended Posts