This is a phrase we use when the signs are clear that something is about to change, maybe the fall of a government or even the end of a relationship. Often it spells catastrophe.
The origin is a Bible one, from the Book of Daniel. At the time of the Babylonian empire, King Belshazzar held a debauched party with his rulers and wives. They were having a tremendous time until the fingers of a man's hand appeared and wrote on the wall.