Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 748fddc

Browse files
committed
fix command parsing and a parameter for polling interval
Signed-off-by: Guvenc Gulce <[email protected]>
1 parent 031c6e2 commit 748fddc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net"
1010
"net/http"
1111
"os"
12+
"strings"
1213
"time"
1314

1415
"github.com/prometheus/client_golang/prometheus"
@@ -86,7 +87,9 @@ func queryTelemetry(conn net.Conn, command string, response interface{}) {
8687
log.Fatalf("Failed to read response from %s: %v", socketPath, err)
8788
}
8889
responseBuffer.Write(respBytes[:n])
89-
if bytes.Contains(respBytes, []byte(command[:len(command)-2])) {
90+
parts := strings.SplitN(command, ",", 2)
91+
command = parts[0]
92+
if bytes.Contains(respBytes, []byte(command)) {
9093
break
9194
}
9295
}
@@ -125,7 +128,6 @@ func updateMetrics(conn net.Conn, hostname string) {
125128
for graphNodeName, callCount := range dpserviceCallCount.GraphCallCnt.Node_0_to_255 {
126129
promMetricsCallCount.With(prometheus.Labels{"node_name": hostname, "graph_node": graphNodeName}).Set(callCount)
127130
}
128-
129131
}
130132

131133
func main() {
@@ -143,6 +145,7 @@ func main() {
143145

144146
var host string
145147
hostnameFlag := flag.String("hostname", "", "Hostname to use")
148+
pollIntervalFlag := flag.Int("poll-interval", 20, "Polling interval in seconds")
146149
flag.Parse()
147150

148151
if *hostnameFlag == "" {
@@ -166,7 +169,7 @@ func main() {
166169
go func() {
167170
for {
168171
updateMetrics(conn, host)
169-
time.Sleep(5 * time.Second)
172+
time.Sleep(time.Duration(*pollIntervalFlag) * time.Second)
170173
}
171174
}()
172175

0 commit comments

Comments
 (0)