But without knowing the total size how can you tell that there is not sufficient mass to force contraction in the future. Can they measure the rate of expansion over time ?
This is indeed possible and is done. The rate of expansion is observed directly by identifying "standard candles", i.e., supernovae that have a known brightness (there are a few complications, and there are other methods as well…). Comparing this to their apparent brightness in the sky gives you the distance. Measuring their "redshift" - a characteristic signature in their light spectra that all objects exhibit - gives you a direct measurement of the factor by which the universe has expanded during the billions of years that the light has travelled. That way, you can measure the expansion curve directly and compare it to models of the expansion.
However, there are other pieces of evidence. Most importantly, the quantity that you need in order to work out the expansion model is not so much the total mass, but rather the mass density. Therefore, it is sufficient to estimate the mass in a representative region of the universe. For example, you can look at the velocities of galaxies in galaxy clusters to measure the total mass in there, determine the ratio of total mass to starlight, and then simply multiply with the number of stars that you observe over large distances. Or you can use gravitational lensing to estimate the mass of such a structure.
Furthermore, computational astrophysicists routinely run simulations of how clusters, galaxies, and stars emerged from what was initially a rather smooth distribution of gas. The rate at which structures in the universe form, and the number ratios of small to large structures, also depend on parameters such as the mass density. If there's more mass around, it also tends to clump together more quickly and so on. This, too, can be compared to observations, for example by measuring how "clumped" galaxies are, and comparing the structures we see to these simulations, and thus certain models can be ruled out.
All these observations put together seem to paint a fairly consistent picture now. The amount of matter in the universe appears to be something like 25% of what would have been needed to eventually stop the expansion. However, the story doesn't end there - about 20 years ago, measurements of the expansion curve as described above indicated that the expansion wasn't just going on with little deceleration, but was actually even speeding up. It wasn't just that the mass density was too low - but there seemed to be a second, distinct effect coming into play.
At that time, an additional factor was re-introduced into the equations that Einstein had initially considered as a way to counteract gravity when he still believed in the universe having to be static, but which was then discarded and tacitly assumed to be zero for many decades - the "cosmological constant".
It's not really pretty, and possibly you might reproduce similar observations by altering the law of gravity, or by coming up with a different way of generating redshift signatures in distant objects - but on the other hand, the cosmological constant had actually always been there in the equations since the early 20th century, even though cosmologists had almost forgotten about it until those supernova measurements forced them to reactivate it.
But the amazing thing is how well everything comes together. It turns out that the cosmological constant appears to add up with the matter density to almost precisely 100%, which would have been required to make the universe geometrically flat - meaning that, if you find a ruler that's millions of light years long, you can measure distances using Pythagoras's theorem everywhere in the universe. A flat geometry is, incidentally, just what the theory of cosmic inflation predicts (imagine a bug standing on the surface of a balloon, and the the ballon suddenly gets inflated a million times - to the bug, the surface will look perfectly flat afterwards). However, unlike matter, the cosmological constant doesn't slow down the expansion, but accelerates it even more.