In spiral galaxies like the Milky Way, we derive the gravitational mass
from observing the motions of stars and gas clouds in the disk as
they orbit the center. The rotation curve of a galaxy shows
how the velocity of stars around the center varies as the distance
from the center increases. Most spiral galaxies show
flat rotation curves out as far as
we can trace them, even where no more stars are visible. Therefore we
conclude that the gravitational mass is more than 10 times more massive
than the luminous mass.
Evidence for dark matter in clusters of galaxies
In clusters of galaxies, we derive the gravitational mass by measuring the
orbital motions of the member galaxies.
Since the galaxies in a cluster are roughly at the same distance from us,
we can interpret any spread in their redshifts as orbital motion around the
center of the cluster; it might amount to more than 1000 km/sec! By measuring
the redshifts of lots of galaxies in the cluster, we can calculate the
gravitational mass required to keep the galaxies in orbit (rather than
escaping). This gravitational mass
then can be compared to the luminous
mass contributed by the galaxies plus that contributed by the Xray gas.