2017-08-04 11:13:19 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2018-01-25 00:02:14 +00:00
|
|
|
"path"
|
2017-11-09 10:10:35 +00:00
|
|
|
"time"
|
2017-08-04 11:13:19 +00:00
|
|
|
|
2018-01-25 00:02:14 +00:00
|
|
|
"github.com/containers/storage"
|
|
|
|
crioStorage "github.com/kubernetes-incubator/cri-o/utils"
|
2017-08-04 11:13:19 +00:00
|
|
|
"golang.org/x/net/context"
|
2018-02-12 20:13:07 +00:00
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
|
2017-08-04 11:13:19 +00:00
|
|
|
)
|
|
|
|
|
2018-01-25 00:02:14 +00:00
|
|
|
func getStorageFsInfo(store storage.Store) (*pb.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 := pb.FilesystemUsage{
|
|
|
|
Timestamp: time.Now().UnixNano(),
|
2018-02-12 20:13:07 +00:00
|
|
|
FsId: &pb.FilesystemIdentifier{Mountpoint: imagesPath},
|
|
|
|
UsedBytes: &pb.UInt64Value{Value: bytesUsed},
|
|
|
|
InodesUsed: &pb.UInt64Value{Value: inodesUsed},
|
2018-01-25 00:02:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &usage, nil
|
|
|
|
}
|
|
|
|
|
2017-08-04 11:13:19 +00:00
|
|
|
// ImageFsInfo returns information of the filesystem that is used to store images.
|
2017-11-09 10:10:35 +00:00
|
|
|
func (s *Server) ImageFsInfo(ctx context.Context, req *pb.ImageFsInfoRequest) (resp *pb.ImageFsInfoResponse, err error) {
|
|
|
|
const operation = "image_fs_info"
|
|
|
|
defer func() {
|
|
|
|
recordOperation(operation, time.Now())
|
|
|
|
recordError(operation, err)
|
|
|
|
}()
|
|
|
|
|
2018-01-25 00:02:14 +00:00
|
|
|
store := s.StorageImageServer().GetStore()
|
|
|
|
fsUsage, err := getStorageFsInfo(store)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &pb.ImageFsInfoResponse{
|
|
|
|
ImageFilesystems: []*pb.FilesystemUsage{fsUsage},
|
|
|
|
}, nil
|
2017-08-04 11:13:19 +00:00
|
|
|
}
|