Skip to content

Commit

Permalink
Merge pull request #674 from r0fls/add-pv-capacity-metric
Browse files Browse the repository at this point in the history
add persistent volume capacity metric
  • Loading branch information
k8s-ci-robot committed Feb 22, 2019
2 parents 83302c9 + 58fd352 commit fb19057
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/persistentvolume-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

| Metric name| Metric type | Labels/tags | Status |
| ---------- | ----------- | ----------- | ----------- |
| kube_persistentvolume_capacity_bytes | Gauge | `persistentvolume`=<pv-name> | STABLE |
| kube_persistentvolume_status_phase | Gauge | `persistentvolume`=&lt;pv-name&gt; <br>`phase`=&lt;Bound\|Failed\|Pending\|Available\|Released&gt;| STABLE |
| kube_persistentvolume_labels | Gauge | `persistentvolume`=&lt;persistentvolume-name&gt; <br> `label_PERSISTENTVOLUME_LABEL`=&lt;PERSISTENTVOLUME_LABEL&gt; | STABLE |
| kube_persistentvolume_info | Gauge | `persistentvolume`=&lt;pv-name&gt; <br> `storageclass`=&lt;storageclass-name&gt; | STABLE |
Expand Down
15 changes: 15 additions & 0 deletions internal/collector/persistentvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ var (
}
}),
},
{
Name: "kube_persistentvolume_capacity_bytes",
Type: metric.MetricTypeGauge,
Help: "Persistentvolume capacity in bytes.",
GenerateFunc: wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family {
storage := p.Spec.Capacity[v1.ResourceStorage]
return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(storage.Value()),
},
},
}
}),
},
}
)

Expand Down
19 changes: 19 additions & 0 deletions internal/collector/persistentvolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kube-state-metrics/pkg/metric"
)
Expand All @@ -34,6 +35,8 @@ func TestPersistentVolumeCollector(t *testing.T) {
# TYPE kube_persistentvolume_labels gauge
# HELP kube_persistentvolume_info Information about persistentvolume.
# TYPE kube_persistentvolume_info gauge
# HELP kube_persistentvolume_capacity_bytes The size of the Persistentvolume in bytes.
# TYPE kube_persistentvolume_capacity_bytes gauge
`
cases := []generateMetricsTestCase{
// Verify phase enumerations.
Expand Down Expand Up @@ -201,6 +204,22 @@ func TestPersistentVolumeCollector(t *testing.T) {
`,
MetricNames: []string{"kube_persistentvolume_labels"},
},
{
Obj: &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pv",
},
Spec: v1.PersistentVolumeSpec{
Capacity: v1.ResourceList{
v1.ResourceStorage: resource.MustParse("5Gi"),
},
},
},
Want: `
kube_persistentvolume_capacity_bytes{persistentvolume="test-pv"} 5.36870912e+09
`,
MetricNames: []string{"kube_persistentvolume_capacity_bytes"},
},
}
for i, c := range cases {
c.Func = metric.ComposeMetricGenFuncs(persistentVolumeMetricFamilies)
Expand Down

0 comments on commit fb19057

Please sign in to comment.