Cosmic metal production and the mean metallicity of the Universe