Skip to content

Commit

Permalink
docker: check type when totalling blkio & net metrics
Browse files Browse the repository at this point in the history
closes #2027
  • Loading branch information
sparrc committed Dec 21, 2016
1 parent bf5f265 commit 1e12ffb
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,22 @@ func gatherContainerStats(
if field == "container_id" {
continue
}

var uintV uint64
switch v := value.(type) {
case uint64:
uintV = v
case int64:
uintV = uint64(v)
default:
continue
}

_, ok := totalNetworkStatMap[field]
if ok {
totalNetworkStatMap[field] = totalNetworkStatMap[field].(uint64) + value.(uint64)
totalNetworkStatMap[field] = totalNetworkStatMap[field].(uint64) + uintV
} else {
totalNetworkStatMap[field] = value
totalNetworkStatMap[field] = uintV
}
}
}
Expand Down Expand Up @@ -491,11 +502,22 @@ func gatherBlockIOMetrics(
if field == "container_id" {
continue
}

var uintV uint64
switch v := value.(type) {
case uint64:
uintV = v
case int64:
uintV = uint64(v)
default:
continue
}

_, ok := totalStatMap[field]
if ok {
totalStatMap[field] = totalStatMap[field].(uint64) + value.(uint64)
totalStatMap[field] = totalStatMap[field].(uint64) + uintV
} else {
totalStatMap[field] = value
totalStatMap[field] = uintV
}
}
}
Expand Down

0 comments on commit 1e12ffb

Please sign in to comment.