Skip to content

Commit cc69d5a

Browse files
committed
Prevent generating duplicated PVC metrics.
1 parent d54ee0b commit cc69d5a

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

Gopkg.lock

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
branch = "master"
3838
name = "golang.org/x/net"
3939

40+
[[constraint]]
41+
name = "k8s.io/apimachinery"
42+
branch = "release-1.9"
43+
4044
[prune]
4145
go-tests = true
4246
unused-packages = true

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
all: test
3+
go install github.com/cofyc/kubelet-exporter/cmd/kubelet-exporter
4+
5+
test:
6+
go test -timeout 5m github.com/cofyc/kubelet-exporter/...

pkg/collectors/volume_stats.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"net/http"
88
"time"
99

10-
"golang.org/x/net/context/ctxhttp"
11-
1210
"github.com/golang/glog"
1311
"github.com/prometheus/client_golang/prometheus"
12+
"golang.org/x/net/context/ctxhttp"
13+
"k8s.io/apimachinery/pkg/util/sets"
1414
)
1515

1616
const (
@@ -169,6 +169,7 @@ func (collector *volumeStatsCollector) Collect(ch chan<- prometheus.Metric) {
169169
}
170170

171171
if statsSummary.Pods != nil {
172+
allPVCs := sets.String{}
172173
for _, podStats := range statsSummary.Pods {
173174
if podStats.VolumeStats == nil {
174175
continue
@@ -179,12 +180,18 @@ func (collector *volumeStatsCollector) Collect(ch chan<- prometheus.Metric) {
179180
// ignore if no PVC reference
180181
continue
181182
}
183+
pvcUniqStr := pvcRef.Namespace + pvcRef.Name
184+
if allPVCs.Has(pvcUniqStr) {
185+
// ignore if already collected
186+
continue
187+
}
182188
addGauge(volumeStatsCapacityBytes, pvcRef, float64(*volumeStat.CapacityBytes))
183189
addGauge(volumeStatsAvailableBytes, pvcRef, float64(*volumeStat.AvailableBytes))
184190
addGauge(volumeStatsUsedBytes, pvcRef, float64(*volumeStat.UsedBytes))
185191
addGauge(volumeStatsInodes, pvcRef, float64(*volumeStat.Inodes))
186192
addGauge(volumeStatsInodesFree, pvcRef, float64(*volumeStat.InodesFree))
187193
addGauge(volumeStatsInodesUsed, pvcRef, float64(*volumeStat.InodesUsed))
194+
allPVCs.Insert(pvcUniqStr)
188195
}
189196
}
190197
}

0 commit comments

Comments
 (0)