Because of its important cosmological consequences, astronomers have been trying for decades to measure the average density of matter in the universe. Their method is straightforward. With powerful telescopes, they carefully observe large volumes of space and add up the masses of the stars they can see as well as the mass of other material whose presence they can infer by studying stellar and galactic motion.
This would presume we know roughly the size of the whole universe and that the observable portions are either the whole or reasonable representatives of it. I'm not convinced we aren't like Columbus estimating the size of Asia relative to the earth. It makes plenty of sense based on the data we have, but fails because of the data we're missing.