set metric_source to du or fsquota accordingly
This commit is contained in:
parent
6611c36372
commit
3967f03bb1
@ -17,11 +17,8 @@ limitations under the License.
|
||||
package volume
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
servermetrics "k8s.io/kubernetes/pkg/kubelet/server/metrics"
|
||||
"k8s.io/kubernetes/pkg/volume/util/fs"
|
||||
)
|
||||
|
||||
@ -44,9 +41,6 @@ func NewMetricsDu(path string) MetricsProvider {
|
||||
// and gathering filesystem info for the Volume path.
|
||||
// See MetricsProvider.GetMetrics
|
||||
func (md *metricsDu) GetMetrics() (*Metrics, error) {
|
||||
startTime := time.Now()
|
||||
defer servermetrics.CollectVolumeStatCalDuration("du", startTime)
|
||||
|
||||
metrics := &Metrics{Time: metav1.Now()}
|
||||
if md.path == "" {
|
||||
return metrics, NewNoPathDefinedError()
|
||||
|
@ -24,9 +24,11 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
servermetrics "k8s.io/kubernetes/pkg/kubelet/server/metrics"
|
||||
"k8s.io/kubernetes/pkg/volume/util/fsquota"
|
||||
)
|
||||
|
||||
@ -71,9 +73,13 @@ func DiskUsage(path string) (UsageInfo, error) {
|
||||
// First check whether the quota system knows about this directory
|
||||
// A nil quantity or error means that the path does not support quotas
|
||||
// or xfs_quota tool is missing and we should use other mechanisms.
|
||||
startTime := time.Now()
|
||||
consumption, _ := fsquota.GetConsumption(path)
|
||||
if consumption != nil {
|
||||
usage.Bytes = consumption.Value()
|
||||
defer servermetrics.CollectVolumeStatCalDuration("fsquota", startTime)
|
||||
} else {
|
||||
defer servermetrics.CollectVolumeStatCalDuration("du", startTime)
|
||||
}
|
||||
|
||||
inodes, _ := fsquota.GetInodes(path)
|
||||
|
Loading…
Reference in New Issue
Block a user