Archive for the ‘Linux’ Category
The morning session I attended was “Python in 3 hours”, which provided excellent coverage of Python for folks who may never have seen it before. Steve Holden, being more qualified than most to present this material, did a stellar job of not only presenting the material, but also addressing questions coming from the attendees.
Steve’s talk is fantastic, but I really wish there was an introductory talk for folks who were coming in with the question “Why Python?”. Steve’s talk assumes interest in the language, and that’s completely fair, but I brought a buddy who I think was looking more for the “why” than the “how”. Of course I try to evangelise the language where I can, but to be honest, I’m not as good a salesperson for Python as I wish I was. I use Python for all of my sysadmin tasks these days and love it, but I already hated the other languages I was using, so I guess I just wasn’t a very hard sell. ![]()
I got an early start. Too early. But I’m from the west coast, so my body thinks I slept in. I wandered around a bit, took a few pics which you can see at my Flickr OSCON set, and I discovered a couple of things that might be of interest:
- The starbucks in the conference center charges over $2 for a small cup of joe. There’s a starbucks right across the street (you can see it from the breakfast area - seriously, it’s 5 seconds away), and they charge less than $2 for a medium (grande). That’s less than I pay at home.
- The ATM outside the starbucks charges $3 for cash. I’ll report back when I find a cheaper one, but most places seem to take plastic here.
- Every computer involved in this conference, from registration to the video screens that dot the common areas, are running Windows XP. Just sayin’.
- The light rail system is free to go just about anywhere except for the airport, so there’s no excuse not to get out and see Portland and take in the food and beer and stuff.
- For beer-lovers, not only is there the Oregon Brewers Festival starting at the tail end of this conference, but there’s apparently another festival that we missed *last* weekend!! Keep that in mind when you’re planning to come to OSCON next year.
If you’re attending the 10th Annual Open Source Convention, I’ve compiled just a few tips for you on this, “day 0″ of the event:
- Don’t check bags. Everything is slower if you check bags, and if you’re packing more than three shirts, you’re crazy, because if history is any indicator, you’re going to be bombarded with shirts over the course of the week. One maximum size (22″ x 14″ + 9″) suitcase, and a bookbag with a laptop pocket is all I brought, and I’m confident I’ll have all I need. I’ll report back if things change
- Request a room away from the ice machine. They can be loud. This year my room is the last room at the end of a long hallway. Ahhhhhhhh….
- Don’t bring toiletries of any kind: you can’t bring a lot of them on board, and I’d rather just avoid it altogether and buy stuff when I get to my destination. Don’t use the Hotel store though - there’s a Dollar store about 2 blocks from the Lloyd Center Doubletree Hotel (on the back end of the Lloyd Center mall), and they probably have everything you’ll need. If not, walk another block north to the Safeway, and you can get anything, though I didn’t find any travel-sized stuff.
- Show up to registration early: I’m leaving shortly for registration. Registration moves pretty quickly even if you go on Monday morning, but on Sunday night (from 5-7pm) there’s a nice, jovial, laid-back mood around the registration areas.
- When you’re in Portland, know that you’re in an area that is something of a mecca for beer. Even if you don’t like beer, I urge you to join friends and at least have a look at the beers available. You’re in an area where even the hotel bar has an ok beer selection. Saying you don’t like beer is like saying you don’t like food. If “beer” to you means Coors Light (or similar), you have no idea what beer is - but that’s ok, because you’re now in a place that can grant you a PhD in beer snobbery in a matter of a weekend. Really. Take advantage of it!! (a hint: many people who “don’t like beer” really just don’t like the bitterness that comes from hops. Ask a bartender for a sample of their finest wheat beer. I’ll bet you’ll be hooked).
- Don’t stay in your hotel room if you can help it. Engage. Look at the whiteboard that is probably in the registration area as I type this. Find the conference web site, irc channels, wikis, and everything else that you can. 75% of the value of coming to OSCON is finding and meeting people you’ll be in contact with well after you leave. It’s a commercial conference, yes — but it’s a community atmosphere.
- Plan your day. You can try to plan everything you’re going to attend before you get here, but it probably won’t work very well, because you’ll inevitably hear someone talking about something else and decide to attend that instead. What might work better is if you try to plan the night before — but not after the parties — probably sometime between the last session of the day and dinner. At least have an idea what you’re doing the next day, because parsing the program on-the-fly is, imho, difficult, especially when ten people you know walk by and say hi and stuff.
- Try to plan lunch in the city. This can be a little difficult, but you can hop on the light rail for free as soon as the conference breaks for lunch, and be downtown in no time. Last time I attended, I only made it out for two lunches downtown, and I’m kind of a foodie, so I would’ve liked to sample more of the local faire. Try to keep away from the chains (you can get that at home) and be adventurous!!
I’m working on a new project that will be open sourced if I can ever get it to be generically useful. It’s called “sarviz”, and it’s a visualization tool for output from the “sar” UNIX system reporting utility. I know tools like this exist, but please read on, as I’m looking to do something a bit different from what I’ve seen.
A quick, simple explanation of sar
System administrators typically run sar as a cron job, and each day sar will generate a report that lists the values of various system counters for a specified time interval throughout the day. So you end up with a text file that lists, for example, the cpu iowait value every 10 minutes throughout the day. There are maybe a dozen different categories of counters enabled by default, and more that aren’t (like disk-related counters). Anyway, you wind up with a text file that looks something like this:
23:30:01         CPU    %user    %nice  %system  %iowait   %steal    %idle
23:40:02         all     0.32     0.00     0.32     6.57     0.49    92.29
23:40:02Â Â Â Â Â Â Â Â Â Â Â 0Â Â Â Â Â 0.32Â Â Â Â Â 0.00Â Â Â Â Â 0.32Â Â Â Â Â 6.57Â Â Â Â Â 0.49Â Â Â Â 92.29
23:50:01         all     0.74     0.00     0.82     7.14     0.55    90.76
23:50:01Â Â Â Â Â Â Â Â Â Â Â 0Â Â Â Â Â 0.74Â Â Â Â Â 0.00Â Â Â Â Â 0.82Â Â Â Â Â 7.14Â Â Â Â Â 0.55Â Â Â Â 90.76
Average:         all     0.82     0.00     0.72    13.54     0.78    84.14
Average:Â Â Â Â Â Â Â Â Â Â Â 0Â Â Â Â Â 0.82Â Â Â Â Â 0.00Â Â Â Â Â 0.72Â Â Â Â 13.54Â Â Â Â Â 0.78Â Â Â Â 84.14
This is just a small part of one section of the file (this box has only one cpu, which is why the ‘all’ and ‘0′ numbers are the same, btw). The whole file on one server, running with default configurations, is 4000 lines long.
There’s a ton of great information in here, but… it all looks like the above. There’s no graphical output to be had. This is bad, because it would be nice to use this (historical) monitoring output for things like capacity planning, problem tracking, etc. You would, of course, want to couple this type of monitoring with something else that’ll do real-time monitoring, alerts, dependencies, escalation, etc.
So I want to write an application that’ll generate graphs of all of this stuff. Furthermore, I thought it would be cool to do something like what planetplanet does, which is to say that I want sarviz to run as a cron job, parse all of this stuff, and generate static html files, with an index.html that’ll make it really easy to browse this information either by host, by date, by resource… whatever. Later on I can add features to actually do even more useful stuff like longer-term trending of resource usage (by aggregating across various ’sar’ output files), and more.
Sar is not alone
Sar comes with some friends, and it turns out they can be extremely useful. The best one for my purposes here is called ’sadf’, and it is used to basically format the sar output to make it more useful for programmatic processing. It can output the information in CSV format, or make it ready for insertion into a relational database, but what I’m currently using for sarviz (and it’s early, so this could change) is the XML output capability. With XML output, I won’t have to deal with parsing out column headers, scanning an entire file for information from a single sar run, dealing with the blank lines sar uses by default to make it easier to read on a console, etc. So with sadf I can get output that looks like this:
<timestamp date=”2008-06-15″ time=”07:10:01″ interval=”600″>
<processes per=”second” proc=”0.93″/>
<context-switch per=”second” cswch=”221.50″/>
<cpu-load>
<cpu number=”all” user=”1.77″ nice=”0.00″ system=”0.56″ iowait=”0.04″ steal=”0.08″ idle=”97.55″/>
<cpu number=”0″ user=”1.77″ nice=”0.00″ system=”0.56″ iowait=”0.04″ steal=”0.08″ idle=”97.55″/>
</cpu-load> ….
This is a bit nicer to deal with, and I was excited to use Python’s (now built-in) ElementTree module to do something from scratch after having dealt with it being somewhat abstracted in the Python tools for the GData API (which I used to write a command line client for Google Spreadsheets, for example).
Doing Simple Things with ElementTree
Well, as it turns out, I had kind of a hard time getting started doing what I thought were simple things with ElementTree, so I want to post a few examples of how I did them so that I and others have something to refer to online.
The first thing to know about ElementTree is that there are Element objects, and ElementTree objects. ElementTree objects are made up of a hierarchical collection of Element objects, and Element objects are the things you can actually get attributes from that you’re likely to want. For whatever reason, I was a little confused starting out, because I wanted to get an ElementTree object and then ask that object to “scan the tree and give me all of the “time” attributes of the “timestamp” elements in the tree. You might be able to do this with a one-liner, but I never found a document that said how.
So here’s how to load in an XML file, parse it, and return all of the timestamp elements in that tree (or, rather, this is how I did it, which seems reasonable):
strudel:sa jonesy$ python
Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from xml.etree import ElementTree as ET
>>> tree = ET.parse(”sa15.xml”)
>>> for ts in tree.findall(”host/statistics/timestamp”):
…Â Â Â Â Â Â Â isotime = ts.attrib["date"]+”T”+ts.attrib["time"]
…Â Â Â Â Â Â Â print isotime
2008-06-16T05:00:01
2008-06-16T05:10:01
2008-06-16T05:20:01
2008-06-16T05:30:01
2008-06-16T05:40:01
2008-06-16T05:50:01
2008-06-16T06:00:01
2008-06-16T06:10:01
2008-06-16T06:20:01
2008-06-16T06:30:01
2008-06-16T06:40:01
2008-06-16T06:50:01
….
So, I imported the ElementTree module, fed my xml file to a method called “parse()”, and that gives me an ElementTree object. In that tree, I then ask for the timestamp elements which are under the root element at “host/statistics/timestamp”. You can then see that I create an ISO8601-formatted timestamp by asking for the “date” and “time” attributes of the timestamp element, and put a “T” between them. I would’ve used something like “T”.join, but there are other attributes in that element, and I only needed two, so I took the easy way out here instead of creating a list first and then doing the join on the list.
Of course, my real interest in the timestamps isn’t to print them, but to get the statistics for each sar run (represented by a timestamp, since sar records statistics for regular time intervals). So now let’s grab the 1-, 5-, and 15-minute load averages according to sar. I want all of this printed on one line along with the timestamp, because this output is going to be graphed using Timeplot, and that’s how Timeplot wants the data. Here goes:
>>>for ts in tree.findall("host/statistics/timestamp"):
...       isotime = ts.attrib["date"] + “T” + ts.attrib["time"]
…Â Â Â Â Â Â Â for q in ts.findall(”queue”):
…Â Â Â Â Â Â Â Â Â Â Â Â qstat = [isotime, q.attrib["ldavg-1"], q.attrib["ldavg-5"], q.attrib["ldavg-15"]]
…Â Â Â Â Â Â Â Â Â Â Â Â print “,”.join(qstat)
2008-06-16T05:10:01,0.05,0.12,0.09
2008-06-16T05:20:01,0.03,0.06,0.07
2008-06-16T05:30:01,0.02,0.02,0.03
2008-06-16T05:40:01,0.02,0.06,0.03
2008-06-16T05:50:01,0.03,0.06,0.03
2008-06-16T06:00:01,0.04,0.03,0.00
2008-06-16T06:10:01,0.02,0.06,0.03
2008-06-16T06:20:01,0.06,0.10,0.04
2008-06-16T06:30:01,0.13,0.11,0.06
2008-06-16T06:40:01,0.16,0.12,0.08
2008-06-16T06:50:01,0.04,0.06,0.06
The thing to note here, in case it escaped your eyeball, is that the second call to ‘findall’ feeds an argument relative to the ‘ts’ object rather than the ‘tree’ object.
This data is ready for Timeplot, and now it’s just a matter of somehow generating the files with the appropriate HTML and JavaScript in them to present the information. I have absolutely no clue how to easily use dynamic variables from Python to easily generate static HTML and JavaScript, so what I have in that area of my code is not something I want to share, out of sheer embarrasment. If someone has done that, let me know. PlanetPlanet does not output JavaScript, best I can tell, but it does output HTML, so I’ll be checking that part of the code out (probably uses BeautifulSoup I guess?). Input on that is hereby solicited!
Ah, the lazyweb. Today, I’m putting together content for a class I’m teaching on basic Linux administration, but during my meeting with a group of trainees to determine the scope of the course, they requested that I completely skip any coverage of “perl -e” one-liners, and show them the Python equivalents. Of course, I found this page, which has a few, but I figured I’d put out the call for more, just to get a good collection of ideas, and a higher-level idea of how people are using Python for system administration for ‘quick-n-dirty’ jobs. If I get a bunch of interesting ones, I’ll collect them all somewhere for easy reference (or add them to the wiki linked above?), so link this callout wherever pythonistas can be found.
Oddly enough, my experience with Python has me going in the completely opposite direction: I don’t write as many one-liners as I did with perl. If it’s not obvious to me how to do something with sed, awk, grep, find, xargs, and the “regular” tools, I write a Python script. I’ve tried remembering some things I used nasty Perl one-liners for, but I guess they were sufficiently nasty that I’ve forgotten them.
By the way, if you’re a sysadmin who writes their tools using Python, do consider giving a talk at this year’s PyWorks conference in November!
Having a Google account is sometimes useful in ways you hadn’t planned for. For example, at a few different employers I’ve been at, I’ve had to prepare for reviews by providing a list of accomplishments to my supervisor. One decent tool for generating this list is email, though it can take some time. Another useful tool is the Web History feature of your Google account.
Though this isn’t necessarily indicative of everything I’ve accomplished in the first half of 2008 per se, it’s definitely indicative of the types of things I’ve generally been into so far this year, and it’s interesting to look back. What does your Web History say?
- Gearman - this is used by some rather large web sites, notably Digg. It reminds me a little of having Torque and Maui, but geared toward more general-purpose applications. In fact, it was never clear to me that PBS/Maui couldn’t actually do this, but I didn’t get far enough into Gearman to really say that authoritatively.
- How SimpleDB Differs from a Relational Database - Links off to some very useful takes on the “cloud” databases, which are truly fascinating creatures, but have a vastly different data management philosophy from the relational model we’re all used to.
- Reblog - I found this in the footer of someone’s blog post. It’s kinda neat, but to be honest, I think you can do similar stuff using the Flock browser.
- Google Finance APIs and Tools - did I ever mention that I had a Series 7 & 63 license two months after my 20th birthday? I love anything that I can think for very long periods of time about, where there’s lots and lots and LOTS of data to play with, where you can make correlations and answer questions nobody even thought to ask. Of course, soon after finding this page I found the actual Google Finance page, which answers an awful lot of potential questions. The stock screener is actually what I was looking to write myself, but with the data freely available, I’m sure it won’t be long before I find something else fun to do with it. I’m not a fan of Google’s “Feeds” model, but I’ve dealt with it before, and will do it again if it means getting at this data.
- Bitpusher - it was recommended to me as an alternative to traditional dedicated server hosting. Worth a look.
- S3 Firefox Organizer - This is a firefox plugin that provides an interface that looks a lot like an FTP GUI or something, but allows you to move files to and from “buckets” in Amazon’s S3 service.
- Boto - A python library for writing programs that interact with the various Amazon Web Services. It’s not particularly well-documented, and it has a few quirks, but it is useful.
- OmniGraffle - A Visio replacement for Apple OS X. I like it a lot better than Visio, actually. It has tons of contributed templates. You shouldn’t have any trouble making the switch. A little pricey, but I plunked down the cash, and have not been disappointed.
- The Python Queue Module according to Doug - Doug Hellmann’s Python Module of the Week (PyMOTW) should be published in dead tree form some day. I happen to have some code that could make better use of queuing if it were a) written in Python, and b) used the Queue module. I was a little put off by the fact that every single tutorial I found on this module assumed you wanted to use threading, which I actually don’t, because I’m not smart enough…. though the last person I told that to said something to the effect of “the fact that you believe that means you’re smart enough”. Heh.
- MySQL GROUP modifiers - turns out this isn’t what I needed for the problem I was trying to solve, but the “WITH ROLLUP” feature was new to me at the time I found it, and it’s kinda cool.
- Wordpress “Subscribe to Comments” plugin - Baron suggested that it would be good to have this, and I had honestly not even thought about it. But looking around, this is the only plugin of its kind that I found, and it’s only tested up to WP 2.3x, and I’m on 2.5x. This is precisely why I hate plugins (as an end user, anyway. Loghetti supports plugins)
- Lifeblogging - I had occasion to go back and flip through some of the volumes of journals I’ve kept since age 12, wondering if it might be time to digitize those in some form. I might digitize them, but they will *not* be public I don’t think. Way too embarrassing.
- ldapmodrdn - for a buddy who hasn’t yet found all of the openldap command line tools. You can’t use ‘ldapmodify’ (to my knowledge) to *rename* an entry.
- Django graphs - I haven’t yet tried this, because I’m still trying to learn Django in what little spare time I have, but it looks like there’s at least some effort towards this out there in the community. I have yet to see a newspaper that doesn’t have graphs *somewhere* (finance, sports, weather…), so I’m surprised Django doesn’t have something like this built-in.
- URL Decode UDF for MySQL - I’ve used this. It works really well.
- Erlang - hey, I’m game for anything. If I weren’t, I’d still be writing all of my code in Perl.
- The difference between %iowait in sar and %util in iostat - I use both tools, and wanted the clarification because I was writing some graphing code in Python (using Timeplot, which rocks, by the way), and stumbled upon the question. Google to the rescue!
- OSCON ‘08 - I’m going. Are you going? I’m also going to the Oregon Brewers Festival on the last day of OSCON, as I did in ‘06. Wonderful!
- Explosion at one of my hosting providers - didn’t affect me, but… wow!
- hypertable - *sigh* someday…when there’s time…
- Small-scale hydro power - Yeah, I’m kind of a DIYer at heart. I do some woodworking, all my own plumbing, painting, flooring, I brew my own beer, I cook, I collect rain in big barrels, power sprinklers using pool runoff to give my lawn a jumpstart in spring… that kind of stuff. One day I noticed water coming out of a downspout fast enough to leap over one of my rain barrels and thought there must be some way to harness that power. Sadly, there really isn’t, so I did some research. It’s non-trivial.
- You bet your garden - I also do my own gardening and related experiments.
- RightScale Demo - WATCH YOUR VOLUME - a screencast showing off RightScale’s features. Impressive considering the work it would take me, a lone admin, to set something like this up. The learning curve involved in effectively/efficiently managing/scaling/monitoring/troubleshooting EC2 is non-trivial.
- Homebrew Kegerator - Maybe if this startup is bought out I can actually afford this thing to put my homebrewed beer in. The 30-year-old spare fridge in the basement is getting a little… gamey.
- The pound proxy daemon - I use this. It works well enough, but I’ve crashed it under load, too. I’ve also had at least one hosting provider misconfigure it on my behalf, and I had to go and tell them how to fix it :-/
- Droid Sans Mono - a fantastic coding font. Installing this font is in my post-install routine for all of my desktops.
- Generator tricks for systems programmers - David Beazley has made available a lot of Python source code and presentation slides from what I imagine was a great talk (if you’re a systems guy, which I am).
- The Wide Finder Saga - I found this just as I was writing Loghetti. There are still some things in Mr. Lundh’s code that I haven’t implemented, but it was a fantastic lesson.
- Using gnu sort for IP addresses - I’ve used sort in a lot of different ways over the years… but not for IP addresses. This is a nice hack for pulling this off with sort, but it doesn’t scale very well when you have millions of them, due to the sort utility’s ‘divide and conquer’ method of sorting.
- Writing an Hadoop/MapReduce Program in Python - this got me over the hump.
- Notes on using EC2/S3 - This got me over some other small humps
- BeautifulSoup - found while searching for the canonical way to screen scrape with Python. I’d done it a million times in Perl, and you can do it with httplib and regex and stuff in Python if you want, but this way is at least a million times nicer.
Well, that’s a decent enough summary I guess. As you can see, I’ve been doing a good bit of Python scripting. Most of my code these days is written in Python instead of Perl, in part because I was given the choice, and in part because Python fits my brain and makes me want to write more code, to push myself more. I’ve also been dealing with things involving “cloud” computing and “scalability” — like Hadoop, and EC2/S3. I haven’t done as much testing of the Google utility computing services, but I’ve used their various APIs for some things.
So what’s in your history?
I’ve been working with what I used to call “utility computing” tools for about 6-9 months. However, for about the past 2 months, I’ve been seeing the term “cloud computing” all over the place, and there is so much buzz surrounding it that it’s reaching that magical point best described using Alan Greenspan’s words: “Irrational Exuberance”.
When Alan Greenspan used those words to describe the attitudes of investors toward the markets, what he was basically saying was that there were people who didn’t really know what they were doing, putting more money than they ought, into things they knew relatively little about. Further, he was saying that the decisions people were making with regards to where to put their money were a) bad, or at least b) not based on sound reasoning, or the ‘facts on the ground’.
This, I think, is where we are at with “cloud computing”. The blog post that put me over the edge is this one, for the record. I read Sean’s writings often enough, but this one strikes me as being a little off, a little sensationalistic, not based in reality, and a little misleading.
Maybe he just didn’t put enough qualifiers in there. His post might make more sense if he limited its scope and provided more facts, but I guess it’s just an opinion piece so he decided not to go that route, and that’s his prerogative I guess.
By limiting the scope, I mean he should’ve realized that there are millions of web sites currently scaling quite nicely without the use of cloud computing. In addition, some of the new ones that are having issues are also not using cloud computing, and when they hit bumps in the road, they make it through, and the great thing is that they also share their stories, and those stories indicate that a cloud (or, the current cloud offerings) wouldn’t have helped much (there’s lots of other evidence of that too). What would’ve helped is if they had paid more attention to:
- monitoring
- initial infrastructure design
- their own app code and app design
I was writing a utility in Python (using boto) to test/play with Amazon’s SQS service. As boto isn’t particularly well documented where SQS specifically is concerned, I also plan to post some examples (either here or on Linuxlaboratory.org, or both). When I had some trouble getting a message that was sent to a queue, I went to the Amazon documentation, and found this little gem in the Amazon Web Services FAQ
I am sure that my queue has messages, but a call to ReceiveMessage returned none. What could be the problem?
Due to the distributed nature of the queue, a weighted random set of machines is sampled on a ReceiveMessage call. That means only the messages on the sampled machines are returned. If the number of messages in the queue is small (less than 1000), it is likely you will get fewer messages than you requested. If the number of messages in the queue is extremely small, you might not receive any messages in a particular ReceiveMessage response. Your application should be prepared to poll the queue until a message is received. Note that with the 2008-01-01 version of Amazon SQS, you’re charged for each request you make, so set your polling frequency with that in mind.
So… if you were planning to decouple application components using SQS using an ‘eventual consistency’ model, keep in mind that they’re using the same model, and that they’re charging you for the privilege of eventually getting the messages you’ve already paid to put there, but aren’t necessarily available at any given point in time. I personally think this is a little goofy, and wrong.
If I put a message in a queue, I should be charged for actually getting the message. I should *not* be charged for checking to see if Amazon’s internal workings have made my messages available to me yet.
What if you’re a sysadmin that supports a large development community, or a large systems research facility, or something else that requires you to provision systems that, perhaps, *aren’t* cookie-cutter machines? A lot of different solutions actually exist for doing this, with varying degrees of complexity and usefulness. However, in order to give people the highest level of flexibility without making your own life onerous, why not run your own EC2-like cloud?
If you’ve ever used the ROCKS beowulf cluster OS, you know how easy it can be to get a fully-functioning cluster installed in a matter of just a couple of hours, or perhaps even minutes (assuming the hardware is there and working and connected and all of that). If you don’t know, trust me, it’s easy. Really easy. If you’ve installed a linux distro from a CD, you can install a cluster with ROCKS, I promise.
Taking that a step further, Eucalyptus allows you to take your ROCKS cluster and make it into an EC2-like compute cloud. It installs as a ROCKS “roll”.
