Skip to content

Commit 5150e41

Browse files
committed
🎨 Add route connections
1 parent 8ba1b51 commit 5150e41

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ After=network-online.target
1616
1717
[Service]
1818
Type=simple
19-
ExecStart=/usr/local/bin/mysqlrouter_exporter --url mysqlrouter.luis.local --user luis --pass luis
19+
ExecStart=/usr/local/bin/mysqlrouter_exporter --url http://mysqlrouter.luis.local --user luis --pass luis
2020
2121
[Install]
2222
WantedBy=multi-user.target

main.go

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,46 @@ var (
8181
Name: "route_destinations",
8282
Help: "",
8383
}, []string{"name", "address", "port"})
84-
/* WIP
85-
routeConnectionsGauge = prometheus.NewGaugeVec(
84+
routeConnectionsByteFromServerGauge = prometheus.NewGaugeVec(
8685
prometheus.GaugeOpts{
87-
Name: "route_connections",
88-
Help: "",
89-
}, []string{"name", "", "port"})
90-
*/
86+
Name: "route_connections_byte_from_server",
87+
Help: "Route connections byte from server",
88+
}, []string{"name"})
89+
routeConnectionsByteToServerGauge = prometheus.NewGaugeVec(
90+
prometheus.GaugeOpts{
91+
Name: "route_connections_byte_to_server",
92+
Help: "Route connections byte to server",
93+
}, []string{"name"})
94+
routeConnectionsSourceAddressGauge = prometheus.NewGaugeVec(
95+
prometheus.GaugeOpts{
96+
Name: "route_connections_source_address",
97+
Help: "Route connections source address",
98+
}, []string{"name", "source_address"})
99+
routeConnectionsDestinationAddressGauge = prometheus.NewGaugeVec(
100+
prometheus.GaugeOpts{
101+
Name: "route_connections_destination_address",
102+
Help: "Route connections destination address",
103+
}, []string{"name", "destination_address"})
104+
routeConnectionsTimeStartedGauge = prometheus.NewGaugeVec(
105+
prometheus.GaugeOpts{
106+
Name: "route_connections_time_started",
107+
Help: "Route connections time started",
108+
}, []string{"name", "time_started"})
109+
routeConnectionsTimeConnectedToServerGauge = prometheus.NewGaugeVec(
110+
prometheus.GaugeOpts{
111+
Name: "route_connections_time_connected_to_server",
112+
Help: "Route connections time connected to server",
113+
}, []string{"name", "time_connected_to_server"})
114+
routeConnectionsTimeLastSentToServerGauge = prometheus.NewGaugeVec(
115+
prometheus.GaugeOpts{
116+
Name: "route_connections_time_last_sent_to_server",
117+
Help: "Route connections time last sent to server",
118+
}, []string{"name", "time_last_sent_to_server"})
119+
routeConnectionsTimeLastReceivedFromServerGauge = prometheus.NewGaugeVec(
120+
prometheus.GaugeOpts{
121+
Name: "route_connections_time_last_received_from_server",
122+
Help: "Route connections time last received from server",
123+
}, []string{"name", "time_last_received_from_server"})
91124
)
92125

93126
func init() {
@@ -103,6 +136,14 @@ func init() {
103136
routeBlockedHostsGauge,
104137
routeHealthGauge,
105138
routeDestinationsGauge,
139+
routeConnectionsByteFromServerGauge,
140+
routeConnectionsByteToServerGauge,
141+
routeConnectionsSourceAddressGauge,
142+
routeConnectionsDestinationAddressGauge,
143+
routeConnectionsTimeStartedGauge,
144+
routeConnectionsTimeConnectedToServerGauge,
145+
routeConnectionsTimeLastSentToServerGauge,
146+
routeConnectionsTimeLastReceivedFromServerGauge,
106147
)
107148
}
108149

@@ -196,12 +237,30 @@ func main() {
196237
routeDestinationsGauge.WithLabelValues(route.Name, d.Address, strconv.Itoa(d.Port))
197238
}
198239

199-
/* WIP
200240
rc, err := mr.GetRouteConnections(route.Name)
201241
if err != nil {
202242
panic(err)
203243
}
204-
*/
244+
if len(rc) == 0 {
245+
routeConnectionsByteFromServerGauge.WithLabelValues(route.Name).Set(0)
246+
routeConnectionsByteToServerGauge.WithLabelValues(route.Name).Set(0)
247+
routeConnectionsSourceAddressGauge.WithLabelValues(route.Name, "")
248+
routeConnectionsDestinationAddressGauge.WithLabelValues(route.Name, "")
249+
routeConnectionsTimeStartedGauge.WithLabelValues(route.Name, "")
250+
routeConnectionsTimeConnectedToServerGauge.WithLabelValues(route.Name, "")
251+
routeConnectionsTimeLastSentToServerGauge.WithLabelValues(route.Name, "")
252+
routeConnectionsTimeLastReceivedFromServerGauge.WithLabelValues(route.Name, "")
253+
}
254+
for _, c := range rc {
255+
routeConnectionsByteFromServerGauge.WithLabelValues(route.Name).Set(float64(c.BytesFromServer))
256+
routeConnectionsByteToServerGauge.WithLabelValues(route.Name).Set(float64(c.BytesToServer))
257+
routeConnectionsSourceAddressGauge.WithLabelValues(route.Name, c.SourceAddress)
258+
routeConnectionsDestinationAddressGauge.WithLabelValues(route.Name, c.DestinationAddress)
259+
routeConnectionsTimeStartedGauge.WithLabelValues(route.Name, c.TimeStarted.String())
260+
routeConnectionsTimeConnectedToServerGauge.WithLabelValues(route.Name, c.TimeConnectedToServer.String())
261+
routeConnectionsTimeLastSentToServerGauge.WithLabelValues(route.Name, c.TimeLastSentToServer.String())
262+
routeConnectionsTimeLastReceivedFromServerGauge.WithLabelValues(route.Name, c.TimeLastReceivedFromServer.String())
263+
}
205264
}
206265
time.Sleep(60 * time.Second)
207266
}

0 commit comments

Comments
 (0)