window.location = window.location
Tuesday, March 24, 2009
Refresh a page using Javascript
Courtesy of the great Panda, here's how to refresh a page using javascript. It's one of those things that makes sense once you see it, but that I doubt I would have guessed had I needed it.
Tuesday, March 17, 2009
Creating a Shared Context for Monitoring the Health of an Application
As part of my vital signs project, I'm building a framework for monitoring the health of an application based on various ways of 'taking its temperature'. Each vital sign will measure something specific (drive space left on the server, database requests per second, etc.).
The point of this project is to quickly give any viewer an idea of the health of the system. I mean any viewer. If the Grand Poobah in charge of Water Buffalo stops by, I want the new intern to be able to bring the VIP up to speed on the results immediately.
Unfortunately, raw data requires too much context. Hard drive space is bad below 50,000 and db requests per second are bad above 150, and there are 10, 100 or 1000 metrics with different thresholds. While we do need to collect all this very disparate raw data, we must display results in that are simple and uniform.
By convention, we'll report all results on a scale from 0 to 100:
100 => Optimal
75 .. 99 => Acceptable
50 .. 74 => Check Engine
25 .. 49 => Warning Will Robinson!
01 .. 24 => Critical
00 => Down
If a VP passes looks up at the 42-inch monitor in his office (which flashes charts and ... whatever ... ) and notices that db requests per second is at 30, I want that person to pick up the phone, call me, and say, "Hey, something's wrong." This is way better than hearing, "How could you let this happen? And why is 30,000 requests per second a problem, anyway?"
Hopefully the end result will look something like this:
* Overall Health is Prominent (and uses Shared Context)
* Nested Data uses Shared Context for Results
* Color Coded for Additional Context
* I would also like to see Spark Lines for historical context.
APPLICATION HEALTH:
70/100
84 Drive Space
92 DB Requests per Second
52 HTTP Request Time
64 Longest Running DB Request
Thursday, March 12, 2009
Ruby Hash constructor -- useful, unintuitive
I've been confused in the past about the behavior of Ruby's Hash constructor. Now that I've looked at the documentation, I have to say I think it violates the principle of least surprise.
A default hash returns nil any time you access a key with no set value. The default value can be changed through the constructor. This can be useful when you want to do something like this...
>> brownie_points = {}=> {}>> brownie_points[:zack] += 2NoMethodError: undefined method `+' for nil:NilClass>> brownie_points.default=> nil
>> brownie_points = Hash.new(0)=> {}>> brownie_points.default=> 0>> brownie_points[:zack] += 3=> 5>> brownie_points[:sam]=> 0
We can all agree that this is useful. Moreover, developers will rarely use the constructor, because the ruby language construct {} is so much more elegant. I just don't see myself doing a lot of this...
attributes = {:key_one => :value_one}Hash.new(attributes)
That being said, the prime directive isn't we aren't using that method let's do something with it. It's the principle of least suprise. Not only that, but it violates a pretty universal convention in all of OO that objects' constructors will accept values that make up their initial state. Instead, it accepts the value to return when you ask for something outside it's current state.
To work around this problem, ruby includes a class-level method [].
>> Hash[:frank => 'friendly', :zack => 'here let me thread that for you', :panda => :zen]=> {:zack=>"here let me thread that for you", :frank=>"friendly", :panda => :zen}
Fortunately most programmers will never run in to this issue because of the {} construct, which is more fun anyway.
Subscribe to:
Posts (Atom)