[This is a fast-access FAQ excerpt.]
This expression meaning "to dwindle to nothing" is recorded from
1846, which precludes derivation "peter" in the sense "penis", an
Americanism not attested until 1902. "To peter out" was apparently
first used by American miners referring to exhausted veins of ore.
The origin is uncertain. It may come from "saltpetre" (used in the
miners' explosives, so called because it forms a salt-like crust
on rocks, ultimately from Greek petra = "rock", whence we also
get "petrify" and "petroleum"); or it may come from French peter,
which literally means "to fart" but is used figuratively to mean
"to fizzle" and in the phrase peter dans la main = "to come to
nothing" (this comes from the Indo-European root *perd-/*pezd-,
whence we get "fart", "feisty", "fizzle", "partridge", "pedicular",
and "petard").