Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


A simple script for pulling stats from beanstalk

 
Post new topic   Reply to topic    Cacti Forum Index -> Addons for Cacti
Author Message
portante



Joined: 23 Jan 2009
Posts: 3

PostPosted: Sun Nov 22, 2009 10:58 pm    Post subject: A simple script for pulling stats from beanstalk Reply with quote

A simple script for pulling stats from beanstalk. Cacti graphs to come later.

Code:

#!/usr/bin/python

from telnetlib import Telnet
from optparse import OptionParser

DEF_PORT = "11300"

parser = OptionParser(usage="usage: %prog [-h] [-p PORT] HOSTNAME ...\nTotals will be returned for multiple HOSTNAME arguments.")
parser.set_defaults(port=DEF_PORT)
parser.add_option("-p", "--port", dest="port", metavar="PORT",
                  help="default beanstalkd port [default: %s]" % DEF_PORT)
(options, args) = parser.parse_args()
if not args:
    parser.error("Ah, we need a host to pull stats from...")
    sys.exit(1)

tn = Telnet(args[0], int(options.port))
tn.write("stats" + "\r\n")
stuff = tn.read_until("OK 860\r\n---\n", 2)
if not stuff:
    print "Unable to parse response"
    exit

output = ""
while True:
    stuff = tn.read_until("\n", 2)
    if stuff:
   if stuff == "\r\n":
            break
   stuff = stuff[:len(stuff)-1]
   stuff = stuff.split(':')
        if output:
            output += " "
        output += stuff[0] + ":" + stuff[1].strip()
    else:
        break

print output
Back to top
Linegod
Developer


Joined: 20 Feb 2003
Posts: 950
Location: Canada

PostPosted: Sun Jan 10, 2010 11:07 am    Post subject: Reply with quote

If you get a chance, please post this to the Scripts area of the Documentation site:

http://docs.cacti.net/scripts
http://docs.cacti.net/scripts.guidelines
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Addons for Cacti All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group