If you integrate the DOS, $g(E)$, up to the Fermi-level, $E_F$, the area should be very close to the number of electrons, $N$; i.e.
$$
N \approx \int_{-\infty}^{E_f} g(E) dE \tag{1}.
$$
You'll have to be careful what the normalisation is for the DOS, but this will only affect the definition of $N$, e.g. whether it's the number of electrons per unit cell, or per unit volume, or per atom etc.
The reason the integral is usually only "close" to the number of electrons, $N$, is because it is standard practice to apply a smearing function in the calculation to better approximate the integral over the Brillouin zone. If you include this smearing function, $f(E-E_F)$, in the integrand and integrate over all energies, then the result should be exact:
$$
N = \int_{-\infty}^{\infty} f(E-E_F) g(E) dE \tag{2}.
$$
This relationship is actually the definition of the Fermi energy $E_F$, so it really should be reliable. If you find that you don't get the correct answer, you should check that you are using the same broadening function and width - e.g. some programs ask for the smearing width as the standard deviation of the broadening, and some as the full-width half-maximum (FWHM).
There may also be some small discrepancies in the electron count if you use a Fermi energy calculated on one k-point grid, and then do the integral on the DOS from a different k-point grid. In practice, this usually arises when the Fermi energy is from the self-consistent (SCF) ground state calculation, and the DOS is calculated from a non-self-consistent calculation performed on a finer k-point grid.