Non-rechargeable Battery Gauge circuit / Coulomb counter
In a nutshell, measure the current periodically with an IC like INA219 and integrate it over time to know the battery consumed.
Using a shunt resistor based current monitor like INA219 you can get about 1kHz of load current sampling rate. Only situations where this approach might be less accurate is if you have many magnitudes of dynamic range of current to measure (A to uA) or if you have short bursts (few us) of high current consumed you.

If you're measuring every ms, then keep accumulating the current up measured in A in variable, say charge_count. You can now check charge_count against the battery capacity to see how much capacity is left.
To calculate the battery capacity, let's take an example of a 1 Ah battery, which means you can draw 1A for an hour. So it means 1A for 3600000 ms. So you can check charge_count against 3600000 value to see how much battery is left.
Measuring the current in A requires you to convert the sampled value to float, you can change the entire calculations to use integers if you use appropriate scaling.