Add prometheus endpoint to support total Used storageInfo (#5988)

Since we deprecated Total/Free we don't need to update
prometheus with those metrics. This PR also adds support
for caching implementation.
This commit is contained in:
Harshavardhana 2018-05-30 11:30:14 -07:00 committed by kannappanr
parent dd0db526d9
commit 5282639f3c
5 changed files with 40 additions and 25 deletions

View File

@ -77,6 +77,13 @@ type cacheObjects struct {
DeleteBucketFn func(ctx context.Context, bucket string) error DeleteBucketFn func(ctx context.Context, bucket string) error
} }
// CacheStorageInfo - represents total, free capacity of
// underlying cache storage.
type CacheStorageInfo struct {
Total uint64 // Total cache disk space.
Free uint64 // Free cache available space.
}
// CacheObjectLayer implements primitives for cache object API layer. // CacheObjectLayer implements primitives for cache object API layer.
type CacheObjectLayer interface { type CacheObjectLayer interface {
// Bucket operations. // Bucket operations.
@ -98,7 +105,7 @@ type CacheObjectLayer interface {
CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []CompletePart) (objInfo ObjectInfo, err error) CompleteMultipartUpload(ctx context.Context, bucket, object, uploadID string, uploadedParts []CompletePart) (objInfo ObjectInfo, err error)
// Storage operations. // Storage operations.
StorageInfo(ctx context.Context) StorageInfo StorageInfo(ctx context.Context) CacheStorageInfo
} }
// backendDownError returns true if err is due to backend failure or faulty disk if in server mode // backendDownError returns true if err is due to backend failure or faulty disk if in server mode
@ -771,7 +778,7 @@ func (c cacheObjects) CompleteMultipartUpload(ctx context.Context, bucket, objec
} }
// StorageInfo - returns underlying storage statistics. // StorageInfo - returns underlying storage statistics.
func (c cacheObjects) StorageInfo(ctx context.Context) (storageInfo StorageInfo) { func (c cacheObjects) StorageInfo(ctx context.Context) (cInfo CacheStorageInfo) {
var total, free uint64 var total, free uint64
for _, cfs := range c.cache.cfs { for _, cfs := range c.cache.cfs {
if cfs == nil { if cfs == nil {
@ -783,12 +790,10 @@ func (c cacheObjects) StorageInfo(ctx context.Context) (storageInfo StorageInfo)
total += info.Total total += info.Total
free += info.Free free += info.Free
} }
storageInfo = StorageInfo{ return CacheStorageInfo{
Total: total, Total: total,
Free: free, Free: free,
} }
storageInfo.Backend.Type = FS
return storageInfo
} }
// DeleteBucket - marks bucket to be deleted from cache if bucket is deleted from backend. // DeleteBucket - marks bucket to be deleted from cache if bucket is deleted from backend.

View File

@ -84,6 +84,28 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
float64(globalConnStats.getTotalInputBytes()), float64(globalConnStats.getTotalInputBytes()),
) )
// Expose cache stats only if available
cacheObjLayer := newCacheObjectsFn()
if cacheObjLayer != nil {
cs := cacheObjLayer.StorageInfo(context.Background())
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName("minio", "disk", "cache_storage_bytes"),
"Total cache capacity on current Minio server instance",
nil, nil),
prometheus.GaugeValue,
float64(cs.Total),
)
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName("minio", "disk", "cache_storage_free_bytes"),
"Total cache available on current Minio server instance",
nil, nil),
prometheus.GaugeValue,
float64(cs.Free),
)
}
// Expose disk stats only if applicable // Expose disk stats only if applicable
// Fetch disk space info // Fetch disk space info
@ -92,7 +114,9 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
if objLayer == nil { if objLayer == nil {
return return
} }
s := objLayer.StorageInfo(context.Background()) s := objLayer.StorageInfo(context.Background())
// Gateways don't provide disk info // Gateways don't provide disk info
if s.Backend.Type == Unknown { if s.Backend.Type == Unknown {
return return
@ -108,22 +132,14 @@ func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {
totalDisks = s.Backend.OfflineDisks + s.Backend.OnlineDisks totalDisks = s.Backend.OfflineDisks + s.Backend.OnlineDisks
} }
// Total/Free Storage Bytes // Total disk usage by current Minio server instance
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc( prometheus.NewDesc(
prometheus.BuildFQName("minio", "disk", "storage_bytes"), prometheus.BuildFQName("minio", "disk", "storage_used_bytes"),
"Total disk storage available to current Minio server instance", "Total disk storage used by current Minio server instance",
nil, nil), nil, nil),
prometheus.GaugeValue, prometheus.GaugeValue,
float64(s.Total), float64(s.Used),
)
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName("minio", "disk", "storage_free_bytes"),
"Total free disk storage available to current Minio server instance",
nil, nil),
prometheus.GaugeValue,
float64(s.Free),
) )
// Minio Total Disk/Offline Disk // Minio Total Disk/Offline Disk

View File

@ -39,9 +39,7 @@ const (
// StorageInfo - represents total capacity of underlying storage. // StorageInfo - represents total capacity of underlying storage.
type StorageInfo struct { type StorageInfo struct {
Total uint64 // Total disk space. Used uint64 // Used total used per tenant.
Free uint64 // Free available space.
Used uint64 // Used total used per tenant.
// Backend type. // Backend type.
Backend struct { Backend struct {

View File

@ -188,7 +188,7 @@ func printStorageInfo(storageInfo StorageInfo) {
} }
} }
func printCacheStorageInfo(storageInfo StorageInfo) { func printCacheStorageInfo(storageInfo CacheStorageInfo) {
msg := fmt.Sprintf("%s %s Free, %s Total", colorBlue("Cache Capacity:"), msg := fmt.Sprintf("%s %s Free, %s Total", colorBlue("Cache Capacity:"),
humanize.IBytes(uint64(storageInfo.Free)), humanize.IBytes(uint64(storageInfo.Free)),
humanize.IBytes(uint64(storageInfo.Total))) humanize.IBytes(uint64(storageInfo.Total)))

View File

@ -1786,10 +1786,6 @@ func TestWebObjectLayerFaultyDisks(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed %v", err) t.Fatalf("Failed %v", err)
} }
// if Total size is 0 it indicates faulty disk.
if storageInfoReply.StorageInfo.Total != 0 {
t.Fatalf("Should get zero Total size since disks are faulty ")
}
// Test authorization of Web.Download // Test authorization of Web.Download
req, err = http.NewRequest("GET", "/minio/download/bucket/object?token="+authorization, nil) req, err = http.NewRequest("GET", "/minio/download/bucket/object?token="+authorization, nil)