feat: implement new logic for local storage and exporters
This commit is contained in:
parent
491eeaabd7
commit
366aac9edc
11 changed files with 1170 additions and 33 deletions
39
system_metricsV2.go
Normal file
39
system_metricsV2.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (smc *SystemMetricsCollector) StartV2(ctx context.Context, storage StorageInterface, logChan chan<- LogEntry) {
|
||||
ticker := time.NewTicker(time.Duration(smc.pollInterval) * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
slog.Info("System metrics collector stopped")
|
||||
return
|
||||
case <-ticker.C:
|
||||
metrics, err := smc.collectMetrics()
|
||||
if err != nil {
|
||||
slog.Error("error collecting system metrics", "error", err)
|
||||
continue
|
||||
}
|
||||
|
||||
entry := NewLogEntry("system_metrics")
|
||||
entry.Service = "system-metrics"
|
||||
entry.LogLevel = "Info"
|
||||
entry.SystemMetrics = metrics
|
||||
|
||||
select {
|
||||
case logChan <- entry:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
slog.Warn("Log channel is full, system metrics dropped")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue