My G3 iMac is 14 years old.
I have other Macs twice that old, and portables that have been handled a hundred or more times by airport security. I have dropped and dented them, I have had to replace a couple of optical drives (they're cheap), completely worn out several mice (ditto), but none of my Macs have ever completely died.
I'm wondering how often you should by a new imac computer.
By a new Mac when the one you have no longer does what you need it to do.
The shortest life from any Mac we have (and that is about 18 in a family of five) was 5.5 years for a Macbook Pro, whose particiular model had a bad video chipset component sold to Apple by another firm. Affected a lot of Mac notebooks but also other brands.
We have replaced most of our Macs because they were older PowerPC (pre-2006) models and were no longer supported by software we needed to run, typically tax and bookkeeping programs.