Skip to content

Commit

Permalink
provide max value to profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
cha87de committed Nov 3, 2018
1 parent 6f49dca commit 1002071
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
20 changes: 13 additions & 7 deletions profiler/pickup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@ package profiler
import (
"strconv"

"github.com/cha87de/kvmtop/collectors"
"github.com/cha87de/kvmtop/models"

"github.com/cha87de/kvmtop/collectors/cpucollector"
)

func pickupCPU(domain models.Domain) int {
func pickupCPU(domain models.Domain) (int, int) {
cputimeAllCores, _ := strconv.Atoi(cpucollector.CpuPrintThreadMetric(&domain, "cpu_times"))
queuetimeAllCores, _ := strconv.Atoi(cpucollector.CpuPrintThreadMetric(&domain, "cpu_runqueues"))
cpuUtil := cputimeAllCores + queuetimeAllCores
return cpuUtil
cpuMax := 100
return cpuUtil, cpuMax
}

func pickupIO(domain models.Domain) int {
func pickupIO(domain models.Domain) (int, int) {
// TODO
return 0
return 0, 0
}

func pickupNet(domain models.Domain) int {
// TODO
return 0
func pickupNet(domain models.Domain) (int, int) {
receivedBytes, _ := strconv.Atoi(collectors.GetMetricDiffUint64(domain.Measurable, "net_ReceivedBytes", true))
transmittedBytes, _ := strconv.Atoi(collectors.GetMetricDiffUint64(domain.Measurable, "net_TransmittedBytes", true))
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, max
}
9 changes: 5 additions & 4 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,18 @@ 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, max int
if name == "cpu" {
util = pickupCPU(domain)
util, max = pickupCPU(domain)
} else if name == "io" {
util = pickupIO(domain)
util, max = pickupIO(domain)
} else if name == "net" {
util = pickupNet(domain)
util, max = pickupNet(domain)
}
metrics = append(metrics, spec.TSDataMetric{
Name: name,
Value: float64(util),
Max: float64(max),
})
return true
})
Expand Down

0 comments on commit 1002071

Please sign in to comment.