mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 02:15:43 +03:00
Implementing the total ticks per task for the docker driver
This commit is contained in:
@@ -19,7 +19,7 @@ type MemoryStats struct {
|
||||
type CpuStats struct {
|
||||
SystemMode float64
|
||||
UserMode float64
|
||||
Ticks float64
|
||||
TotalTicks float64
|
||||
ThrottledPeriods uint64
|
||||
ThrottledTime uint64
|
||||
Percent float64
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
cstructs "github.com/hashicorp/nomad/client/driver/structs"
|
||||
"github.com/hashicorp/nomad/helper/discover"
|
||||
"github.com/hashicorp/nomad/helper/fields"
|
||||
shelpers "github.com/hashicorp/nomad/helper/stats"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
@@ -125,6 +126,7 @@ type DockerHandle struct {
|
||||
imageID string
|
||||
containerID string
|
||||
version string
|
||||
clkSpeed float64
|
||||
killTimeout time.Duration
|
||||
maxKillTimeout time.Duration
|
||||
resourceUsageLock sync.RWMutex
|
||||
@@ -777,6 +779,9 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle
|
||||
doneCh: make(chan bool),
|
||||
waitCh: make(chan *cstructs.WaitResult, 1),
|
||||
}
|
||||
if clkSpeed, err := shelpers.TotalTicksAvailable(); err == nil {
|
||||
h.clkSpeed = clkSpeed
|
||||
}
|
||||
if err := exec.SyncServices(consulContext(d.config, container.ID)); err != nil {
|
||||
d.logger.Printf("[ERR] driver.docker: error registering services with consul for task: %q: %v", task.Name, err)
|
||||
}
|
||||
@@ -851,6 +856,9 @@ func (d *DockerDriver) Open(ctx *ExecContext, handleID string) (DriverHandle, er
|
||||
doneCh: make(chan bool),
|
||||
waitCh: make(chan *cstructs.WaitResult, 1),
|
||||
}
|
||||
if clkSpeed, err := shelpers.TotalTicksAvailable(); err == nil {
|
||||
h.clkSpeed = clkSpeed
|
||||
}
|
||||
if err := exec.SyncServices(consulContext(d.config, pid.ContainerID)); err != nil {
|
||||
h.logger.Printf("[ERR] driver.docker: error registering services with consul: %v", err)
|
||||
}
|
||||
@@ -1015,6 +1023,13 @@ func (h *DockerHandle) collectStats() {
|
||||
s.CPUStats.CPUUsage.UsageInUsermode, s.PreCPUStats.CPUUsage.UsageInUsermode,
|
||||
s.CPUStats.CPUUsage.TotalUsage, s.PreCPUStats.CPUUsage.TotalUsage, cores)
|
||||
|
||||
if h.clkSpeed == 0.0 {
|
||||
if clkSpeed, err := shelpers.TotalTicksAvailable(); err != nil {
|
||||
h.clkSpeed = clkSpeed
|
||||
}
|
||||
}
|
||||
cs.TotalTicks = (cs.Percent / 100) * h.clkSpeed
|
||||
|
||||
h.resourceUsageLock.Lock()
|
||||
h.resourceUsage = &cstructs.TaskResourceUsage{
|
||||
ResourceUsage: &cstructs.ResourceUsage{
|
||||
|
||||
@@ -787,7 +787,7 @@ func (e *UniversalExecutor) aggregatedResourceUsage(pidStats map[string]*cstruct
|
||||
UserMode: userModeCPU,
|
||||
Percent: percent,
|
||||
Measured: ExecutorBasicMeasuredCpuStats,
|
||||
Ticks: totalTicks,
|
||||
TotalTicks: totalTicks,
|
||||
}
|
||||
|
||||
totalMemory := &cstructs.MemoryStats{
|
||||
|
||||
@@ -173,7 +173,7 @@ func (e *UniversalExecutor) Stats() (*cstructs.TaskResourceUsage, error) {
|
||||
Percent: percent,
|
||||
ThrottledPeriods: stats.CpuStats.ThrottlingData.ThrottledPeriods,
|
||||
ThrottledTime: stats.CpuStats.ThrottlingData.ThrottledTime,
|
||||
Ticks: e.systemCpuStats.TicksConsumed(percent),
|
||||
TotalTicks: e.systemCpuStats.TicksConsumed(percent),
|
||||
Measured: ExecutorCgroupMeasuredCpuStats,
|
||||
}
|
||||
taskResUsage := cstructs.TaskResourceUsage{
|
||||
|
||||
@@ -102,7 +102,7 @@ type MemoryStats struct {
|
||||
type CpuStats struct {
|
||||
SystemMode float64
|
||||
UserMode float64
|
||||
Ticks float64
|
||||
TotalTicks float64
|
||||
ThrottledPeriods uint64
|
||||
ThrottledTime uint64
|
||||
Percent float64
|
||||
|
||||
Reference in New Issue
Block a user