Skip to content

Commit

Permalink
provide fixed min/max to profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
cha87de committed Jan 17, 2019
1 parent 9e4b296 commit 7d1ee0c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 16 deletions.
1 change: 1 addition & 0 deletions config/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ type ProfilerOptionsType struct {
History int `long:"history" default:"1"`
FilterStdDevs int `long:"filterstddevs" default:"-1"`
OutputFreq time.Duration `long:"outputFreq" default:"60"`
FixedBound bool `long:"fixedbound"`
}
42 changes: 32 additions & 10 deletions profiler/pickup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/cha87de/kvmtop/collectors/cpucollector"
)

func pickupCPU(domain models.Domain) int {
func pickupCPU(domain models.Domain) (int, int, int) {
cputimeAllCores, err := strconv.Atoi(cpucollector.CpuPrintThreadMetric(&domain, "cpu_threadIDs", "cpu_times"))
if err != nil {
fmt.Printf("err Atiu cpu_times: %v\n", err)
Expand All @@ -20,10 +20,12 @@ func pickupCPU(domain models.Domain) int {
fmt.Printf("err Atiu cpu_runqueues: %v\n", err)
}
cpuUtil := cputimeAllCores + queuetimeAllCores
return cpuUtil
min := 0
max := 100
return cpuUtil, min, max
}

func pickupIO(domain models.Domain) int {
func pickupIO(domain models.Domain) (int, int, int) {
readBytes, err := strconv.Atoi(collectors.GetMetricDiffUint64(domain.Measurable, "io_read_bytes", true))
if err != nil {
fmt.Printf("err Atiu io_read_bytes: %v\n", err)
Expand All @@ -33,20 +35,40 @@ func pickupIO(domain models.Domain) int {
fmt.Printf("err Atiu io_write_bytes: %v\n", err)
}
total := readBytes + writtenbytes
return total
min := 0
// TODO get disk i/o max speed from system
maxSata3 := 6 // GBit/s
max := maxSata3 * 1024 * 1024 * 1024 // Bit/s
return total, min, max
}

func pickupNet(domain models.Domain) int {
receivedBytes, err := strconv.Atoi(collectors.GetMetricDiffUint64(domain.Measurable, "net_ReceivedBytes", true))
func pickupNet(domain models.Domain) (int, int, int) {
rawRx := collectors.GetMetricDiffUint64(domain.Measurable, "net_ReceivedBytes", true)
if rawRx == "" {
rawRx = "0"
}
receivedBytes, err := strconv.Atoi(rawRx)
if err != nil {
fmt.Printf("err Atiu net_ReceivedBytes: %v\n", err)
}
transmittedBytes, err := strconv.Atoi(collectors.GetMetricDiffUint64(domain.Measurable, "net_TransmittedBytes", true))
rawTx := collectors.GetMetricDiffUint64(domain.Measurable, "net_TransmittedBytes", true)
if rawTx == "" {
rawTx = "0"
}
transmittedBytes, err := strconv.Atoi(rawTx)
if err != nil {
fmt.Printf("err Atiu net_TransmittedBytes: %v\n", err)
}
total := receivedBytes + transmittedBytes
// max, _ := strconv.Atoi(collectors.GetMetricUint64(models.Collection.Host.Measurable, "net_host_speed", 0)) // MBit
// max = max * 1024 * 1024 / 8 // to Byte
return total
min := 0
rawNetSpeed := collectors.GetMetricUint64(models.Collection.Host.Measurable, "net_host_speed", 0)
if rawNetSpeed == "0" {
// set default to 1GBit/s
defaultSpeed := 1 * 1024 * 1024 * 1024
rawNetSpeed = fmt.Sprintf("%d", defaultSpeed)
fmt.Printf("no netspeed given, set default to %s\n", rawNetSpeed)
}
max, _ := strconv.Atoi(rawNetSpeed) // MBit
max = max * 1024 * 1024 / 8 // to Byte
return total, min, max
}
15 changes: 9 additions & 6 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func pickup() {
States: config.Options.Profiler.States,
History: config.Options.Profiler.History,
FilterStdDevs: config.Options.Profiler.FilterStdDevs,
FixBound: config.Options.Profiler.FixedBound,
OutputFreq: config.Options.Profiler.OutputFreq,
OutputCallback: profileOutput,
})
Expand All @@ -67,18 +68,20 @@ func pickup() {
metrics := make([]spec.TSDataMetric, 0)
models.Collection.Collectors.Map.Range(func(nameRaw interface{}, collectorRaw interface{}) bool {
name := nameRaw.(string)
var util int
var util, min, max int
if name == "cpu" {
util = pickupCPU(domain)
util, min, max = pickupCPU(domain)
} else if name == "io" {
util = pickupIO(domain)
util, min, max = pickupIO(domain)
} else if name == "net" {
util = pickupNet(domain)
util, min, max = pickupNet(domain)
}

metrics = append(metrics, spec.TSDataMetric{
Name: name,
Value: float64(util),
Name: name,
Value: float64(util),
FixedMin: float64(min),
FixedMax: float64(max),
})
return true
})
Expand Down

0 comments on commit 7d1ee0c

Please sign in to comment.