mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 02:37:24 +08:00
optimized(host): use goroutine to start ContainerStatsProvider (#21683)
This commit is contained in:
@@ -112,7 +112,7 @@ func (host *SHostService) RunService() {
|
||||
log.Fatalf("Guest manager Bootstrap %s", err)
|
||||
}
|
||||
// hostmetrics after guestmanager bootstrap
|
||||
hostmetrics.Init(hostInstance.GetContainerStatsProvider())
|
||||
hostmetrics.Init(hostInstance)
|
||||
hostmetrics.Start()
|
||||
fsdriver.Init("")
|
||||
|
||||
|
||||
@@ -240,9 +240,13 @@ func (h *SHostInfo) Init(ctx context.Context) error {
|
||||
if err := h.initContainerCPUMap(h.sysinfo.Topology); err != nil {
|
||||
return errors.Wrap(err, "init container cpu map")
|
||||
}
|
||||
if err := h.startContainerStatsProvider(h.cri); err != nil {
|
||||
return errors.Wrap(err, "start container stats provider")
|
||||
}
|
||||
go func() {
|
||||
if err := h.startContainerStatsProvider(h.cri); err != nil {
|
||||
log.Warningf("start container stats provider error: %v", err)
|
||||
} else {
|
||||
log.Infof("container stats provider started")
|
||||
}
|
||||
}()
|
||||
if fileutils2.Exists(options.HostOptions.ContainerSystemCpufreqSimulateConfigFile) {
|
||||
if err := h.getContainerCpufreqSimulateConfig(); err != nil {
|
||||
return errors.Wrap(err, "getContainerCpuSimulateConfig")
|
||||
|
||||
@@ -55,9 +55,13 @@ type SHostMetricsCollector struct {
|
||||
|
||||
var hostMetricsCollector *SHostMetricsCollector
|
||||
|
||||
func Init(csp stats.ContainerStatsProvider) {
|
||||
type IHostInfo interface {
|
||||
GetContainerStatsProvider() stats.ContainerStatsProvider
|
||||
}
|
||||
|
||||
func Init(hostInfo IHostInfo) {
|
||||
if hostMetricsCollector == nil {
|
||||
hostMetricsCollector = NewHostMetricsCollector(csp)
|
||||
hostMetricsCollector = NewHostMetricsCollector(hostInfo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,27 +147,27 @@ func (m *SHostMetricsCollector) collectReportData() string {
|
||||
return m.guestMonitor.CollectReportData()
|
||||
}
|
||||
|
||||
func NewHostMetricsCollector(csp stats.ContainerStatsProvider) *SHostMetricsCollector {
|
||||
func NewHostMetricsCollector(hostInfo IHostInfo) *SHostMetricsCollector {
|
||||
return &SHostMetricsCollector{
|
||||
ReportInterval: options.HostOptions.ReportInterval,
|
||||
waitingReportData: make([]string, 0),
|
||||
guestMonitor: NewGuestMonitorCollector(csp),
|
||||
guestMonitor: NewGuestMonitorCollector(hostInfo),
|
||||
}
|
||||
}
|
||||
|
||||
type SGuestMonitorCollector struct {
|
||||
monitors map[string]*SGuestMonitor
|
||||
prevPids map[string]int
|
||||
prevReportData map[string]*GuestMetrics
|
||||
containerStatsProvider stats.ContainerStatsProvider
|
||||
monitors map[string]*SGuestMonitor
|
||||
prevPids map[string]int
|
||||
prevReportData map[string]*GuestMetrics
|
||||
hostInfo IHostInfo
|
||||
}
|
||||
|
||||
func NewGuestMonitorCollector(csp stats.ContainerStatsProvider) *SGuestMonitorCollector {
|
||||
func NewGuestMonitorCollector(hostInfo IHostInfo) *SGuestMonitorCollector {
|
||||
return &SGuestMonitorCollector{
|
||||
monitors: make(map[string]*SGuestMonitor, 0),
|
||||
prevPids: make(map[string]int, 0),
|
||||
prevReportData: make(map[string]*GuestMetrics, 0),
|
||||
containerStatsProvider: csp,
|
||||
monitors: make(map[string]*SGuestMonitor, 0),
|
||||
prevPids: make(map[string]int, 0),
|
||||
prevReportData: make(map[string]*GuestMetrics, 0),
|
||||
hostInfo: hostInfo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +223,12 @@ func (s *SGuestMonitorCollector) GetGuests() map[string]*SGuestMonitor {
|
||||
case compute.HYPERVISOR_POD:
|
||||
if podStats == nil {
|
||||
var err error
|
||||
podStats, err = s.containerStatsProvider.ListPodCPUAndMemoryStats()
|
||||
csp := s.hostInfo.GetContainerStatsProvider()
|
||||
if csp == nil {
|
||||
log.Warningf("container stats provider is not ready")
|
||||
return true
|
||||
}
|
||||
podStats, err = csp.ListPodCPUAndMemoryStats()
|
||||
if err != nil {
|
||||
log.Errorf("ListPodCPUAndMemoryStats: %s", err)
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user