Skip to content

Commit 6a22196

Browse files
authored
Merge pull request #12 from rluisr/feature/default-skip-flag
[Breaking] Change the flag. It doesn't collect some metrics default.
2 parents c31878c + 0bd5624 commit 6a22196

File tree

2 files changed

+46
-45
lines changed

2 files changed

+46
-45
lines changed

README.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,39 @@ You can also set it as a flag.
4646
Collector Flags
4747
----------------
4848

49-
Name | Default | Description
50-
------------------------------------------------------------|-----------|-------------
51-
skip.collect.route.connections.byte_from_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
52-
skip.collect.route.connections.byte_to_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
53-
skip.collect.route.connections.time_started | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
54-
skip.collect.route.connections.time_connected_to_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
55-
skip.collect.route.connections.time_last_sent_to_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
56-
skip.collect.route.connections.time_received_from_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
49+
mysqlrouter_exporter can all get metrics. [MySQL Router REST API Reference](https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-rest-api-reference.html)
50+
51+
Name | Default | Description
52+
-------------------------------------------------------|-----------|-------------
53+
collect.metadata.status | false | Collect metrics from metadata status. CPU usage will increase.
54+
collect.route.connections.byte_from_server | false | Collect metrics from route connections. CPU usage will increase.
55+
collect.route.connections.byte_to_server | false | Collect metrics from route connections. CPU usage will increase.
56+
collect.route.connections.time_started | false | Collect metrics from route connections. CPU usage will increase.
57+
collect.route.connections.time_connected_to_server | false | Collect metrics from route connections. CPU usage will increase.
58+
collect.route.connections.time_last_sent_to_server | false | Collect metrics from route connections. CPU usage will increase.
59+
collect.route.connections.time_received_from_server | false | Collect metrics from route connections. CPU usage will increase.
5760

5861
```
5962
Usage:
6063
mysqlrouter_exporter [OPTIONS]
6164
6265
Application Options:
63-
--url= MySQL Router Rest API URL [$MYSQLROUTER_EXPORTER_URL]
64-
--user= Username for REST API [$MYSQLROUTER_EXPORTER_USER]
65-
--pass= Password for REST API [$MYSQLROUTER_EXPORTER_PASS]
66-
-p, --listen-port= Listen port (default: 49152)
67-
-k, --skip-tls-verify Skip TLS Verification
68-
--skip.collect.route.connections.byte_from_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
69-
usage.
70-
--skip.collect.route.connections.byte_to_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
71-
usage.
72-
--skip.collect.route.connections.time_started Skip Collect metrics from route connections. Set the flag if you getting high CPU
73-
usage.
74-
--skip.collect.route.connections.time_connected_to_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
75-
usage.
76-
--skip.collect.route.connections.time_last_sent_to_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
77-
usage.
78-
--skip.collect.route.connections.time_received_from_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
79-
usage.
80-
-v, --version Show version
66+
--url= MySQL Router Rest API URL [$MYSQLROUTER_EXPORTER_URL]
67+
--user= Username for REST API [$MYSQLROUTER_EXPORTER_USER]
68+
--pass= Password for REST API [$MYSQLROUTER_EXPORTER_PASS]
69+
-p, --listen-port= Listen port (default: 49152)
70+
-k, --skip-tls-verify Skip TLS Verification
71+
--collect.metadata.status Collect metrics from metadata status. CPU usage will increase.
72+
--collect.route.connections.byte_from_server Collect metrics from route connections. CPU usage will increase.
73+
--collect.route.connections.byte_to_server Collect metrics from route connections. CPU usage will increase.
74+
--collect.route.connections.time_started Collect metrics from route connections. CPU usage will increase.
75+
--collect.route.connections.time_connected_to_server Collect metrics from route connections. CPU usage will increase.
76+
--collect.route.connections.time_last_sent_to_server Collect metrics from route connections. CPU usage will increase.
77+
--collect.route.connections.time_received_from_server Collect metrics from route connections. CPU usage will increase.
78+
-v, --version Show version
8179
8280
Help Options:
83-
-h, --help Show this help message
81+
-h, --help Show this help message
8482
```
8583

8684
Prometheus configuration

main.go

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ var args struct {
2828
ListenPort int `short:"p" long:"listen-port" default:"49152" description:"Listen port"`
2929
SkipTLSVerify bool `short:"k" long:"skip-tls-verify" description:"Skip TLS Verification"`
3030

31-
SkipCollectRouteConnectionsByteFromServer bool `short:"" long:"skip.collect.route.connections.byte_from_server" description:"Skip Collect metrics from route connections. Set the flag if you getting high CPU usage."`
32-
SkipCollectRouteConnectionsByteToServer bool `short:"" long:"skip.collect.route.connections.byte_to_server" description:"Skip Collect metrics from route connections. Set the flag if you getting high CPU usage."`
33-
SkipCollectRouteConnectionsTimeStarted bool `short:"" long:"skip.collect.route.connections.time_started" description:"Skip Collect metrics from route connections. Set the flag if you getting high CPU usage."`
34-
SkipCollectRouteConnectionsTimeConnectedToServer bool `short:"" long:"skip.collect.route.connections.time_connected_to_server" description:"Skip Collect metrics from route connections. Set the flag if you getting high CPU usage."`
35-
SkipCollectRouteConnectionsTimeLastSentToServer bool `short:"" long:"skip.collect.route.connections.time_last_sent_to_server" description:"Skip Collect metrics from route connections. Set the flag if you getting high CPU usage."`
36-
SkipCollectRouteConnectionsTimeReceivedFromServer bool `short:"" long:"skip.collect.route.connections.time_received_from_server" description:"Skip Collect metrics from route connections. Set the flag if you getting high CPU usage."`
31+
CollectMetadataStatus bool `short:"" long:"collect.metadata.status" description:"Collect metrics from metadata status. CPU usage will increase."`
32+
CollectRouteConnectionsByteFromServer bool `short:"" long:"collect.route.connections.byte_from_server" description:"Collect metrics from route connections. CPU usage will increase."`
33+
CollectRouteConnectionsByteToServer bool `short:"" long:"collect.route.connections.byte_to_server" description:"Collect metrics from route connections. CPU usage will increase."`
34+
CollectRouteConnectionsTimeStarted bool `short:"" long:"collect.route.connections.time_started" description:"Collect metrics from route connections. CPU usage will increase."`
35+
CollectRouteConnectionsTimeConnectedToServer bool `short:"" long:"collect.route.connections.time_connected_to_server" description:"Collect metrics from route connections. CPU usage will increase."`
36+
CollectRouteConnectionsTimeLastSentToServer bool `short:"" long:"collect.route.connections.time_last_sent_to_server" description:"Collect metrics from route connections. CPU usage will increase."`
37+
CollectRouteConnectionsTimeReceivedFromServer bool `short:"" long:"collect.route.connections.time_received_from_server" description:"Collect metrics from route connections. CPU usage will increase."`
3738

3839
Version bool `short:"v" long:"version" description:"Show version"`
3940
}
@@ -93,12 +94,14 @@ func collectMetrics() {
9394
}
9495

9596
// status
96-
metadataStatus, gmsErr := mysqlRouterClient.GetMetadataStatus(metadata.Name)
97-
if gmsErr != nil {
98-
writeError(gmsErr)
99-
return
97+
if args.CollectMetadataStatus {
98+
metadataStatus, gmsErr := mysqlRouterClient.GetMetadataStatus(metadata.Name)
99+
if gmsErr != nil {
100+
writeError(gmsErr)
101+
return
102+
}
103+
metadataStatusGauge.WithLabelValues(metadata.Name, strconv.Itoa(metadataStatus.RefreshFailed), metadataStatus.TimeLastRefreshSucceeded.String(), metadataStatus.LastRefreshHostname, strconv.Itoa(metadataStatus.LastRefreshPort))
100104
}
101-
metadataStatusGauge.WithLabelValues(metadata.Name, strconv.Itoa(metadataStatus.RefreshFailed), metadataStatus.TimeLastRefreshSucceeded.String(), metadataStatus.LastRefreshHostname, strconv.Itoa(metadataStatus.LastRefreshPort))
102105
}
103106

104107
// routes
@@ -146,22 +149,22 @@ func collectMetrics() {
146149
return
147150
}
148151
for _, routeConnection := range routeConnections {
149-
if !args.SkipCollectRouteConnectionsByteFromServer {
152+
if args.CollectRouteConnectionsByteFromServer {
150153
routeConnectionsByteFromServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.BytesFromServer))
151154
}
152-
if !args.SkipCollectRouteConnectionsByteToServer {
155+
if args.CollectRouteConnectionsByteToServer {
153156
routeConnectionsByteToServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.BytesToServer))
154157
}
155-
if !args.SkipCollectRouteConnectionsTimeStarted {
158+
if args.CollectRouteConnectionsTimeStarted {
156159
routeConnectionsTimeStartedGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeStarted.Unix() * 1000)) // nolint
157160
}
158-
if !args.SkipCollectRouteConnectionsTimeConnectedToServer {
161+
if args.CollectRouteConnectionsTimeConnectedToServer {
159162
routeConnectionsTimeConnectedToServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeConnectedToServer.Unix() * 1000)) //nolint
160163
}
161-
if !args.SkipCollectRouteConnectionsTimeLastSentToServer {
164+
if args.CollectRouteConnectionsTimeLastSentToServer {
162165
routeConnectionsTimeLastSentToServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeLastSentToServer.Unix() * 1000)) // nolint
163166
}
164-
if !args.SkipCollectRouteConnectionsTimeReceivedFromServer {
167+
if args.CollectRouteConnectionsTimeReceivedFromServer {
165168
routeConnectionsTimeLastReceivedFromServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeLastReceivedFromServer.Unix() * 1000)) // nolint
166169
}
167170
}
@@ -175,7 +178,7 @@ func writeError(err error) {
175178
func main() {
176179
_, err := flags.Parse(&args)
177180
if err != nil {
178-
os.Exit(1)
181+
log.Fatalln(err)
179182
}
180183
if args.Version {
181184
fmt.Printf("version: %s commit: %s date: %s\n", version, commit, date)

0 commit comments

Comments
 (0)