Many boats these days have a battery or systems monitor permanently installed. Popular models include: E-Meter, Link 10, Victron BMV, Philippi BCM, and so forth.
With these meters, DC current is measured in and out of the battery by a device called a Shunt that is installed in the negative lead to the battery. A Shunt is simply a bar of metal with a known resistance between the two ends.
The resulting drop in current is then measured by the monitor and multiplied to give the correct current reading. The Shunt is the very last item connected to the battery negative post, and no other negative leads must be allowed to by-pass it. This is to ensure that it measures every amp of current going both in and out of the battery.
As you can see from the example below, it is possible for solar panels or a wind/hydro generator to supply power for DC loads directly, via bus bars or other connection points, without their current flowing into the battery or through the battery monitor Shunt.