I wrote here last month about fooling around with Konfabulator, and I have been having a lot of fun with it. It really does remind me of working in BASIC all those years ago, with little programs that do cool stuff, and nary an MSDN browser session in sight. Working with Konfabulator reminds me of those days in other ways as well. Debugging facilities are pretty much limited to print statements, log messages, and alert boxes. You don’t have to be a programmer to enjoy Konfabulator. It is a compact program, trivial to install and set up, and comes with a bunch of cool widgets. Many more are available on the online gallery. But if you are a programmer then you can hardly use it for very long without making widgets of your own. True to form I couldn’t do a simple “Hello World” thing. Nope. I have a new computer built on AMD’s dual core Athlon XP processor, and I wanted a widget that monitored CPU loads for both cores. Why would you want to monitor CPU loads? Just because. I called my widget CPUSpy, and it looks like this:
If you have Konfabulator you can [download removed]. Once it is downloaded just double click the file to install it. You’ll need Windows XP, Server 2003, or Vista, for reasons I will detail below. Creating this widget turned out to be an interesting and sometimes frustrating exercise, for a couple of different reasons.
The first thing I had to do was create some images. I used to do a lot of this years ago, back when Paintshop Pro was shareware, but my skills were very rusty. The current standard for creating web graphics is Adobe’s Photoshop CS. This is an amazingly powerful program, with a suitably astronomic price tag: a full retail version costs more than $450. I started with Ulead’s Photoimpact. This product is priced in the $89 range, and you can download a fully-functional 30-day trial. The product has been evolving for more than ten years. It’s not as powerful as Photoshop, but it is powerful, and neither program is trivial to learn and use. Ultimately, though, PI’s clunky interface got the better of me. Fortunately there was a third choice, a cut-down version of the Adobe product called Photoshop Elements. Priced in the same range as Photoimpact, this is a slightly less powerful program with a much better user interface, and you can buy and download it (although there is no trial version). I think the widget turned out pretty well, and it actually looks better onscreen than the jpeg above would indicate. One of Konfabulator’s coolest features is it’s alpha-blended window and font transparency. If you install CPUSpy right click the widget after it starts running, and choose Widget Preferences from the context menu. In the Appearance tab you can play all aspects of the widget’s UI, including overall color scheme, transparency, and fonts. However, I have not yet mastered Photoshop to the point where I can reproduce the beautiful, glossy, fluid shapes of the widgets that Arlo Rose created for Konfabulator.
The first problem was to figure out how to get processor data. The first solution that came to mind was the Windows performance monitoring model. If you run perfmon.exe you can see this facility in action. Windows maintains a layer of objects that represent abstractions of the hardware, including a Processor object. One of the counter properties of the Processor object is Percent Processor Time. That was the one I needed to get the processor load. There are a couple of different ways to hook into this information. One is the pdh library, that should work on any Windows platform. Another is the Windows Management Instrumentation (WMI) high performance formatted data objects. These are only available on the platforms I mentioned above. Neverthless I decided to go this direction because the WMI has a COM automation layer that supports a low-overhead high-performance means of querying the hardware objects. Performance as important, because the performance monitoring object model is essentially stored in a database that you have to query using a SQL-like syntax called WML. Queries take significant amounts of time (a second or so), and using the WMI high performance objects you can query for the object you want, grab handles to the counters you want, and then just refresh them and read them from time to time. Much faster. Still, I may try to make a pdh version of this and see how it performs.
So that’s my first widget story. CPUSpy is now in version 1.1, and very complete I think. Hope you download it and give it a try. If you do, pass along your comments to me at firstname.lastname@example.org. I’m leaving this one behind for the moment, and have started on the next project: a widget to monitor TCP/IP connections visually. When I have one or two additional widgets done I may make a page to host them.