In this paper, we introduce a new invariant of Cohen-Macaulay local rings in terms of canonical ideals. The invariant measures how close to be Gorenstein, and preserved by localizations, dividing non-zerodivisors, and flat local homomorphisms. Furthermore it builds bridges between almost Gorenstein and nearly Gorenstein in dimension one. We also explore the invariant in numerical semigroup rings and rings arising from idealizations.