From d27ba14ce2315e8270382ca3331bc15d5e5039cf Mon Sep 17 00:00:00 2001
From: Simon Crowle <sgc@it-innovation.soton.ac.uk>
Date: Mon, 9 Apr 2018 17:10:59 +0100
Subject: [PATCH] Adds example MTBF, MTTR and MDT KPIs for MC config stats

---
 docs/monitoring.md | 52 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/docs/monitoring.md b/docs/monitoring.md
index e964ce0..c69733e 100644
--- a/docs/monitoring.md
+++ b/docs/monitoring.md
@@ -517,7 +517,7 @@ FLAME _endpoints_ (VMs created and managed by the SFEMC) and media service _medi
 > 'MST' - Mean state time: the sum of each time taken by each completed state of type 'X' divided by the number of completed state 'X's; i.e:
 >
 >```math
-> meanStateTime = \frac{\sum(startTimeOfState - endTimeOfState)}{numberOfTimesInState}
+> meanStateTime = \frac{\sum(endTimeOfState - startTimeOfState)}{numberOfTimesInState}
 >```
 >
 
@@ -591,6 +591,56 @@ An example (based on the figure above) of some measurement rows for a media comp
 | ... | starting | 10 | 5 | 5   | 0 | 0 | 0 | 0 | 0 | 0 | ... |
 
 
+### Example endpoint state configuration queries
+
+
+### Example media component state configuration queries
+
+In the following examples we illustrate how to calculate _mean time between failures_ (MTBF); _mean time to repair_ (MTTR) and _mean down time_ (MDT) for a media component (in our case, the _mpegdash_ MC) according to definitions found [here](https://en.wikipedia.org/wiki/Mean_time_between_failures).
+
+_Q. What is the Mean Time Before Failure (MTBF) of media component 'mpegdash'?_
+
+```
+select mean(running_mst) as "mpegdash_MTBF(s)" from "mpegdash_mc_config" where running_mst <> 0
+```
+
+```
+time mpegdash_MTBF(s)
+---- ----------------
+0    3602.1000000000004
+```
+ 
+
+_Q. What is the Mean Time to Repair (MTTR) of media component 'mpegdash'?_
+
+```
+select mean(starting_mst) as "mpegdash_MTTR(s)" from "mpegdash_mc_config" where starting_mst <> 0
+```
+
+```
+name: mpegdash_mc_config
+time mpegdash_MTTR(s)
+---- ----------------
+0    5.5
+```
+
+_Q. What is the Mean Down Time (MTD) of media component 'mpegdash'?_
+
+```
+select mean(starting_mst) as "starting_mdt" into "mpegdash_mc_config_mdt" from "mpegdash_mc_config" where starting_mst <> 0
+select mean(stopping_mst) as "stopping_mdt" into "mpegdash_mc_config_mdt" from "mpegdash_mc_config" where stopping_mst <> 0
+select mean(stopped_mst) as "stopped_mdt" into "mpegdash_mc_config_mdt" from "mpegdash_mc_config" where stopped_mst <> 0
+select (starting_mdt + stopping_mdt + stopped_mdt) as "MDT(s)" from "mpegdash_mc_config_mdt"
+```
+
+```
+name: mpegdash_mc_config_mdt
+time MDT(s)
+---- ------
+0    6.8
+```
+
+
 ## Media Service Measurements 
 
 Media service measurements measure the configuration, usage and performance of media service instances deployed by the platform.
-- 
GitLab