Ah, sft42, but.....
To quote from World Wide Words, the phrase was "... first recorded in the USA in the early part of this century. There is some suspicion, because of a citation from 1835, that the phrase may in fact be at least of this age.
There is a story, often repeated, that the phrase originated in naval warfare at the time of the Napoleonic wars, if not before. It is said that the stack of cannon balls alongside each gun, arranged in a pyramid on a brass plate to save space, was called a monkey. In very cold weather, it is related, the cannon balls would shrink and balls would fall off the stack.
Though monkey was a term used in this context and era (the boys bringing charges to the guns from the magazine were known as powder monkeys and there is some evidence that a type of cannon was called a monkey in the mid seventeenth century), there is no evidence for the word being applied to a pile of cannon shot.
The explanation sounds like a story that's been woven around a term already well known and is full of logical holes: would they pile shot into a pyramid? (hugely unsafe on a rolling and pitching deck); why a brass plate? (far too expensive, and unnecessary: they actually used wooden frames with holes in, called garlands, fixed to the sides of the ship); was the plate and pile together actually called a monkey? (no evidence, as I say); would cold weather really cause such shrinkage as to cause balls to fall off? (highly improbable, as all the balls would reduce in size equally and the differential movement between the brass plate and the iron balls would be only a fraction of a millimetre).
Fun story, though."