Let $M$ be a (commutative cancellative) monoid. A nonunit element $q\in M$ is called almost primary if for all $a,b\in M$, $q\mid ab$ implies that there exists $k\in \mathbb {N}$ such that $q\mid a^k$ or $q\mid b^k$. We introduce a new monoid invariant, diversity, which generalizes this almost primary property. This invariant is developed and contextualized with other monoid invariants. It naturally leads to two additional properties (homogeneity and strong homogeneity) that measure how far an almost primary element is from being primary. Finally, as an application the authors consider factorizations into almost primary elements, which generalizes the established notion of factorization into primary elements.