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