Once actual chemistry broke open our ability to analyze that drug, related chemicals could be synthesized and studied, which led to biguanidines, of which metformin is one, which were tested in animals.
Many drugs are found this way by looking at chemicals related to ones we already know about, and then testing on animals and humans. Self testing of new drugs by researchers used to be very common.
How did folk medicine come to know the effects of guanidine? Dunno.