Skip to content

Commit 571f531

Browse files
vlorincguvenc
authored andcommitted
add file-prefix flag to make dpdk telemetry socket more configurable at the start of exporter
1 parent 93d76b7 commit 571f531

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cli/dpservice-exporter/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ var (
3535

3636
func main() {
3737
var err error
38-
var hostnameFlag string
38+
var hostnameFlag, filePrefix string
3939
var exporterPort uint64
4040
var exporterAddr netip.AddrPort
4141

4242
flag.StringVar(&hostnameFlag, "hostname", "", "Hostname to use (defaults to current hostname)")
43+
flag.StringVar(&filePrefix, "file-prefix", "rte", "File prefix of dpservice dpdk telemetry socket.")
4344
flag.IntVar(&pollIntervalFlag, "poll-interval", 20, "Polling interval in seconds")
4445
flag.Uint64Var(&exporterPort, "port", 9064, "Port on which exporter will be running.")
4546
flag.Uint64Var(&grpcPort, "grpc-port", 1337, "Port on which dpservice is running.")
@@ -68,8 +69,12 @@ func main() {
6869
uid, err := getUID()
6970
if err != nil {
7071
log.Warningf("Could not get UID, assuming root: %v", err)
71-
} else if uid != 0 {
72-
metrics.SocketPath = fmt.Sprintf("/run/user/%d/dpdk/rte/dpdk_telemetry.v2", uid)
72+
}
73+
// Set DPDK telemetry socket path based on UID
74+
if uid == 0 {
75+
metrics.SocketPath = fmt.Sprintf("/var/run/dpdk/%s/dpdk_telemetry.v2", filePrefix)
76+
} else {
77+
metrics.SocketPath = fmt.Sprintf("/run/user/%d/dpdk/%s/dpdk_telemetry.v2", uid, filePrefix)
7378
}
7479

7580
r := prometheus.NewRegistry()
@@ -162,11 +167,11 @@ func getHostname(hostnameFlag string) (string, error) {
162167
func getUID() (int, error) {
163168
user, err := user.Current()
164169
if err != nil {
165-
return -1, fmt.Errorf("could not get user: %v", err)
170+
return 0, fmt.Errorf("could not get user: %v", err)
166171
}
167172
uid, err := strconv.Atoi(user.Uid)
168173
if err != nil {
169-
return -1, fmt.Errorf("could not get uid: %v", err)
174+
return 0, fmt.Errorf("could not get uid: %v", err)
170175
}
171176
return uid, nil
172177
}

0 commit comments

Comments
 (0)