The reason astronomers can tell how far the light gets shifted is because certain chemical elements, like the calcium in bones or the oxygen people breathe has a unique fingerprint of light that no other chemical element has. They can see what colors of light are coming from a star, and see what it is made of. Once they know that, they look at the difference between where the fingerprint (called spectral lines) is and where it is supposed to be. When they see that, they can tell how far away the star is, whether it is moving toward us or away from us, and also how fast it is going, since the faster it goes, the farther the distance the spectral lines are from where they should be.