-
Notifications
You must be signed in to change notification settings - Fork 129
/
weatherExample.py
23 lines (21 loc) · 1.14 KB
/
weatherExample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''
____ __ ____
/ __ \____ _/ /_____ _/ __ \____ ____ _
/ / / / __ `/ __/ __ `/ / / / __ \/ __ `/
/ /_/ / /_/ / /_/ /_/ / /_/ / /_/ / /_/ /
/_____/\__,_/\__/\__,_/_____/\____/\__, /
/____/
'''
import requests
import time
from checks import AgentCheck
import json
class cgmChecker(AgentCheck):
def check(self, instance):
r = requests.get('http://api.wunderground.com/api/<<APIKEYGOESHERE>>/conditions/q/CO/Broomfield.json') #Replace w/ your API key
if r.status_code == requests.codes.ok: #ensure API response is sucessful (200)
response = r.json() #set JSON response to response variable
temp_f = response["current_observation"]["temp_f"] #iterate through API response and set custom metrics
wind_mph = response["current_observation"]["wind_mph"] #iterate through API response and set custom metrics
self.gauge('temp_f_broomfield', temp_f, tags=['weather_check']) #Pass the metric to the Datadog agent
self.gauge('wind_mph_broomfield', wind_mph, tags=['weather_check']) #Pass the metric to the Datadog agent