Calculate time in different events

How is it possible to cacluate MBTF/availability of equipment within elastic?

The events equipment available and unavailable come within different events. How is it possible to caculate the timedifference between @timestamp of both events based on equipment id?

Calculting the total time the device is unavailable is respect of the total time range is giving me an idea of the availability of the device.