Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,39 @@ You can also set it as a flag.
Collector Flags
----------------

Name | Default | Description
------------------------------------------------------------|-----------|-------------
skip.collect.route.connections.byte_from_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
skip.collect.route.connections.byte_to_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
skip.collect.route.connections.time_started | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
skip.collect.route.connections.time_connected_to_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
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.
skip.collect.route.connections.time_received_from_server | false | Skip Collect metrics from route connections. Set the flag if you getting high CPU usage.
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)

Name | Default | Description
-------------------------------------------------------|-----------|-------------
collect.metadata.status | false | Collect metrics from metadata status. CPU usage will increase.
collect.route.connections.byte_from_server | false | Collect metrics from route connections. CPU usage will increase.
collect.route.connections.byte_to_server | false | Collect metrics from route connections. CPU usage will increase.
collect.route.connections.time_started | false | Collect metrics from route connections. CPU usage will increase.
collect.route.connections.time_connected_to_server | false | Collect metrics from route connections. CPU usage will increase.
collect.route.connections.time_last_sent_to_server | false | Collect metrics from route connections. CPU usage will increase.
collect.route.connections.time_received_from_server | false | Collect metrics from route connections. CPU usage will increase.

```
Usage:
mysqlrouter_exporter [OPTIONS]

Application Options:
--url= MySQL Router Rest API URL [$MYSQLROUTER_EXPORTER_URL]
--user= Username for REST API [$MYSQLROUTER_EXPORTER_USER]
--pass= Password for REST API [$MYSQLROUTER_EXPORTER_PASS]
-p, --listen-port= Listen port (default: 49152)
-k, --skip-tls-verify Skip TLS Verification
--skip.collect.route.connections.byte_from_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
usage.
--skip.collect.route.connections.byte_to_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
usage.
--skip.collect.route.connections.time_started Skip Collect metrics from route connections. Set the flag if you getting high CPU
usage.
--skip.collect.route.connections.time_connected_to_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
usage.
--skip.collect.route.connections.time_last_sent_to_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
usage.
--skip.collect.route.connections.time_received_from_server Skip Collect metrics from route connections. Set the flag if you getting high CPU
usage.
-v, --version Show version
--url= MySQL Router Rest API URL [$MYSQLROUTER_EXPORTER_URL]
--user= Username for REST API [$MYSQLROUTER_EXPORTER_USER]
--pass= Password for REST API [$MYSQLROUTER_EXPORTER_PASS]
-p, --listen-port= Listen port (default: 49152)
-k, --skip-tls-verify Skip TLS Verification
--collect.metadata.status Collect metrics from metadata status. CPU usage will increase.
--collect.route.connections.byte_from_server Collect metrics from route connections. CPU usage will increase.
--collect.route.connections.byte_to_server Collect metrics from route connections. CPU usage will increase.
--collect.route.connections.time_started Collect metrics from route connections. CPU usage will increase.
--collect.route.connections.time_connected_to_server Collect metrics from route connections. CPU usage will increase.
--collect.route.connections.time_last_sent_to_server Collect metrics from route connections. CPU usage will increase.
--collect.route.connections.time_received_from_server Collect metrics from route connections. CPU usage will increase.
-v, --version Show version

Help Options:
-h, --help Show this help message
-h, --help Show this help message
```

Prometheus configuration
Expand Down
39 changes: 21 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ var args struct {
ListenPort int `short:"p" long:"listen-port" default:"49152" description:"Listen port"`
SkipTLSVerify bool `short:"k" long:"skip-tls-verify" description:"Skip TLS Verification"`

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."`
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."`
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."`
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."`
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."`
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."`
CollectMetadataStatus bool `short:"" long:"collect.metadata.status" description:"Collect metrics from metadata status. CPU usage will increase."`
CollectRouteConnectionsByteFromServer bool `short:"" long:"collect.route.connections.byte_from_server" description:"Collect metrics from route connections. CPU usage will increase."`
CollectRouteConnectionsByteToServer bool `short:"" long:"collect.route.connections.byte_to_server" description:"Collect metrics from route connections. CPU usage will increase."`
CollectRouteConnectionsTimeStarted bool `short:"" long:"collect.route.connections.time_started" description:"Collect metrics from route connections. CPU usage will increase."`
CollectRouteConnectionsTimeConnectedToServer bool `short:"" long:"collect.route.connections.time_connected_to_server" description:"Collect metrics from route connections. CPU usage will increase."`
CollectRouteConnectionsTimeLastSentToServer bool `short:"" long:"collect.route.connections.time_last_sent_to_server" description:"Collect metrics from route connections. CPU usage will increase."`
CollectRouteConnectionsTimeReceivedFromServer bool `short:"" long:"collect.route.connections.time_received_from_server" description:"Collect metrics from route connections. CPU usage will increase."`

Version bool `short:"v" long:"version" description:"Show version"`
}
Expand Down Expand Up @@ -93,12 +94,14 @@ func collectMetrics() {
}

// status
metadataStatus, gmsErr := mysqlRouterClient.GetMetadataStatus(metadata.Name)
if gmsErr != nil {
writeError(gmsErr)
return
if args.CollectMetadataStatus {
metadataStatus, gmsErr := mysqlRouterClient.GetMetadataStatus(metadata.Name)
if gmsErr != nil {
writeError(gmsErr)
return
}
metadataStatusGauge.WithLabelValues(metadata.Name, strconv.Itoa(metadataStatus.RefreshFailed), metadataStatus.TimeLastRefreshSucceeded.String(), metadataStatus.LastRefreshHostname, strconv.Itoa(metadataStatus.LastRefreshPort))
}
metadataStatusGauge.WithLabelValues(metadata.Name, strconv.Itoa(metadataStatus.RefreshFailed), metadataStatus.TimeLastRefreshSucceeded.String(), metadataStatus.LastRefreshHostname, strconv.Itoa(metadataStatus.LastRefreshPort))
}

// routes
Expand Down Expand Up @@ -146,22 +149,22 @@ func collectMetrics() {
return
}
for _, routeConnection := range routeConnections {
if !args.SkipCollectRouteConnectionsByteFromServer {
if args.CollectRouteConnectionsByteFromServer {
routeConnectionsByteFromServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.BytesFromServer))
}
if !args.SkipCollectRouteConnectionsByteToServer {
if args.CollectRouteConnectionsByteToServer {
routeConnectionsByteToServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.BytesToServer))
}
if !args.SkipCollectRouteConnectionsTimeStarted {
if args.CollectRouteConnectionsTimeStarted {
routeConnectionsTimeStartedGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeStarted.Unix() * 1000)) // nolint
}
if !args.SkipCollectRouteConnectionsTimeConnectedToServer {
if args.CollectRouteConnectionsTimeConnectedToServer {
routeConnectionsTimeConnectedToServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeConnectedToServer.Unix() * 1000)) //nolint
}
if !args.SkipCollectRouteConnectionsTimeLastSentToServer {
if args.CollectRouteConnectionsTimeLastSentToServer {
routeConnectionsTimeLastSentToServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeLastSentToServer.Unix() * 1000)) // nolint
}
if !args.SkipCollectRouteConnectionsTimeReceivedFromServer {
if args.CollectRouteConnectionsTimeReceivedFromServer {
routeConnectionsTimeLastReceivedFromServerGauge.WithLabelValues(route.Name, router.Hostname, routeConnection.SourceAddress, routeConnection.DestinationAddress).Set(float64(routeConnection.TimeLastReceivedFromServer.Unix() * 1000)) // nolint
}
}
Expand All @@ -175,7 +178,7 @@ func writeError(err error) {
func main() {
_, err := flags.Parse(&args)
if err != nil {
os.Exit(1)
log.Fatalln(err)
}
if args.Version {
fmt.Printf("version: %s commit: %s date: %s\n", version, commit, date)
Expand Down