-
Notifications
You must be signed in to change notification settings - Fork 1k
/
image_fs_info.go
44 lines (36 loc) · 1.13 KB
/
image_fs_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package server
import (
"context"
"path"
"time"
"github.com/containers/storage"
crioStorage "github.com/cri-o/cri-o/utils"
types "k8s.io/cri-api/pkg/apis/runtime/v1"
)
func getStorageFsInfo(store storage.Store) (*types.FilesystemUsage, error) {
rootPath := store.GraphRoot()
storageDriver := store.GraphDriverName()
imagesPath := path.Join(rootPath, storageDriver+"-images")
bytesUsed, inodesUsed, err := crioStorage.GetDiskUsageStats(imagesPath)
if err != nil {
return nil, err
}
usage := types.FilesystemUsage{
Timestamp: time.Now().UnixNano(),
FsId: &types.FilesystemIdentifier{Mountpoint: imagesPath},
UsedBytes: &types.UInt64Value{Value: bytesUsed},
InodesUsed: &types.UInt64Value{Value: inodesUsed},
}
return &usage, nil
}
// ImageFsInfo returns information of the filesystem that is used to store images.
func (s *Server) ImageFsInfo(context.Context) (*types.ImageFsInfoResponse, error) {
store := s.StorageImageServer().GetStore()
fsUsage, err := getStorageFsInfo(store)
if err != nil {
return nil, err
}
return &types.ImageFsInfoResponse{
ImageFilesystems: []*types.FilesystemUsage{fsUsage},
}, nil
}