-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (45 loc) · 1.58 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"fmt"
"net/http"
devstdout "github.com/containerscrew/devstdout/pkg"
"github.com/containerscrew/kernelsnoop/internal/core"
"github.com/containerscrew/kernelsnoop/internal/dto"
"github.com/containerscrew/kernelsnoop/internal/monitoring"
nettrack "github.com/containerscrew/kernelsnoop/internal/trackers/net_track"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
// Read config file
config, err := dto.ReadConfigFile()
if err != nil {
panic(err)
}
log := devstdout.NewLogger(
devstdout.OptionsLogger{Level: config.Log.Level, AddSource: false, LoggerType: config.Log.Type},
)
log.Info("Starting kernelsnoop")
// Create a struct to hold both log and config
contextData := &dto.ContextData{
Log: log,
Config: &config,
}
// Add the contextData struct to the context using the custom key
ctx := context.WithValue(context.Background(), dto.ContextDataKey, contextData)
// Reset memory lock limit
if err := core.RemoveMemLock(); err != nil {
log.Error(fmt.Sprintf("failed to remove memlock rlimit: %v. Consider using sudo or give necessary capabilities to the program", err))
}
// Initialize Prometheus metrics (register the metrics)
monitoring.InitPrometheus()
// Start the HTTP server for Prometheus to scrape metrics
go func() {
http.Handle("/metrics", promhttp.Handler())
log.Info("Serving Prometheus metrics on :2112/metrics")
if err := http.ListenAndServe(":2112", nil); err != nil {
log.Error(fmt.Sprintf("Error starting Prometheus metrics server: %v", err))
}
}()
nettrack.NetworkTrack(ctx)
}