Apr 10 2008
Linux system monitoring with Twitter.
Here is a little script I wrote to update twitter with server status infomation.
this is not trying to replace Nagios or more advanced server monitoring tools, but if you want to track your own personal server and want a cool hack you can use this script and tweak it.
Please if you do some cool updates could you email it to imrobotmaker@yahoo.com
Thanks
—cut below here —-
#!/bin/bash
#
# twitter-stats Script to update Twitter with server stats
#
# Author: By Marco Penguin
# Purpose --- See Below
# We will be using curl to send updates to twitter.
# With this example here will send reports for SSH Connections, Disk Space and Server Load
# You can modify this script to send other cool stuff you want to track
#
# Warning: You should protect your updates on twitter unless you want to make this info public
#
# Things you want to change TUSERNAME "Your twitter username" TPASSWD "Your Twitter Password"
# Add this script to your cronjobs or put it on your /etc/cron.hourly to run every hour
# or /etc/cron.daily to run it only once a day.
### Some Twitter Variables
TUSERNAME="your_twitter__username"
TPASSWD="your_twitter_password"
### Stuff We Want to track #####
SSHNET=$( netstat | grep "ssh" | tr -s ' ' | cut -d: -f2 )
DISKSPACE=$( df -h | tr -s ' ' | grep -e hda -e hdb | cut -d' ' -f1,4 | sed "s/\/dev\//hardrive /g" | sed "s/$/ remaining space/g" )
LOAD=$( uptime | tr -s ' ' | cut -d' ' -f9-14 | sed "s/[:,]//g” )
### Path to Curl #########
CURL=”/usr/bin/curl”
######### Update Twitter Information #########
### Send Disk Space Info to twitter ########
$CURL -s -u $TUSERNAME:$TPASSWD -d status=”$DISKSPACE” http://twitter.com/statuses/update.xml > /dev/null
##### Send Server Load Status to Twitter ######
$CURL -s -u $TUSERNAME:$TPASSWD -d status=”$LOAD” http://twitter.com/statuses/update.xml > /dev/null
### Send Remote SSH connections status ######
$CURL -s -u $TUSERNAME:$TPASSWD -d status=”Remote SSH connections $SSHNET” http://twitter.com/statuses/update.xml > /dev/null
—end of code—-
You can download the full script here.
http://penguincares.no-ip.org:9090/twitter-stats.txt
