Skip to content

Instantly share code, notes, and snippets.

@yvmarques
Created June 8, 2012 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yvmarques/2894294 to your computer and use it in GitHub Desktop.
Save yvmarques/2894294 to your computer and use it in GitHub Desktop.
Tweet stats from your server
#!/usr/bin/env python
import tweepy
import commands
import time
# Fill these informations from you Twitter App Admin
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
while(True):
connections = commands.getoutput("""echo `netstat -an|wc -l`""")
memory = commands.getoutput("""free -t -m | grep "Total" | awk '{print "Used : "$3" MB Free : "$4" MB";}'""")
load = commands.getoutput("""uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f1""")
disks = commands.getoutput("""df -h | grep "dev/" | awk '{print "Disk : "$1" Used : "$5;}'""")
api.update_status("Load : %s | Connections : %s | Memory : %s | %s", (
load,
connections,
memory,
' | '.join(disks.split("\n"))
)
)
time.sleep(60*5) # Every five 5 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment