An apparatus for controlling a water stream exiting a hydrocarbon dewatering tank, the apparatus comprising: a sound velocity detector comprising: a transducer arranged to emit wave energy through the water stream contained in a drain line of the dewatering tank, a detector arranged to receive the wave energy from the transducer after the wave energy has passed through the water stream, and a transmitter in electronic communication with the detector, the transmitter arranged to convert the wave energy received by the detector into a readable signal; and a control system comprising: a computer defining a signal processing device having non-transitory computer memory, the computer in electronic communication with the transmitter, the signal processing device arranged to receive the readable signal from the transmitter; a program product stored in memory and operable on the signal processing device, the program product in electronic communication with the signal processing device, the program product composed of instructions executable to: receive the readable signal from the transmitter, convert the readable signal upon receipt into a measured velocity, compare the measured velocity against a predetermined value range, and take a corrective action if the measured velocity is outside the predetermined value range; and a control element that is arranged to move to a closed position to stop the flow of the water stream exiting the dewatering tank when the corrective action is taken, wherein the control element comprises a controllable valve that is connected to the drain line, wherein the controllable valve is in communication with the computer, wherein the controllable valve is arranged to control the flow of the water stream, and wherein the computer being arranged to take the corrective action includes being arranged to send a signal to the controllable valve to close if the measured velocity is outside the predetermined value range; and, wherein the transducer and the detector are both suitable for being disposed outside of the drain line. a sound velocity detector comprising: a transducer arranged to emit wave energy through the water stream contained in a drain line of the dewatering tank, a detector arranged to receive the wave energy from the transducer after the wave energy has passed through the water stream, and a transmitter in electronic communication with the detector, the transmitter arranged to convert the wave energy received by the detector into a readable signal; and a transducer arranged to emit wave energy through the water stream contained in a drain line of the dewatering tank, a detector arranged to receive the wave energy from the transducer after the wave energy has passed through the water stream, and a transmitter in electronic communication with the detector, the transmitter arranged to convert the wave energy received by the detector into a readable signal; and a control system comprising: a computer defining a signal processing device having non-transitory computer memory, the computer in electronic communication with the transmitter, the signal processing device arranged to receive the readable signal from the transmitter; a program product stored in memory and operable on the signal processing device, the program product in electronic communication with the signal processing device, the program product composed of instructions executable to: receive the readable signal from the transmitter, convert the readable signal upon receipt into a measured velocity, compare the measured velocity against a predetermined value range, and take a corrective action if the measured velocity is outside the predetermined value range; and a computer defining a signal processing device having non-transitory computer memory, the computer in electronic communication with the transmitter, the signal processing device arranged to receive the readable signal from the transmitter; a program product stored in memory and operable on the signal processing device, the program product in electronic communication with the signal processing device, the program product composed of instructions executable to: receive the readable signal from the transmitter, convert the readable signal upon receipt into a measured velocity, compare the measured velocity against a predetermined value range, and take a corrective action if the measured velocity is outside the predetermined value range; and receive the readable signal from the transmitter, convert the readable signal upon receipt into a measured velocity, compare the measured velocity against a predetermined value range, and take a corrective action if the measured velocity is outside the predetermined value range; and a control element that is arranged to move to a closed position to stop the flow of the water stream exiting the dewatering tank when the corrective action is taken, wherein the control element comprises a controllable valve that is connected to the drain line, wherein the controllable valve is in communication with the computer, wherein the controllable valve is arranged to control the flow of the water stream, and wherein the computer being arranged to take the corrective action includes being arranged to send a signal to the controllable valve to close if the measured velocity is outside the predetermined value range; and, wherein the transducer and the detector are both suitable for being disposed outside of the drain line.