Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fixes multiple usage of same metric
Browse files Browse the repository at this point in the history
- removes vol parameter from parseMountOutput
- removes for loop around mountpoint check which caused the error.
  • Loading branch information
ofesseler committed Feb 16, 2017
1 parent 600452a commit 3a1f091
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 14 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,21 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
}
}

for _, vol := range vols {
mountBuffer, execMountCheckErr := execMountCheck()
if execMountCheckErr != nil {
log.Error(execMountCheckErr)
} else {
mounts, err := parseMountOutput(vol, mountBuffer.String())
if err != nil {
log.Error(err)
if mounts != nil && len(mounts) > 0 {
for _, mount := range mounts {
ch <- prometheus.MustNewConstMetric(
mountSuccessful, prometheus.GaugeValue, float64(0), mount.volume, mount.mountPoint,
)
}
mountBuffer, execMountCheckErr := execMountCheck()
if execMountCheckErr != nil {
log.Error(execMountCheckErr)
} else {
mounts, err := parseMountOutput(mountBuffer.String())
if err != nil {
log.Error(err)
if mounts != nil && len(mounts) > 0 {
for _, mount := range mounts {
ch <- prometheus.MustNewConstMetric(
mountSuccessful, prometheus.GaugeValue, float64(0), mount.volume, mount.mountPoint,
)
}
}
} else {
for _, mount := range mounts {
ch <- prometheus.MustNewConstMetric(
mountSuccessful, prometheus.GaugeValue, float64(1), mount.volume, mount.mountPoint,
Expand Down Expand Up @@ -345,7 +344,7 @@ type mount struct {
}

// ParseMountOutput pares output of system execution 'mount'
func parseMountOutput(vol string, mountBuffer string) ([]mount, error) {
func parseMountOutput(mountBuffer string) ([]mount, error) {
mounts := make([]mount, 0, 2)
mountRows := strings.Split(mountBuffer, "\n")
for _, row := range mountRows {
Expand Down
2 changes: 1 addition & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestParseMountOutput(t *testing.T) {
},
}
for _, c := range tests {
mounts, err := parseMountOutput("asd", c.mountOutput)
mounts, err := parseMountOutput(c.mountOutput)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 3a1f091

Please sign in to comment.