diff --git a/cmd/gateway-main.go b/cmd/gateway-main.go index ef06354b2..c5f67accd 100644 --- a/cmd/gateway-main.go +++ b/cmd/gateway-main.go @@ -187,6 +187,9 @@ func StartGateway(ctx *cli.Context, gw Gateway) { // Add healthcheck router registerHealthCheckRouter(router) + // Add server metrics router + registerMetricsRouter(router) + // Register web router when its enabled. if globalIsBrowserEnabled { logger.FatalIf(registerWebRouter(router), "Unable to configure web browser") @@ -196,6 +199,8 @@ func StartGateway(ctx *cli.Context, gw Gateway) { registerAPIRouter(router) globalHTTPServer = xhttp.NewServer([]string{gatewayAddr}, registerHandlers(router, globalHandlers...), globalTLSCertificate) + globalHTTPServer.UpdateBytesReadFunc = globalConnStats.incInputBytes + globalHTTPServer.UpdateBytesWrittenFunc = globalConnStats.incOutputBytes // Start server, automatically configures TLS if certs are available. go func() { diff --git a/cmd/metrics.go b/cmd/metrics.go index ad96fadef..1a32845fe 100644 --- a/cmd/metrics.go +++ b/cmd/metrics.go @@ -64,23 +64,7 @@ func (c *minioCollector) Describe(ch chan<- *prometheus.Desc) { // Collect is called by the Prometheus registry when collecting metrics. func (c *minioCollector) Collect(ch chan<- prometheus.Metric) { - // Fetch disk space info - objLayer := newObjectLayerFn() - // Service not initialized yet - if objLayer == nil { - return - } - s := objLayer.StorageInfo(context.Background()) - - var totalDisks, offlineDisks int - // Setting totalDisks to 1 and offlineDisks to 0 in FS mode - if s.Backend.Type == FS { - totalDisks = 1 - offlineDisks = 0 - } else { - offlineDisks = s.Backend.OfflineDisks - totalDisks = s.Backend.OfflineDisks + s.Backend.OnlineDisks - } + // Always expose network stats // Network Sent/Received Bytes ch <- prometheus.MustNewConstMetric( @@ -100,6 +84,30 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) { float64(globalConnStats.getTotalInputBytes()), ) + // Expose disk stats only if applicable + + // Fetch disk space info + objLayer := newObjectLayerFn() + // Service not initialized yet + if objLayer == nil { + return + } + s := objLayer.StorageInfo(context.Background()) + // Gateways don't provide disk info + if s.Backend.Type == Unknown { + return + } + + var totalDisks, offlineDisks int + // Setting totalDisks to 1 and offlineDisks to 0 in FS mode + if s.Backend.Type == FS { + totalDisks = 1 + offlineDisks = 0 + } else { + offlineDisks = s.Backend.OfflineDisks + totalDisks = s.Backend.OfflineDisks + s.Backend.OnlineDisks + } + // Total/Free Storage Bytes ch <- prometheus.MustNewConstMetric( prometheus.NewDesc(