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
79
main.go
79
main.go
|
|
@ -21,25 +21,60 @@ func init() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
cfg, err := LoadConfig()
|
||||
cfg, err := LoadConfigV2()
|
||||
if err != nil {
|
||||
slog.Error("error loading configuration", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
slog.Info("TIXEL System Monitor started")
|
||||
|
||||
es, err := NewElasticsearchClient(cfg.Elasticsearch)
|
||||
if err != nil {
|
||||
slog.Error("elasticsearch client error", "error", err)
|
||||
var storage StorageInterface
|
||||
if cfg.LocalStorage.Enable {
|
||||
sqliteStorage, err := NewSQLiteStorage(cfg.LocalStorage.DBPath)
|
||||
if err != nil {
|
||||
slog.Error("failed to initialize SQLite storage", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
storage = sqliteStorage
|
||||
defer storage.Close()
|
||||
slog.Info("SQLite storage initialized", "path", cfg.LocalStorage.DBPath)
|
||||
} else {
|
||||
slog.Error("Local storage is disabled, but it's required for the new architecture")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := TestElasticsearchConnection(es); err != nil {
|
||||
slog.Error("elasticsearch connection test failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
var exportManager *ExportManager
|
||||
if cfg.Export.Enabled {
|
||||
exportConfig := ExportManagerConfig{
|
||||
BatchSize: cfg.Export.BatchSize,
|
||||
ExportInterval: cfg.Export.ExportInterval,
|
||||
RetryAttempts: cfg.Export.RetryAttempts,
|
||||
RetryBackoff: cfg.Export.RetryBackoff,
|
||||
HealthCheckInterval: cfg.Export.HealthCheckInterval,
|
||||
}
|
||||
|
||||
slog.Info("Elasticsearch connection successful")
|
||||
exportManager = NewExportManager(storage, exportConfig)
|
||||
|
||||
if cfg.Elasticsearch.Enabled {
|
||||
esExporter, err := NewElasticsearchExporterV2(cfg.Elasticsearch)
|
||||
if err != nil {
|
||||
slog.Error("failed to create Elasticsearch exporter", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := esExporter.HealthCheck(context.Background()); err != nil {
|
||||
slog.Error("Elasticsearch health check failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
exportManager.RegisterExporter("elasticsearch", esExporter)
|
||||
slog.Info("Elasticsearch exporter registered")
|
||||
}
|
||||
|
||||
// Add more exporters here in the future
|
||||
// exportManager.RegisterExporter("checkmk", checkmkExporter)
|
||||
// exportManager.RegisterExporter("grafana", grafanaExporter)
|
||||
}
|
||||
|
||||
logChan := make(chan LogEntry, 1000)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
|
@ -47,6 +82,21 @@ func main() {
|
|||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
processor := NewLogProcessor(storage)
|
||||
processor.Start(ctx, logChan)
|
||||
}()
|
||||
|
||||
if exportManager != nil {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
exportManager.Start(ctx)
|
||||
}()
|
||||
}
|
||||
|
||||
for _, service := range cfg.Services {
|
||||
if !service.Enabled {
|
||||
slog.Info("Service deactivated, skipping...", "service", service.Name)
|
||||
|
|
@ -88,23 +138,16 @@ func main() {
|
|||
go func() {
|
||||
defer wg.Done()
|
||||
collector := NewSystemMetricsCollector(cfg.SystemMetrics, cfg.PollIntervalSeconds)
|
||||
collector.Start(ctx, es, cfg.Elasticsearch.Index)
|
||||
collector.StartV2(ctx, storage, logChan)
|
||||
}()
|
||||
slog.Info("Started collecting System-Metrics")
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
processor := NewLogProcessor(es, cfg.Elasticsearch.Index)
|
||||
processor.Start(ctx, logChan)
|
||||
}()
|
||||
|
||||
if cfg.WebService.Enabled {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
webService := NewWebService(cfg, es)
|
||||
webService := NewWebServiceV2(cfg, storage)
|
||||
if err := webService.Start(ctx); err != nil {
|
||||
slog.Error("web service error", "error", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue