Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Created January 5, 2013 21:00
Show Gist options
  • Save thefinn93/4463630 to your computer and use it in GitHub Desktop.
Save thefinn93/4463630 to your computer and use it in GitHub Desktop.

Graphs the number of active users on a subreddit. I just wrote this. You need add a list of subreddits you want graphed to your munin-node file (on debian/ubuntu it's in /etc/munin/plugin-conf.d/munin-node, probably other places on other distros), like such:

[reddit-usersonsub]
env.subs AdviceANimals,announcements,AskREddit,atheism,aww,bestof,blog,funny,gaming,IAmA,movies,Music,pics,politics,science,technology,todayilearned,videos,worldnews,WTF
#!/usr/bin/env python
import requests
import os,sys
try:
subs = os.getenv("subs").split(",")
except:
sys.exit(1)
config = False
if len(sys.argv) > 1:
if sys.argv[1] == "config":
config = True
if config:
print "graph_title Subreddit Users Online"
print "graph_vlabel users"
print "graph_category reddit"
for sub in subs:
if config:
print sub + ".label Users on /r/" + sub
else:
data = requests.get("http://www.reddit.com/r/" + sub + "/about.json")
print sub + ".value " + str(data.json()['data']['accounts_active'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment