Skip to content

Commit d0951f7

Browse files
committed
Refactor
1 parent 5228eee commit d0951f7

File tree

4 files changed

+241
-202
lines changed

4 files changed

+241
-202
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ mysqlrouter_exporter
22
=====================
33
[![Build Status](https://cloud.drone.io/api/badges/rluisr/mysqlrouter_exporter/status.svg)](https://cloud.drone.io/rluisr/mysqlrouter_exporter)
44

5+
Supported MySQL Router version
6+
-------------------------------
7+
8.0.16 - 8.0.20
8+
59
Usage
610
-----
7-
1. Download binary from [release](https://github.com/rluisr/mysqlrouter_exporter/releases).
8-
2. Move to /usr/local/bin/
9-
3. Add systemd script.
10-
4. Start
11+
1. Enable REST API on your MySQL Router [here](https://lefred.be/content/mysqlrouter-8-0-17-and-the-rest-api/)
12+
2. Download binary from [release](https://github.com/rluisr/mysqlrouter_exporter/releases).
13+
3. Move to /usr/local/bin/
14+
4. Add systemd script.
15+
5. Start
1116
```
1217
[Unit]
1318
Description=mysqlrouter-exporter
@@ -31,8 +36,7 @@ You must set these environment variables:
3136
- `MYSQLROUTER_EXPORTER_PASS:` Password for REST API
3237

3338

34-
Default exporter listen port is `49152`.
35-
If you want change it use `MYSQLROUTER_EXPORTER_PORT`.
39+
Default exporter listen port is `49152`. If you want change it, use flag `--port`.
3640

3741
Prometheus configuration
3842
-------------------------

gauges.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package main
2+
3+
import (
4+
"github.com/prometheus/client_golang/prometheus"
5+
"github.com/prometheus/client_golang/prometheus/promauto"
6+
)
7+
8+
var (
9+
routerStatusGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
10+
Namespace: nameSpace,
11+
Name: "router_status",
12+
Help: "MySQL Router information",
13+
}, []string{"process_id", "product_edition", "time_started", "version", "hostname"})
14+
metadataGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
15+
Namespace: nameSpace,
16+
Name: "metadata",
17+
Help: "metadata list",
18+
}, []string{"name"})
19+
metadataConfigGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
20+
Namespace: nameSpace,
21+
Name: "metadata_config",
22+
Help: "metadata config",
23+
}, []string{"name", "cluster_name", "time_refresh_in_ms", "group_replication_id"})
24+
metadataConfigNodeGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
25+
Namespace: nameSpace,
26+
Name: "metadata_config_node",
27+
Help: "metadata config node",
28+
}, []string{"name", "router_host", "cluster_name", "hostname", "port"})
29+
metadataStatusGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
30+
Namespace: nameSpace,
31+
Name: "metadata_status",
32+
Help: "metadata status",
33+
}, []string{"name", "refresh_failed", "time_last_refresh_succeeded", "last_refresh_hostname", "last_refresh_port"})
34+
routeGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
35+
Namespace: nameSpace,
36+
Name: "route",
37+
Help: "route name",
38+
}, []string{"name"})
39+
routeActiveConnectionsGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
40+
Namespace: nameSpace,
41+
Name: "route_active_connections",
42+
Help: "route active connections",
43+
}, []string{"name", "router_hostname"})
44+
routeTotalConnectionsGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
45+
Namespace: nameSpace,
46+
Name: "route_total_connections",
47+
Help: "route total connections",
48+
}, []string{"name", "router_hostname"})
49+
routeBlockedHostsGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
50+
Namespace: nameSpace,
51+
Name: "route_blocked_hosts",
52+
Help: "route blocked_hosts",
53+
}, []string{"name", "router_hostname"})
54+
routeHealthGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
55+
Namespace: nameSpace,
56+
Name: "route_health",
57+
Help: "0: not active, 1: active",
58+
}, []string{"name", "router_hostname"})
59+
routeDestinationsGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
60+
Namespace: nameSpace,
61+
Name: "route_destinations",
62+
Help: "",
63+
}, []string{"name", "address", "port"})
64+
routeConnectionsByteFromServerGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
65+
Name: "route_connections_byte_from_server",
66+
Help: "Route connections byte from server",
67+
}, []string{"name", "router_hostname", "source_address", "destination_address"})
68+
routeConnectionsByteToServerGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
69+
Name: "route_connections_byte_to_server",
70+
Help: "Route connections byte to server",
71+
}, []string{"name", "router_hostname", "source_address", "destination_address"})
72+
routeConnectionsTimeStartedGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
73+
Name: "route_connections_time_started",
74+
Help: "Route connections time started",
75+
}, []string{"name", "router_hostname", "source_address", "destination_address"})
76+
routeConnectionsTimeConnectedToServerGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
77+
Name: "route_connections_time_connected_to_server",
78+
Help: "Route connections time connected to server",
79+
}, []string{"name", "router_hostname", "source_address", "destination_address"})
80+
routeConnectionsTimeLastSentToServerGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
81+
Name: "route_connections_time_last_sent_to_server",
82+
Help: "Route connections time last sent to server",
83+
}, []string{"name", "router_hostname", "source_address", "destination_address"})
84+
routeConnectionsTimeLastReceivedFromServerGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
85+
Name: "route_connections_time_last_received_from_server",
86+
Help: "Route connections time last received from server",
87+
}, []string{"name", "router_hostname", "source_address", "destination_address"})
88+
)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/rluisr/mysqlrouter_exporter
22

3-
go 1.12
3+
go 1.14
44

55
require (
66
github.com/koron/go-dproxy v1.2.1

0 commit comments

Comments
 (0)