A pump, including a compression compartment configured to receive, between first and second sides of the compartment, a flexible container holding a fluid and having an outlet The pump also has a pump mechanism that is coupled to drive the first and second sides of the compartment together so as to force the fluid out of the container through the outlet. There are first and second electrodes the are fixed respectively to the first and second sides. The pump also includes a processor that is coupled to measure a capacitance between the first and second electrodes and to estimate, responsively to the capacitance, a volume of the fluid remaining in the container.