Only a mechanical inspection is likely to give you a definitive answer for why the AI tumbled, but typically it'll happen for one of two reasons: either the vacuum pump has decided to take a break, in which case the AI gyros slow down and will eventually no longer hold the instrument up, or you've exceeded the instrument's pitch and/or bank limits and caused it to tumble.
In the case of the former, there's not much you can do in a stock -172 about that. Section 3 in the PIM just tells to verify that the vacuum pump is operating with normal parameters (green arc is 4.5-5.5 in.hg). I've seen PA-28Rs with electric vacuum pumps that served as standbys to the engine-driven ones, but never seen one in a -172, not even as an STC mod. You could always try increasing the throttle; pumps in older aircraft will sometimes fail to perform as expected at lower throttle settings, but there's no guarantee there.
The latter case can happen during maneuvering flight if you exceed +/-30 degrees of pitch and 60 degrees of bank on a non-acrobatic AI. This can inadvertently happen when certain training maneuvers such as power-on or cross-controlled stalls are performed... enthusiastically. I've also seen tumbling occur during spin training. And then there was the Husky we used for banner-towing and which was pitched to 45 degrees on a regular basis during banner picks (waivers are wonderful things). The AI tumbled so regularly, the owner gave up on having mechanics reset it.
But yea, should this happen to you again, run any checklists that might exist on the topic (either directly concerned with the AI or with the vacuum pump system), and switch to partial panel ops if necessary.