Meaning: by the thinnest of margins
Rewrite 1: by the skin on a rooster’s beak
Rewrite 2: by the cheeks on a flea’s behind
Rewrite 3: by the tear on a peacock's tail
Rewrite 4: by the width of a hair
Comment: In rewrite 2, you can argue whether a flea has a "behind," but it's the size that counts in this metaphor. Meanwhile, rewrite 3 may be somewhat obscure. Can you figure it out? If you're having trouble, think of what might appear on a peacock's tail. In rewriting clichés, you want quick clarity -- you don't want your reader to spend a lot of time trying to figure it out.