Since there is no circuit/component on-board to measure the battery level, you have to build external hardware to cooperate with software to measure the level:
Connect two 100K resistors in serial between the VIN and GND: VIN <-> R1 <-> R2 <-> GND. Then route an analog pin to the node between R1 and R2 to sample the voltage Vnode. The VIN voltage should be equal to 2*Vnode. If you adopt different R1 and R2, you should calculate the VIN voltage using different ratio.
Also you have to know the Charging/Discharging voltage curve of the battery, so that you can map the battery voltage to battery level 0% to 100%.