@@ -11,6 +11,7 @@ import (
11
11
"os"
12
12
"sort"
13
13
"strconv"
14
+ "strings"
14
15
"time"
15
16
16
17
"github.com/ddosify/alaz/config"
@@ -36,6 +37,8 @@ var NodeID string
36
37
37
38
// set from ldflags
38
39
var tag string
40
+ var kernelVersion string
41
+ var cloudProvider CloudProvider
39
42
40
43
func init () {
41
44
MonitoringID = os .Getenv ("MONITORING_ID" )
@@ -52,6 +55,67 @@ func init() {
52
55
log .Logger .Fatal ().Msg ("tag is not set" )
53
56
}
54
57
log .Logger .Info ().Str ("tag" , tag ).Msg ("alaz tag" )
58
+
59
+ kernelVersion = extractKernelVersion ()
60
+ cloudProvider = getCloudProvider ()
61
+ }
62
+
63
+ func extractKernelVersion () string {
64
+ // Path to the /proc/version file
65
+ filePath := "/proc/version"
66
+ file , err := os .Open (filePath )
67
+ if err != nil {
68
+ log .Logger .Fatal ().AnErr ("error" , err ).Msgf ("Unable to open file %s" , filePath )
69
+ }
70
+
71
+ // Read the content of the file
72
+ content , err := io .ReadAll (file )
73
+ if err != nil {
74
+ log .Logger .Fatal ().AnErr ("error" , err ).Msgf ("Unable to read file %s" , filePath )
75
+ }
76
+
77
+ // Convert the content to a string
78
+ versionInfo := string (content )
79
+
80
+ // Split the versionInfo string into lines
81
+ lines := strings .Split (versionInfo , "\n " )
82
+
83
+ // Extract the kernel version from the first line
84
+ // Assuming the kernel version is the first word in the first line
85
+ if len (lines ) > 0 {
86
+ fields := strings .Fields (lines [0 ])
87
+ if len (fields ) > 2 {
88
+ return fields [2 ]
89
+ }
90
+ }
91
+
92
+ return "Unable to extract kernel version"
93
+ }
94
+
95
+ type CloudProvider string
96
+
97
+ const (
98
+ CloudProviderAWS CloudProvider = "AWS"
99
+ CloudProviderGCP CloudProvider = "GCP"
100
+ CloudProviderAzure CloudProvider = "Azure"
101
+ CloudProviderDigitalOcean CloudProvider = "DigitalOcean"
102
+ CloudProviderUnknown CloudProvider = ""
103
+ )
104
+
105
+ func getCloudProvider () CloudProvider {
106
+ if vendor , err := os .ReadFile ("/sys/class/dmi/id/board_vendor" ); err == nil {
107
+ switch strings .TrimSpace (string (vendor )) {
108
+ case "Amazon EC2" :
109
+ return CloudProviderAWS
110
+ case "Google" :
111
+ return CloudProviderGCP
112
+ case "Microsoft Corporation" :
113
+ return CloudProviderAzure
114
+ case "DigitalOcean" :
115
+ return CloudProviderDigitalOcean
116
+ }
117
+ }
118
+ return CloudProviderUnknown
55
119
}
56
120
57
121
var resourceBatchSize int64 = 50
@@ -527,7 +591,7 @@ func (b *BackendDS) PersistContainer(c Container, eventType string) error {
527
591
return nil
528
592
}
529
593
530
- func (b * BackendDS ) SendHealthCheck (ebpf bool , metrics bool ) {
594
+ func (b * BackendDS ) SendHealthCheck (ebpf bool , metrics bool , k8sVersion string ) {
531
595
t := time .NewTicker (10 * time .Second )
532
596
defer t .Stop ()
533
597
@@ -546,6 +610,15 @@ func (b *BackendDS) SendHealthCheck(ebpf bool, metrics bool) {
546
610
EbpfEnabled : ebpf ,
547
611
MetricsEnabled : metrics ,
548
612
},
613
+ Telemetry : struct {
614
+ KernelVersion string `json:"kernel_version"`
615
+ K8sVersion string `json:"k8s_version"`
616
+ CloudProvider string `json:"cloud_provider"`
617
+ }{
618
+ KernelVersion : kernelVersion ,
619
+ K8sVersion : k8sVersion ,
620
+ CloudProvider : string (cloudProvider ),
621
+ },
549
622
}
550
623
}
551
624
0 commit comments