5
5
"net/http"
6
6
_ "net/http/pprof"
7
7
"os"
8
- "path"
9
8
"runtime"
10
9
"strings"
11
10
@@ -14,6 +13,7 @@ import (
14
13
"github.com/coroot/coroot-node-agent/flags"
15
14
"github.com/coroot/coroot-node-agent/logs"
16
15
"github.com/coroot/coroot-node-agent/node"
16
+ "github.com/coroot/coroot-node-agent/proc"
17
17
"github.com/coroot/coroot-node-agent/profiling"
18
18
"github.com/coroot/coroot-node-agent/prom"
19
19
"github.com/coroot/coroot-node-agent/tracing"
@@ -65,8 +65,8 @@ func uname() (string, string, error) {
65
65
}
66
66
67
67
func machineID () string {
68
- for _ , p := range []string {"etc/machine-id" , "var/lib/dbus/machine-id" , "sys/devices/virtual/dmi/id/product_uuid" } {
69
- payload , err := os .ReadFile (path . Join ( "/proc/1/root" , p ))
68
+ for _ , p := range []string {"/ etc/machine-id" , "/ var/lib/dbus/machine-id" , "/ sys/devices/virtual/dmi/id/product_uuid" } {
69
+ payload , err := os .ReadFile (proc . HostPath ( p ))
70
70
if err != nil {
71
71
klog .Warningln ("failed to read machine-id:" , err )
72
72
continue
@@ -78,6 +78,15 @@ func machineID() string {
78
78
return ""
79
79
}
80
80
81
+ func systemUUID () string {
82
+ payload , err := os .ReadFile (proc .HostPath ("/sys/devices/virtual/dmi/id/product_uuid" ))
83
+ if err != nil {
84
+ klog .Warningln ("failed to read system-uuid:" , err )
85
+ return ""
86
+ }
87
+ return strings .TrimSpace (string (payload ))
88
+ }
89
+
81
90
func whitelistNodeExternalNetworks () {
82
91
netdevs , err := node .NetDevices ()
83
92
if err != nil {
@@ -119,11 +128,13 @@ func main() {
119
128
whitelistNodeExternalNetworks ()
120
129
121
130
machineId := machineID ()
131
+ systemUuid := systemUUID ()
132
+
122
133
tracing .Init (machineId , hostname , version )
123
134
logs .Init (machineId , hostname , version )
124
135
125
136
registry := prometheus .NewRegistry ()
126
- registerer := prometheus .WrapRegistererWith (prometheus.Labels {"machine_id" : machineId }, registry )
137
+ registerer := prometheus .WrapRegistererWith (prometheus.Labels {"machine_id" : machineId , "system_uuid" : systemUuid }, registry )
127
138
128
139
registerer .MustRegister (info ("node_agent_info" , version ))
129
140
0 commit comments