This paper proposes a method to estimate the inertia constant of synchronous generators (SGs) and the virtual inertia provided by converter-interfaced generators (CIGs). The algorithm is based on a gray-box system identification approach and uses the active power and bus frequency measurements proceeding from phasor measurement units. The measurements are preprocessed to improve the estimation accuracy. Subsequently, a model-independent rotor speed estimator is used to compute rotor speed variations (or internal frequency variations, in the case of CIGs). Afterward, a recursive least-square equation error formulation is implemented to compute the SG and CIG parameters in the z-domain, which are later converted into their respective counterparts in the s-domain. The method is applied to several generation devices in the IEEE 39-bus test system, including traditional SGs and CIGs providing virtual inertia. Numerical results show the accuracy and the low computational burden of the proposed method.