Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace old cpu stats #559

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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