Giter Club home page Giter Club logo

golang-uptime-sla-calculator's Introduction

Uptime SLA Calculator

Build Status Coverage Status Go Report Card GoDoc

Status

Experimental

Motivation

To be used by developers in my organization to calculate SLA based on specific formula. Freely used by others according to the LICENSE.

How to Start

$ go get github.com/haidlir/golang-uptime-sla-calculator

Example

package main

import (
    "log"

    slacalc "github.com/haidlir/golang-uptime-sla-calculator/sla-calculator"
)

type UptimeData struct {
    Timestamp int64
    Value     int
    Exception bool
}

var (
    startTime int64 = 10000
    endTime int64 = 13000

	// toleranceDeltaRatio is used to give calculation tolerance when there is a delta uptime data glitch.
    // See https://github.com/haidlir/golang-uptime-sla-calculator/issues/5 for more detail explanation.
	toleranceDeltaRatio float64 = 0.9
)

var uptimeSeriesData = []UptimeData{
    UptimeData{10100, 0,    false},
    UptimeData{10200, 0,    false},
    UptimeData{10300, 0,    false},
    UptimeData{10400, 0,    false},
    UptimeData{10500, 270,  false},
    UptimeData{10600, 370,  false},
    UptimeData{10700, 470,  false},
    UptimeData{10800, 570,  false},
    UptimeData{10900, 670,  false},
    UptimeData{11000, 40,   false},
    UptimeData{11100, 140,  false},
    UptimeData{11200, 240,  false},
    UptimeData{11300, 340,  false},
    UptimeData{11400, 440,  false},
    UptimeData{11500, 540,  false},
    UptimeData{11600, 0,    false},
    UptimeData{11700, 0,    false},
    UptimeData{11800, 840,  false},
    UptimeData{11900, 940,  false},
    UptimeData{12000, 1040, false},
    UptimeData{12100, 1140, false},
    UptimeData{12200, 0,    false},
    UptimeData{12300, 0,    false},
    UptimeData{12400, 0,    false},
    UptimeData{12500, 10,   false},
    UptimeData{12600, 110,  false},
    UptimeData{12700, 210,  false},
    UptimeData{12800, 0,    true},
    UptimeData{12900, 0,    true},
    UptimeData{13000, 0,    false},
}

func main() {
    // Prepare the data
    uptimeVals := []int{}
    timestamps := []int64{}
    exceptions := []bool{}
    for _, val := range(uptimeSeriesData) {
        uptimeVals = append(uptimeVals, val.Value)
        timestamps = append(timestamps, val.Timestamp)
        exceptions = append(exceptions, val.Exception)
    }
    // Create calculator object
    calc, err := slacalc.NewUptimeSLACalculator(startTime, endTime, timestamps, uptimeVals, toleranceDeltaRatio, exceptions)
    if err != nil {
        log.Fatalf("An Error should not be accoured: %v", err)
    }
    // Print the calculation result
    log.Printf("Connectivity SLA: %.5f", calc.CalculateSNMPAvailability())
    log.Printf("Uptime SLA: %.5f", calc.CalculateUptimeAvailability())
    log.Printf("(Custom) SLA 1: %.5f", calc.CalculateSLA1Availability())
    log.Printf("(Custom) SLA 2: %.5f", calc.CalculateSLA2Availability())
}

More Example...

License

It is released under the MIT license. See LICENSE.

golang-uptime-sla-calculator's People

Contributors

ganiamri avatar haidlir avatar kevinmartinda avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

golang-uptime-sla-calculator's Issues

Miss calculation result in function CalculateUptimeAvailability()

Halo Mas Naqvi,

I found miss calculation result in function CalculateUptimeAvailability() with this set of uptime data.

Unixtime Uptime Delta Unixtime Delta Uptime
1630741500 31541552 0 0
1630741800 31541852 300 300
1630742100 31542152 300 300
1630742400 31542457 300 305*
1630742700 31542752 300 295*

Using this data will output 0.75 while i think it supposed to return 1.00 uptime availability .

So far, i suspect the transformToSpreadedUptime function need to be reviewed. CMIIW

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.