How do you know when you need a new water heater?
For starters, check for leaks. A hot water heater that can't consistently heat water is likely either a) leaking or b) has a faulty heating element. 

Hot water heaters typically have a 10 year lifespan. There should be a date somewhere on the tank. If you're handy with electrical (or gas) and plumbing, it's not a big deal to swap out. If you're not, you'll want to bring in a plumber. 

If you do want to bring in a plumber, then hire one BEFORE the heater springs a major leak. Emergency rates for a plumber are not fun. ;)

Note that all hot water heaters have something called a 'sacrificial anode' that you can replace regularly to extend the life of the tank. It's a rod of metal that will corrode saving the tank, itself. That said, very few replace them...even people like me, that know I should. ;) But it is a relatively cheap way to extend the life of the tank.