To measure the corrosion you can use a pit gauge or pencil probe with UT flaw detector. Once corrosion is mapped, complete fitness for service evaluation (B31G, RStreng, API 579 etc.). Many repair options available, sleeves are commonly used on gas pipelines for external corrosion.
As far as how the corrosion accures, or occurs, the iron in the pipe (Fe) is reacting with oxygen in water to produce iron oxides/hydroxides, but this is a very simple explanation, you can easily look this up in any corrosion book and background info. I highly recommend you seek outside help from consulting company in the area of NDT to map corrosion& pipeline integrity to complete fitness for service and repair options to assist.