Simple rule I've discovered: When I find myself just mindlessly screwing around on the internet (manically surfing between reddit/hn/slashdot, for instance), I'll stop and go do something productive. Whether that's wash some dishes, brush my teeth, do a few Khan Academy math problems, fold some laundry, any activity which requires direct focus.
For me, it really helps me from spiraling into "holy crap, it's been an hour and I haven't done anything" mode.