Skip to content

Commit

Permalink
Extended metrics with Serve stats
Browse files Browse the repository at this point in the history
Signed-off-by: Plamen Petrov <plamb0brt@gmail.com>
  • Loading branch information
plamenmpetrov authored and ustiugov committed Jul 27, 2020
1 parent b172a3c commit 87529e2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
9 changes: 9 additions & 0 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ func TestLoadSnapshotStats(t *testing.T) {

PrintLoadSnapshotStats(s1, s2)
}

func TestServeStats(t *testing.T) {
s1 := NewServeStat()
s1.GetResponse = 25
s1.RetireOld = 10
require.Equal(t, int64(35), s1.Total(), "Total is incorrect")

PrintServeStats(s1)
}
85 changes: 85 additions & 0 deletions metrics/serveStat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// MIT License
//
// Copyright (c) 2020 Plamen Petrov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

package metrics

import (
"fmt"

"gonum.org/v1/gonum/stat"
)

// NewServeStat Creates a new ServeStat
func NewServeStat() *ServeStat {
s := new(ServeStat)
return s
}

// Total Calculates the total time it took to Serve
func (s *ServeStat) Total() int64 {
return s.AddInstance + s.GetResponse + s.RetireOld
}

// PrintTotal Prints the total time to Serve
func (s *ServeStat) PrintTotal() {
fmt.Printf("Serve total: %d us\n", s.Total())
}

// PrintAll Prints a breakdown of the time it took to Serve
func (s *ServeStat) PrintAll() {
fmt.Printf("Serve Stats \tus\n")
fmt.Printf("GetImage \t%d\n", s.AddInstance)
fmt.Printf("FcCreateVM \t%d\n", s.GetResponse)
fmt.Printf("NewContainer \t%d\n", s.RetireOld)
fmt.Printf("Total \t%d\n", s.Total())
}

// PrintServeStats prints the mean and
// standard deviation of each component of
// ServeStat statistics
func PrintServeStats(startVMstats ...*ServeStat) {
addInstances := make([]float64, len(startVMstats))
getResponses := make([]float64, len(startVMstats))
retireOlds := make([]float64, len(startVMstats))
totals := make([]float64, len(startVMstats))

for i, s := range startVMstats {
addInstances[i] = float64(s.AddInstance)
getResponses[i] = float64(s.GetResponse)
retireOlds[i] = float64(s.RetireOld)
totals[i] = float64(s.Total())
}

var (
mean float64
std float64
)
fmt.Printf("Serve Stats \tMean(us)\tStdDev(us)\n")
mean, std = stat.MeanStdDev(addInstances, nil)
fmt.Printf("AddInstance \t%12.2f\t%12.2f\n", mean, std)
mean, std = stat.MeanStdDev(getResponses, nil)
fmt.Printf("GetResponse \t%12.2f\t%12.2f\n", mean, std)
mean, std = stat.MeanStdDev(retireOlds, nil)
fmt.Printf("RetireOld \t%12.2f\t%12.2f\n", mean, std)
mean, std = stat.MeanStdDev(totals, nil)
fmt.Printf("Total \t%12.2f\t%12.2f\n", mean, std)
}
7 changes: 7 additions & 0 deletions metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ type StartVMStat struct {
TaskWait int64
TaskStart int64
}

// ServeStat Serve Stats
type ServeStat struct {
AddInstance int64
GetResponse int64
RetireOld int64
}

0 comments on commit 87529e2

Please sign in to comment.