Designing in Power Standards Lab's (PSL) PQ1 Power Quality Relay is simple: Just connect its inputs to the AC line that feeds your system, and connect its relay contacts to your control computer's digital inputs.
Your software will know every time there is a sag, dip, swell, or impulse on the mains.