Skip to content

Commit 0732da7

Browse files
committed
mon: additional vm metrics
1 parent 71ffedb commit 0732da7

File tree

5 files changed

+81
-13
lines changed

5 files changed

+81
-13
lines changed

docs/prometheus.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ pind_vm_cpu{instance="micronode15:9091", job="pind", vm_name="ps-va-16-1-db"}
8181
`pind_vm_numa` - индекс NUMA ноды к которой привязана виртуалка. Если нагрузки нет,
8282
то виртуалка остаётся в коммуналке и имеет значение -1. Если нагрузка есть, то
8383
принимает значение индекса NUMA ноды.
84+
85+
`pind_vm_required_cores_phys` - требуемое число физических ядер процессора из пула,
86+
выделенного под нагрузку (pool_load).
87+
88+
`pind_vm_required_cores` - требуемое число ядер (с учётом логических) процессора.
89+
90+
`pind_vm_assigned_cores` - число фактически назначенных логических ядер процессора.
91+
92+
`pind_vm_assigned_cores0` - процент назначенных (привязанных) ядер процессора.
93+
Максимум 100% - всё назначилось, ядер хватило.

pkg/monitoring.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ func fillMonitoringState(ctx *Context) *mon_state.State {
4545

4646
numa0 := pinProc.GetNuma0()
4747
proc := &mon_state.Proc{
48-
VmName: pinProc.ProcInfo.VmName,
49-
Time: state.Time,
50-
CPU: pinProc.ProcInfo.cpu0,
51-
Load: pinProc.ProcInfo.load,
52-
Numa0: numa0,
48+
VmName: pinProc.ProcInfo.VmName,
49+
Time: state.Time,
50+
CPU: pinProc.ProcInfo.cpu0,
51+
Load: pinProc.ProcInfo.load,
52+
Numa0: numa0,
53+
RequiredCoresPhys: pinProc.RequiredCoresPhys,
54+
RequiredCores: pinProc.RequiredCores,
55+
AssignedCores: pinProc.AssignedCores,
5356
}
5457

5558
state.Procs[pinProc.ProcInfo.VmName] = proc

pkg/monitoring/collector/proc.go

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ type Proc struct {
1010
VmName string
1111
Proc *mon_state.Proc
1212

13-
CPU *prometheus.Desc
14-
Load *prometheus.Desc
15-
Numa0 *prometheus.Desc
13+
CPU *prometheus.Desc
14+
Load *prometheus.Desc
15+
Numa0 *prometheus.Desc
16+
RequiredCoresPhys *prometheus.Desc
17+
RequiredCores *prometheus.Desc
18+
AssignedCores *prometheus.Desc
19+
AssignedCores0 *prometheus.Desc
1620
}
1721

1822
func NewProc(proc *mon_state.Proc) (*Proc, error) {
@@ -43,6 +47,23 @@ func NewProc(proc *mon_state.Proc) (*Proc, error) {
4347
nil, labels0,
4448
)
4549

50+
ent.RequiredCoresPhys = prometheus.NewDesc("pind_vm_required_cores_phys",
51+
"vm required physical cpu cores",
52+
nil, labels0,
53+
)
54+
ent.RequiredCores = prometheus.NewDesc("pind_vm_required_cores",
55+
"vm required cpu cores",
56+
nil, labels0,
57+
)
58+
ent.AssignedCores = prometheus.NewDesc("pind_vm_assigned_cores",
59+
"vm assigned cpu cores",
60+
nil, labels0,
61+
)
62+
ent.AssignedCores0 = prometheus.NewDesc("pind_vm_assigned_cores0",
63+
"vm assigned cpu cores in percents, max 100%",
64+
nil, labels0,
65+
)
66+
4667
return ent, nil
4768
}
4869

@@ -57,16 +78,33 @@ func (x *Proc) Describe(ch chan<- *prometheus.Desc) {
5778
}
5879

5980
func (x *Proc) Collect(ch chan<- prometheus.Metric) {
81+
assignedCores0 := float64(0)
82+
if x.Proc.RequiredCores != 0 {
83+
assignedCores0 = (float64(x.Proc.AssignedCores) / float64(x.Proc.RequiredCores)) * 100
84+
}
85+
6086
m0 := prometheus.MustNewConstMetric(x.CPU, prometheus.GaugeValue, x.Proc.CPU)
6187
m1 := prometheus.MustNewConstMetric(x.Load, prometheus.GaugeValue, x.Proc.GetLoad0())
6288
m2 := prometheus.MustNewConstMetric(x.Numa0, prometheus.GaugeValue, float64(x.Proc.Numa0))
89+
m3 := prometheus.MustNewConstMetric(x.RequiredCoresPhys, prometheus.GaugeValue, float64(x.Proc.RequiredCoresPhys))
90+
m4 := prometheus.MustNewConstMetric(x.RequiredCores, prometheus.GaugeValue, float64(x.Proc.RequiredCores))
91+
m5 := prometheus.MustNewConstMetric(x.AssignedCores, prometheus.GaugeValue, float64(x.Proc.AssignedCores))
92+
m6 := prometheus.MustNewConstMetric(x.AssignedCores0, prometheus.GaugeValue, assignedCores0)
6393

6494
t0 := x.Proc.Time
6595
mt0 := prometheus.NewMetricWithTimestamp(t0, m0)
6696
mt1 := prometheus.NewMetricWithTimestamp(t0, m1)
6797
mt2 := prometheus.NewMetricWithTimestamp(t0, m2)
98+
mt3 := prometheus.NewMetricWithTimestamp(t0, m3)
99+
mt4 := prometheus.NewMetricWithTimestamp(t0, m4)
100+
mt5 := prometheus.NewMetricWithTimestamp(t0, m5)
101+
mt6 := prometheus.NewMetricWithTimestamp(t0, m6)
68102

69103
ch <- mt0
70104
ch <- mt1
71105
ch <- mt2
106+
ch <- mt3
107+
ch <- mt4
108+
ch <- mt5
109+
ch <- mt6
72110
}

pkg/monitoring/mon_state/state.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ type PoolNode struct {
3131
}
3232

3333
type Proc struct {
34-
VmName string
35-
Time time.Time
36-
CPU float64
37-
Load bool
38-
Numa0 int
34+
VmName string
35+
Time time.Time
36+
CPU float64
37+
Load bool
38+
Numa0 int
39+
RequiredCoresPhys int
40+
RequiredCores int
41+
AssignedCores int
3942
}
4043

4144
func NewState() *State {

pkg/pin.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ type PinProc struct {
4141
Threads map[int]*PinThread // pid -> PinThread, add/remove/update
4242
Node *PoolNodeInfo // process pinned to numa node
4343
NotSelected PinCpus // cores for not selected threads
44+
45+
RequiredCoresPhys int
46+
RequiredCores int
47+
AssignedCores int // actually pined cores count
4448
}
4549

4650
type PinThread struct {
@@ -198,6 +202,12 @@ func getThreadByPID(threads []*ThreadInfo, pid int) (*ThreadInfo, bool) {
198202
return nil, false
199203
}
200204

205+
func (x *PinProc) resetAssignedCoresMetrics() {
206+
//x.RequiredCoresPhys = 0
207+
//x.RequiredCoresPhys = 0
208+
x.AssignedCores = 0
209+
}
210+
201211
func (x *PinProc) UpdateProc(proc *ProcInfo, state *PinState) {
202212
// remove thread
203213
for pid, thread := range x.Threads {
@@ -376,6 +386,7 @@ func (x *PinState) PinIdle() error {
376386

377387
if procInfo.Node != nil {
378388
procInfo.Node = nil
389+
procInfo.resetAssignedCoresMetrics()
379390
}
380391
}
381392

@@ -417,6 +428,8 @@ func (x *PinState) PinLoad(ctx *Context) error {
417428
if cpuCount <= 0 {
418429
continue
419430
}
431+
procInfo.RequiredCoresPhys = cpuCountPhys
432+
procInfo.RequiredCores = cpuCount
420433

421434
node := procInfo.Node
422435
if node == nil {
@@ -447,6 +460,7 @@ func (x *PinState) PinLoad(ctx *Context) error {
447460
}
448461

449462
assignedCount := node.assignCores(ctx, procInfo)
463+
procInfo.AssignedCores = assignedCount
450464
if assignedCount != cpuCount {
451465
if ctx.Config.Service.Pool.PinMode == config.PinModeDelayed {
452466
// evict delayed vms to idle cores

0 commit comments

Comments
 (0)