A pump, including a compression compartmentconfigured to receive, between first and second sides ofthe compartment, a flexible container holding a fluid andhaving an outlet The pump also has a pump mechanism thatis coupled to drive the first and second sides of thecompartment together so as to force the fluid out of thecontainer through the outlet. There are first and secondelectrodes the are fixed respectively to the first andsecond sides. The pump also includes a processor that iscoupled to measure a capacitance between the first andsecond electrodes and to estimate, responsively to thecapacitance, a volume of the fluid remaining in thecontainer.