[Twisted-Python] Custom app using twisted
Don't know if this belongs on the list or not... I've just written a python monitoring program for baby-sitting a bunch of servers (I wanted something easier to setup and maintain than Nagios)... but the inevitable has happened, and I want to make a go-cart run like a ferrari. I was thinking of using python's interface to 'select' a la Medusa, but as soon as I saw 'import asyncore', I thought "There's got to be a better way..." Enter twisted. I would like to be able to run n monitoring instances simultaneously (thus my interest in 'select') to make the code as close to real-time as is practical. However, this is my first dive into POSIX I/O at this level (I ordered a copy of "UNIX Systems Programming" (Robbins) yesterday, to help me learn and adjust). * The monitoring libs that I've put together do everything from local process monitoring (crap like ps with commands.getoutput), httplib checks against sites, process checks on remote servers (ssh+ps with commands.getoutput), ping checks, etc. * An instance of the monitoring class will only do one type of monitoring (either process check, remote process check, ping check, or site check) I would like to write a version of this that's a twisted application, in the hopes that it will be more robust and enterprise-ready. I've started looking at the following: twisted.application.service.IProcess twisted.application.service.Process and spawnProcess from twisted.internet.default.PosixReactorBase But I am not sure how to get started yet... I want to write something that can be run with twistd. Can anyone offer guidance or suggestions as to the approach? Right now, I am locked on the example here: http://twistedmatrix.com/documents/current/howto/application.html ... Is this what I should be looking at for inspiration? Or another approach all together? I've not come across examples of twisted apps that are a narrow specialization like what I have in mind... the app would be a *kind* of server... that would regularly spawn processes and wait for return data, regularly instantiate python monitoring classes. Am I thinking of this in a sane way? Thanks for any input, Duncan -- Duncan M. McGreggor mailto:duncan@adytum.us Systems & p 301.698.5032 Applications Engineer http://adytum.us AdytumSolutions, Inc.
Duncan, Looks like we're in the same boat--this is my third day looking at Twisted. My approach is to skim the doc and read some code, sleep on it, then do it all again but a bit more carefully. And yes, my head hurts. ;-) But I have enjoyed reading the reactor code. My only question there is if anyone is considering using heapq instead of insort, as heapq is really the algorithm of choice for processing dynamicly changing lists in order. So while my head really hurts, at least I'm enjoying the code. And its a nice break from reading the docs, too. Bill Duncan McGreggor <python@adytumsolutions.com> wrote: But I am not sure how to get started yet... I want to write something that can be run with twistd. Can anyone offer guidance or suggestions as to the approach? Right now, I am locked on the example here: http://twistedmatrix.com/documents/current/howto/application.html ... Yahoo! India Matrimony: Find your partner online.
On May 15, 2004, at 1:17 AM, Duncan McGreggor wrote:
But I am not sure how to get started yet... I want to write something that can be run with twistd. Can anyone offer guidance or suggestions as to the approach? Right now, I am locked on the example here: http://twistedmatrix.com/documents/current/howto/application.html ... Is this what I should be looking at for inspiration? Or another approach all together? I've not come across examples of twisted apps that are a narrow specialization like what I have in mind... the app would be a *kind* of server... that would regularly spawn processes and wait for return data, regularly instantiate python monitoring classes.
In case any other twisted newbies are interested in learning to apply twisted in a similar manner, I am sharing a link I found the other day: http://www.onlamp.com/pub/a/python/2004/02/12/advanced_nio.html?page=3 Though this example doesn't use twisted.application or the plug-in method (both of which I am exploring, and will use), it's code has given me ideas on how to proceed. It's simplicity and conceptual similarity to what I am doing is just what I needed :-)
participants (2)
-
Bill la Forge
-
Duncan McGreggor