Last active
November 23, 2017 00:41
-
-
Save Sam-Martin/bd69686df7df67ea5d92b8464a6fa03b to your computer and use it in GitHub Desktop.
Sam's Server's Datadog Sensors
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 subprocess import check_output | |
from datadog import statsd | |
from datadog.api.constants import CheckStatus | |
import requests | |
import re | |
zpool_status = check_output(["/sbin/zpool", "status"]) | |
pattern = re.compile('state: ONLINE') | |
if pattern.search(zpool_status) : | |
print "OK" | |
status = CheckStatus.OK | |
else: | |
print "NOT OK!" | |
status = CheckStatus.CRITICAL | |
statsd.service_check(check_name='zpool.status',status=status,message='Look at the status dummy') | |
# SabNzbd stats | |
r = requests.get('http://127.0.0.1:9090/sabnzbd/api?mode=queue&output=json&apikey=APIKEYHERE') | |
mb_left = int(float(r.json()['queue']['mbleft'])) * 1024 * 1024 | |
kb_per_sec = r.json()['queue']['kbpersec'] | |
statsd.gauge('sabnzbd.mbleft',mb_left) | |
print(str(mb_left) + " KB left in SABnzbd queue") | |
statsd.gauge('sabnzbd.kbpersec',kb_per_sec) | |
print(str(kb_per_sec) + ' kb/sec SABnzbd queue') | |
# Sonarr stats | |
r = requests.get('http://127.0.0.1:8989/api/series?apikey=APIKEYHERE').json() | |
total_episodes = sum(map(lambda x: int(x['episodeFileCount']),r)) | |
print str(total_episodes) + " episodes on disk" | |
statsd.gauge('sonarr.episodesondisk',total_episodes) | |
# Radarr stats | |
r = requests.get('http://127.0.0.1:7878/api/movie?apikey=APIKEYHERE').json() | |
total_movies = len(r) | |
print str(total_movies) + " movies" | |
statsd.gauge('radarr.moviesondisk',total_movies) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment