This paper proposes a method to estimate the inertia constant of synchronous generators (SGs) and the virtual inertia provided by converter-interfaced generators (CIGs). It can be applied when the system is under normal operating conditions or after power imbalance events. The algorithm is based on a recursive 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). Afterwards, 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 and IEEE 118-bus test systems, including traditional SGs and CIGs providing virtual inertia. Numerical results show the accuracy and the low computational burden of the proposed method.