Skip to content

Commit

Permalink
Replace old cpu stats
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 committed Dec 11, 2023
1 parent c23c430 commit 2baea76
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions pkg/stats/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ type Monitor struct {
cpuCostConfig config.CPUCostConfig

promCPULoad prometheus.Gauge
promCPULoadV2 prometheus.Gauge
promProcCPULoad *prometheus.GaugeVec
requestGauge *prometheus.GaugeVec

cpuStats *utils.CPUStats
procStats *utils.CPUStats
cpuStats *utils.CPUStats

pendingCPUs atomic.Float64

Expand All @@ -63,15 +61,8 @@ func (m *Monitor) Start(
canAcceptRequest func() float64,
procUpdate func(map[int]float64) map[string]float64,
) error {
cpuStats, err := utils.NewCPUStats(func(idle float64) {
m.promCPULoad.Set(1 - idle/m.cpuStats.NumCPU())
})
if err != nil {
return err
}

procStats, err := utils.NewProcCPUStats(func(idle float64, usage map[int]float64) {
m.promCPULoadV2.Set(1 - idle/m.cpuStats.NumCPU())
m.promCPULoad.Set(1 - idle/m.cpuStats.NumCPU())
egressUsage := procUpdate(usage)
for egressID, cpuUsage := range egressUsage {
m.promProcCPULoad.With(prometheus.Labels{"egress_id": egressID}).Set(cpuUsage)
Expand All @@ -86,9 +77,7 @@ func (m *Monitor) Start(
if err != nil {
return err
}

m.cpuStats = cpuStats
m.procStats = procStats
m.cpuStats = procStats

if err = m.checkCPUConfig(); err != nil {
return err
Expand All @@ -115,13 +104,6 @@ func (m *Monitor) Start(
ConstLabels: prometheus.Labels{"node_id": conf.NodeID, "node_type": "EGRESS", "cluster_id": conf.ClusterID},
})

m.promCPULoadV2 = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "livekit",
Subsystem: "node",
Name: "cpu_load_v2",
ConstLabels: prometheus.Labels{"node_id": conf.NodeID, "cluster_id": conf.ClusterID},
})

m.promProcCPULoad = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "livekit",
Subsystem: "egress",
Expand All @@ -136,7 +118,7 @@ func (m *Monitor) Start(
ConstLabels: prometheus.Labels{"node_id": conf.NodeID, "cluster_id": conf.ClusterID},
}, []string{"type"})

prometheus.MustRegister(promNodeAvailable, promCanAcceptRequest, m.promCPULoad, m.promCPULoadV2, m.promProcCPULoad, m.requestGauge)
prometheus.MustRegister(promNodeAvailable, promCanAcceptRequest, m.promCPULoad, m.promProcCPULoad, m.requestGauge)

return nil
}
Expand Down

0 comments on commit 2baea76

Please sign in to comment.