Calculation of uptime / downtime for a service
I have a custom solution that checks if a website is online every 1 hour.
The result looks something like this: (there is one entry per day)
There are 24 entries per day (every hour). And every hour has a percentage of availability (100%, 95%, 0% ... etc.).
My questions:
-
How can I get the percentage of downtime and downtime?
-
how can i calculate the downtime and downtime using these values โโbetween 2 dates
DateTime
and get the result in seconds?
Downtime:
- the sum of all values โโdivided by 24 (records), which is 99.67%
Then for downtime, can I just do 100 - 99.67 = 0.33%?
I have some problems getting the downtime / downtime in seconds between 2 dates DateTime
For example: if the dates are 04/20/2015 - 05/26/2015
I think I should do like this:
For each day, calculate the rise time as above (sum of all daily values โโdivided by 24 records) and assuming the following values:
- 04/20/2015: 96.67%
- 04/21/2015: 100.00%
- 04/22/2015: 92.00%
- 04/23/2015: 96.67%
- 04.24.2015: 100.00%
- 04/25/2015: 100.00%
- 04/26/2015: 100.00%
Now the sum of the above values โโis divided by the number of days (7 days between 20.04 and 26.04), which makes the availability 97.91 %
between 20.04 and 26.04.
I guess you get 97.91% of the time per second, I have to do the following:
CultureInfo provider = CultureInfo.InvariantCulture;
DateTime first = DateTime.ParseExact("20.04.2015", "dd.MM.yyyy", provider);
DateTime last = DateTime.ParseExact("26.04.2015", "dd.MM.yyyy", provider);
TimeSpan time = last - first;
decimal secondsUptime = ((time.Days * 86400)/100) * 97.91m; //97.91 is the uptime calculated above for the time period.
// The problem is how to get this?
decimal secondsDowntime = ?
What I have done so far, is this the correct approach?
How do I get a stopwatch?
source to share
If you already have the Up time percentage, all you have to do is some very simple math:
decimal PercentDownTime = 100 - PercentUpTime;
decimal SecondsUpTime = (time.Seconds / 100) * PercentUpTime;
decimal SecondsDownTime = (time.Seconds / 100) * PercentDownTime;
Thanks to Robert for the reminder about the TotalSeconds
property TimeSpan
, but it's ok to use the property in this case Seconds
.
source to share
Hold ... Ur input numbers are incorrect. If u measures once an hour and displays hourly results, than ur 11:00 at 97%? It should be 100% or 0% up or down at this hour .... If y really doesn't have more calculations in this hour ... But even then, to get 97 y, you would have to do at least 100 tests of this hour and 3 of them were omitted.
But if the numbers ur are correct, then the formulas ...
Uptime% = (sum of percentage of time) / (number of measurements) ร 100
Uptime% = (sum of uptime) / 24 ร 100
Downtime% = 100 - (Uptime%)
Uptime seconds = (hours measured or accounted for) ร 3600 ร (uptime%) / 100
Downtime seconds = (number of hours measured or viewed ร 3600) - (uptime seconds)
Note 3600 is the number of seconds per hour, so we multiply the number of hours by this to get us at the desired unit of time.
Note Replace uptime with% with a number between 0 and 100. Not 0 and 1. If u uses 0 to 1, then do not perform the last division by 100.
source to share