2018-04-19 01:01:42 +02:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
2018-04-19 01:01:42 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2020-03-25 06:40:45 +01:00
|
|
|
"strings"
|
2020-05-04 07:35:40 +02:00
|
|
|
"sync/atomic"
|
2020-03-25 06:40:45 +01:00
|
|
|
"time"
|
2018-04-19 01:01:42 +02:00
|
|
|
|
2018-05-09 05:10:55 +02:00
|
|
|
"github.com/minio/minio/cmd/logger"
|
2018-04-19 01:01:42 +02:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2018-05-09 05:10:55 +02:00
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
2018-04-19 01:01:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
httpRequestsDuration = prometheus.NewHistogramVec(
|
|
|
|
prometheus.HistogramOpts{
|
2019-10-23 06:01:14 +02:00
|
|
|
Name: "s3_ttfb_seconds",
|
2019-04-09 20:39:42 +02:00
|
|
|
Help: "Time taken by requests served by current MinIO server instance",
|
2019-10-23 06:01:14 +02:00
|
|
|
Buckets: []float64{.05, .1, .25, .5, 1, 2.5, 5, 10},
|
2018-04-19 01:01:42 +02:00
|
|
|
},
|
2019-10-23 06:01:14 +02:00
|
|
|
[]string{"api"},
|
2018-04-19 01:01:42 +02:00
|
|
|
)
|
2019-06-26 19:36:54 +02:00
|
|
|
minioVersionInfo = prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: "minio",
|
|
|
|
Name: "version_info",
|
|
|
|
Help: "Version of current MinIO server instance",
|
|
|
|
},
|
|
|
|
[]string{
|
|
|
|
// current version
|
|
|
|
"version",
|
|
|
|
// commit-id of the current version
|
|
|
|
"commit",
|
|
|
|
},
|
|
|
|
)
|
2018-04-19 01:01:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
prometheus.MustRegister(httpRequestsDuration)
|
2018-05-09 05:10:55 +02:00
|
|
|
prometheus.MustRegister(newMinioCollector())
|
2019-06-26 19:36:54 +02:00
|
|
|
prometheus.MustRegister(minioVersionInfo)
|
2018-04-19 01:01:42 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 05:10:55 +02:00
|
|
|
// newMinioCollector describes the collector
|
|
|
|
// and returns reference of minioCollector
|
|
|
|
// It creates the Prometheus Description which is used
|
|
|
|
// to define metric and help string
|
|
|
|
func newMinioCollector() *minioCollector {
|
|
|
|
return &minioCollector{
|
2019-04-09 20:39:42 +02:00
|
|
|
desc: prometheus.NewDesc("minio_stats", "Statistics exposed by MinIO server", nil, nil),
|
2018-05-09 05:10:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// minioCollector is the Custom Collector
|
|
|
|
type minioCollector struct {
|
|
|
|
desc *prometheus.Desc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Describe sends the super-set of all possible descriptors of metrics
|
|
|
|
func (c *minioCollector) Describe(ch chan<- *prometheus.Desc) {
|
|
|
|
ch <- c.desc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect is called by the Prometheus registry when collecting metrics.
|
|
|
|
func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
|
2018-04-19 01:01:42 +02:00
|
|
|
|
2019-06-26 19:36:54 +02:00
|
|
|
// Expose MinIO's version information
|
2019-10-23 06:01:14 +02:00
|
|
|
minioVersionInfo.WithLabelValues(Version, CommitID).Set(float64(1.0))
|
2019-06-26 19:36:54 +02:00
|
|
|
|
2020-03-25 06:40:45 +01:00
|
|
|
storageMetricsPrometheus(ch)
|
|
|
|
networkMetricsPrometheus(ch)
|
|
|
|
httpMetricsPrometheus(ch)
|
2020-05-13 17:15:26 +02:00
|
|
|
cacheMetricsPrometheus(ch)
|
2020-03-25 06:40:45 +01:00
|
|
|
gatewayMetricsPrometheus(ch)
|
|
|
|
healingMetricsPrometheus(ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
// collects healing specific metrics for MinIO instance in Prometheus specific format
|
|
|
|
// and sends to given channel
|
|
|
|
func healingMetricsPrometheus(ch chan<- prometheus.Metric) {
|
|
|
|
if !globalIsXL {
|
2019-10-23 06:01:14 +02:00
|
|
|
return
|
|
|
|
}
|
2020-03-25 06:40:45 +01:00
|
|
|
bgSeq, exists := globalBackgroundHealState.getHealSequenceByToken(bgHealingUUID)
|
|
|
|
if !exists {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
healMetricsNamespace := "self_heal"
|
2018-05-09 05:10:55 +02:00
|
|
|
|
2020-03-25 06:40:45 +01:00
|
|
|
dur := time.Duration(-1)
|
|
|
|
if !bgSeq.lastHealActivity.IsZero() {
|
|
|
|
dur = time.Since(bgSeq.lastHealActivity)
|
|
|
|
}
|
2019-10-23 06:01:14 +02:00
|
|
|
|
2020-02-20 04:51:33 +01:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName(healMetricsNamespace, "time", "since_last_activity"),
|
|
|
|
"Time elapsed (in nano seconds) since last self healing activity. This is set to -1 until initial self heal activity",
|
2020-02-20 04:51:33 +01:00
|
|
|
nil, nil),
|
|
|
|
prometheus.GaugeValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(dur),
|
2020-02-20 04:51:33 +01:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
for k, v := range bgSeq.getScannedItemsMap() {
|
2019-10-23 06:01:14 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName(healMetricsNamespace, "objects", "scanned"),
|
|
|
|
"Objects scanned in current self healing run",
|
|
|
|
[]string{"type"}, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.GaugeValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(v), string(k),
|
2019-10-23 06:01:14 +02:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
}
|
|
|
|
for k, v := range bgSeq.getHealedItemsMap() {
|
2019-10-23 06:01:14 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName(healMetricsNamespace, "objects", "healed"),
|
|
|
|
"Objects healed in current self healing run",
|
|
|
|
[]string{"type"}, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.GaugeValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(v), string(k),
|
2019-10-23 06:01:14 +02:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
}
|
|
|
|
for k, v := range bgSeq.gethealFailedItemsMap() {
|
|
|
|
// healFailedItemsMap stores the endpoint and volume state separated by comma,
|
|
|
|
// split the fields and pass to channel at correct index
|
|
|
|
s := strings.Split(k, ",")
|
2019-10-23 06:01:14 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName(healMetricsNamespace, "objects", "heal_failed"),
|
|
|
|
"Objects for which healing failed in current self healing run",
|
|
|
|
[]string{"mount_path", "volume_status"}, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.GaugeValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(v), string(s[0]), string(s[1]),
|
2019-10-23 06:01:14 +02:00
|
|
|
)
|
2018-05-30 06:43:46 +02:00
|
|
|
}
|
2020-03-25 06:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// collects gateway specific metrics for MinIO instance in Prometheus specific format
|
|
|
|
// and sends to given channel
|
|
|
|
func gatewayMetricsPrometheus(ch chan<- prometheus.Metric) {
|
|
|
|
if !globalIsGateway || (globalGatewayName != "s3" && globalGatewayName != "azure" && globalGatewayName != "gcs") {
|
|
|
|
return
|
|
|
|
}
|
2018-05-30 06:43:46 +02:00
|
|
|
|
2020-03-25 06:40:45 +01:00
|
|
|
objLayer := newObjectLayerWithoutSafeModeFn()
|
|
|
|
// Service not initialized yet
|
|
|
|
if objLayer == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:30:02 +02:00
|
|
|
m, err := objLayer.GetMetrics(GlobalContext)
|
2020-03-25 06:40:45 +01:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-05-30 06:43:46 +02:00
|
|
|
|
2018-05-09 05:10:55 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("gateway", globalGatewayName, "bytes_received"),
|
|
|
|
"Total number of bytes received by current MinIO Gateway "+globalGatewayName+" backend",
|
2018-05-09 05:10:55 +02:00
|
|
|
nil, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.CounterValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(m.GetBytesReceived()),
|
2018-05-09 05:10:55 +02:00
|
|
|
)
|
2019-04-05 06:21:50 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("gateway", globalGatewayName, "bytes_sent"),
|
|
|
|
"Total number of bytes sent by current MinIO Gateway to "+globalGatewayName+" backend",
|
2019-04-05 06:21:50 +02:00
|
|
|
nil, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.CounterValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(m.GetBytesSent()),
|
|
|
|
)
|
|
|
|
s := m.GetRequests()
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("gateway", globalGatewayName, "requests"),
|
|
|
|
"Total number of requests made to "+globalGatewayName+" by current MinIO Gateway",
|
|
|
|
[]string{"method"}, nil),
|
|
|
|
prometheus.CounterValue,
|
2020-05-04 07:35:40 +02:00
|
|
|
float64(atomic.LoadUint64(&s.Get)),
|
2020-03-25 06:40:45 +01:00
|
|
|
http.MethodGet,
|
2019-04-05 06:21:50 +02:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("gateway", globalGatewayName, "requests"),
|
|
|
|
"Total number of requests made to "+globalGatewayName+" by current MinIO Gateway",
|
|
|
|
[]string{"method"}, nil),
|
|
|
|
prometheus.CounterValue,
|
2020-05-04 07:35:40 +02:00
|
|
|
float64(atomic.LoadUint64(&s.Head)),
|
2020-03-25 06:40:45 +01:00
|
|
|
http.MethodHead,
|
|
|
|
)
|
2020-04-01 21:52:31 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("gateway", globalGatewayName, "requests"),
|
|
|
|
"Total number of requests made to "+globalGatewayName+" by current MinIO Gateway",
|
|
|
|
[]string{"method"}, nil),
|
|
|
|
prometheus.CounterValue,
|
2020-05-04 07:35:40 +02:00
|
|
|
float64(atomic.LoadUint64(&s.Put)),
|
2020-04-01 21:52:31 +02:00
|
|
|
http.MethodPut,
|
|
|
|
)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("gateway", globalGatewayName, "requests"),
|
|
|
|
"Total number of requests made to "+globalGatewayName+" by current MinIO Gateway",
|
|
|
|
[]string{"method"}, nil),
|
|
|
|
prometheus.CounterValue,
|
2020-05-04 07:35:40 +02:00
|
|
|
float64(atomic.LoadUint64(&s.Post)),
|
2020-04-01 21:52:31 +02:00
|
|
|
http.MethodPost,
|
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// collects cache metrics for MinIO server in Prometheus specific format
|
|
|
|
// and sends to given channel
|
|
|
|
func cacheMetricsPrometheus(ch chan<- prometheus.Metric) {
|
|
|
|
cacheObjLayer := newCachedObjectLayerFn()
|
|
|
|
// Service not initialized yet
|
|
|
|
if cacheObjLayer == nil {
|
|
|
|
return
|
|
|
|
}
|
2019-04-05 06:21:50 +02:00
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("cache", "hits", "total"),
|
|
|
|
"Total number of disk cache hits in current MinIO instance",
|
2019-04-05 06:21:50 +02:00
|
|
|
nil, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.CounterValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(cacheObjLayer.CacheStats().getHits()),
|
2019-04-05 06:21:50 +02:00
|
|
|
)
|
2018-05-09 05:10:55 +02:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("cache", "misses", "total"),
|
|
|
|
"Total number of disk cache misses in current MinIO instance",
|
2018-05-09 05:10:55 +02:00
|
|
|
nil, nil),
|
2019-10-23 06:01:14 +02:00
|
|
|
prometheus.CounterValue,
|
2020-03-25 06:40:45 +01:00
|
|
|
float64(cacheObjLayer.CacheStats().getMisses()),
|
2018-05-09 05:10:55 +02:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("cache", "data", "served"),
|
|
|
|
"Total number of bytes served from cache of current MinIO instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(cacheObjLayer.CacheStats().getBytesServed()),
|
|
|
|
)
|
|
|
|
}
|
2019-10-23 06:01:14 +02:00
|
|
|
|
2020-03-25 06:40:45 +01:00
|
|
|
// collects http metrics for MinIO server in Prometheus specific format
|
|
|
|
// and sends to given channel
|
|
|
|
func httpMetricsPrometheus(ch chan<- prometheus.Metric) {
|
2019-12-06 08:16:06 +01:00
|
|
|
httpStats := globalHTTPStats.toServerHTTPStats()
|
|
|
|
|
2019-10-23 06:01:14 +02:00
|
|
|
for api, value := range httpStats.CurrentS3Requests.APIStats {
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("s3", "requests", "current"),
|
|
|
|
"Total number of running s3 requests in current MinIO server instance",
|
|
|
|
[]string{"api"}, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(value),
|
|
|
|
api,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
for api, value := range httpStats.TotalS3Requests.APIStats {
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("s3", "requests", "total"),
|
|
|
|
"Total number of s3 requests in current MinIO server instance",
|
|
|
|
[]string{"api"}, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(value),
|
|
|
|
api,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
for api, value := range httpStats.TotalS3Errors.APIStats {
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("s3", "errors", "total"),
|
|
|
|
"Total number of s3 errors in current MinIO server instance",
|
|
|
|
[]string{"api"}, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(value),
|
|
|
|
api,
|
|
|
|
)
|
|
|
|
}
|
2020-03-25 06:40:45 +01:00
|
|
|
}
|
2019-10-23 06:01:14 +02:00
|
|
|
|
2020-03-25 06:40:45 +01:00
|
|
|
// collects network metrics for MinIO server in Prometheus specific format
|
|
|
|
// and sends to given channel
|
|
|
|
func networkMetricsPrometheus(ch chan<- prometheus.Metric) {
|
|
|
|
connStats := globalConnStats.toServerConnStats()
|
|
|
|
|
|
|
|
// Network Sent/Received Bytes (internode)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("internode", "tx", "bytes_total"),
|
|
|
|
"Total number of bytes sent to the other peer nodes by current MinIO server instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(connStats.TotalOutputBytes),
|
|
|
|
)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("internode", "rx", "bytes_total"),
|
|
|
|
"Total number of internode bytes received by current MinIO server instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(connStats.TotalInputBytes),
|
|
|
|
)
|
|
|
|
|
|
|
|
// Network Sent/Received Bytes (Outbound)
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("s3", "tx", "bytes_total"),
|
|
|
|
"Total number of s3 bytes sent by current MinIO server instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(connStats.S3OutputBytes),
|
|
|
|
)
|
|
|
|
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("s3", "rx", "bytes_total"),
|
|
|
|
"Total number of s3 bytes received by current MinIO server instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.CounterValue,
|
|
|
|
float64(connStats.S3InputBytes),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// collects storage metrics for MinIO server in Prometheus specific format
|
|
|
|
// and sends to given channel
|
|
|
|
func storageMetricsPrometheus(ch chan<- prometheus.Metric) {
|
|
|
|
objLayer := newObjectLayerWithoutSafeModeFn()
|
|
|
|
// Service not initialized yet
|
|
|
|
if objLayer == nil {
|
|
|
|
return
|
2019-12-06 08:16:06 +01:00
|
|
|
}
|
|
|
|
|
2020-03-25 06:40:45 +01:00
|
|
|
// Fetch disk space info
|
2020-04-09 18:30:02 +02:00
|
|
|
storageInfo := objLayer.StorageInfo(GlobalContext, true)
|
2020-03-25 06:40:45 +01:00
|
|
|
|
|
|
|
offlineDisks := storageInfo.Backend.OfflineDisks
|
|
|
|
onlineDisks := storageInfo.Backend.OnlineDisks
|
|
|
|
totalDisks := offlineDisks.Merge(onlineDisks)
|
|
|
|
|
|
|
|
// MinIO Offline Disks per node
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("minio", "disks", "offline"),
|
|
|
|
"Total number of offline disks in current MinIO server instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(offlineDisks.Sum()),
|
|
|
|
)
|
|
|
|
|
|
|
|
// MinIO Total Disks per node
|
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
|
|
|
prometheus.BuildFQName("minio", "disks", "total"),
|
|
|
|
"Total number of disks for current MinIO server instance",
|
|
|
|
nil, nil),
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(totalDisks.Sum()),
|
|
|
|
)
|
|
|
|
|
|
|
|
for i := 0; i < len(storageInfo.Total); i++ {
|
|
|
|
mountPath, total, free := storageInfo.MountPaths[i], storageInfo.Total[i],
|
|
|
|
storageInfo.Available[i]
|
|
|
|
|
|
|
|
// Total disk usage by the disk
|
2019-12-06 08:16:06 +01:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("disk", "storage", "used"),
|
|
|
|
"Total disk storage used on the disk",
|
|
|
|
[]string{"disk"}, nil),
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(total-free),
|
|
|
|
mountPath,
|
2019-12-06 08:16:06 +01:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
|
|
|
|
// Total available space in the disk
|
2019-12-07 06:51:52 +01:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("disk", "storage", "available"),
|
|
|
|
"Total available space left on the disk",
|
|
|
|
[]string{"disk"}, nil),
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(free),
|
|
|
|
mountPath,
|
2019-12-07 06:51:52 +01:00
|
|
|
)
|
2020-03-25 06:40:45 +01:00
|
|
|
|
|
|
|
// Total storage space of the disk
|
2019-12-07 06:51:52 +01:00
|
|
|
ch <- prometheus.MustNewConstMetric(
|
|
|
|
prometheus.NewDesc(
|
2020-03-25 06:40:45 +01:00
|
|
|
prometheus.BuildFQName("disk", "storage", "total"),
|
|
|
|
"Total space on the disk",
|
|
|
|
[]string{"disk"}, nil),
|
|
|
|
prometheus.GaugeValue,
|
|
|
|
float64(total),
|
|
|
|
mountPath,
|
2019-12-07 06:51:52 +01:00
|
|
|
)
|
2019-12-06 08:16:06 +01:00
|
|
|
}
|
2018-04-19 01:01:42 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 05:10:55 +02:00
|
|
|
func metricsHandler() http.Handler {
|
2019-09-22 16:57:12 +02:00
|
|
|
|
2018-05-09 05:10:55 +02:00
|
|
|
registry := prometheus.NewRegistry()
|
|
|
|
|
2019-06-26 19:36:54 +02:00
|
|
|
err := registry.Register(minioVersionInfo)
|
2020-04-09 18:30:02 +02:00
|
|
|
logger.LogIf(GlobalContext, err)
|
2019-06-26 19:36:54 +02:00
|
|
|
|
|
|
|
err = registry.Register(httpRequestsDuration)
|
2020-04-09 18:30:02 +02:00
|
|
|
logger.LogIf(GlobalContext, err)
|
2018-05-09 05:10:55 +02:00
|
|
|
|
|
|
|
err = registry.Register(newMinioCollector())
|
2020-04-09 18:30:02 +02:00
|
|
|
logger.LogIf(GlobalContext, err)
|
2018-05-09 05:10:55 +02:00
|
|
|
|
|
|
|
gatherers := prometheus.Gatherers{
|
|
|
|
prometheus.DefaultGatherer,
|
|
|
|
registry,
|
|
|
|
}
|
|
|
|
// Delegate http serving to Prometheus client library, which will call collector.Collect.
|
|
|
|
return promhttp.InstrumentMetricHandler(
|
|
|
|
registry,
|
|
|
|
promhttp.HandlerFor(gatherers,
|
|
|
|
promhttp.HandlerOpts{
|
|
|
|
ErrorHandling: promhttp.ContinueOnError,
|
|
|
|
}),
|
|
|
|
)
|
2019-09-22 16:57:12 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// AuthMiddleware checks if the bearer token is valid and authorized.
|
|
|
|
func AuthMiddleware(h http.Handler) http.Handler {
|
|
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
claims, _, authErr := webRequestAuthenticate(r)
|
|
|
|
if authErr != nil || !claims.VerifyIssuer("prometheus", true) {
|
|
|
|
w.WriteHeader(http.StatusForbidden)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
h.ServeHTTP(w, r)
|
|
|
|
})
|
2018-04-19 01:01:42 +02:00
|
|
|
}
|