summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
Diffstat (limited to 'libpod')
-rw-r--r--libpod/define/containerstate.go19
-rw-r--r--libpod/pod.go10
-rw-r--r--libpod/runtime_img.go2
-rw-r--r--libpod/stats.go4
-rw-r--r--libpod/stats_config.go20
-rw-r--r--libpod/stats_unsupported.go2
-rw-r--r--libpod/util.go20
-rw-r--r--libpod/util_test.go3
8 files changed, 30 insertions, 50 deletions
diff --git a/libpod/define/containerstate.go b/libpod/define/containerstate.go
index 6da49a594..825e77387 100644
--- a/libpod/define/containerstate.go
+++ b/libpod/define/containerstate.go
@@ -112,3 +112,22 @@ func (s ContainerExecStatus) String() string {
return "bad state"
}
}
+
+// ContainerStats contains the statistics information for a running container
+type ContainerStats struct {
+ ContainerID string
+ Name string
+ PerCPU []uint64
+ CPU float64
+ CPUNano uint64
+ CPUSystemNano uint64
+ SystemNano uint64
+ MemUsage uint64
+ MemLimit uint64
+ MemPerc float64
+ NetInput uint64
+ NetOutput uint64
+ BlockInput uint64
+ BlockOutput uint64
+ PIDs uint64
+}
diff --git a/libpod/pod.go b/libpod/pod.go
index b5a14c165..8eb06ae2f 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -247,14 +247,14 @@ func (p *Pod) InfraContainerID() (string, error) {
// PodContainerStats is an organization struct for pods and their containers
type PodContainerStats struct {
Pod *Pod
- ContainerStats map[string]*ContainerStats
+ ContainerStats map[string]*define.ContainerStats
}
// GetPodStats returns the stats for each of its containers
-func (p *Pod) GetPodStats(previousContainerStats map[string]*ContainerStats) (map[string]*ContainerStats, error) {
+func (p *Pod) GetPodStats(previousContainerStats map[string]*define.ContainerStats) (map[string]*define.ContainerStats, error) {
var (
ok bool
- prevStat *ContainerStats
+ prevStat *define.ContainerStats
)
p.lock.Lock()
defer p.lock.Unlock()
@@ -266,10 +266,10 @@ func (p *Pod) GetPodStats(previousContainerStats map[string]*ContainerStats) (ma
if err != nil {
return nil, err
}
- newContainerStats := make(map[string]*ContainerStats)
+ newContainerStats := make(map[string]*define.ContainerStats)
for _, c := range containers {
if prevStat, ok = previousContainerStats[c.ID()]; !ok {
- prevStat = &ContainerStats{}
+ prevStat = &define.ContainerStats{}
}
newStats, err := c.GetContainerStats(prevStat)
// If the container wasn't running, don't include it
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go
index 919080c42..cd7f54799 100644
--- a/libpod/runtime_img.go
+++ b/libpod/runtime_img.go
@@ -56,7 +56,7 @@ func (r *Runtime) RemoveImage(ctx context.Context, img *image.Image, force bool)
}
}
} else {
- return nil, fmt.Errorf("could not remove image %s as it is being used by %d containers", img.ID(), len(imageCtrs))
+ return nil, errors.Wrapf(define.ErrImageInUse, "could not remove image %s as it is being used by %d containers", img.ID(), len(imageCtrs))
}
}
diff --git a/libpod/stats.go b/libpod/stats.go
index 6f42afd18..9f4986144 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -13,8 +13,8 @@ import (
)
// GetContainerStats gets the running stats for a given container
-func (c *Container) GetContainerStats(previousStats *ContainerStats) (*ContainerStats, error) {
- stats := new(ContainerStats)
+func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*define.ContainerStats, error) {
+ stats := new(define.ContainerStats)
stats.ContainerID = c.ID()
stats.Name = c.Name()
diff --git a/libpod/stats_config.go b/libpod/stats_config.go
deleted file mode 100644
index 91d3d1493..000000000
--- a/libpod/stats_config.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package libpod
-
-// ContainerStats contains the statistics information for a running container
-type ContainerStats struct {
- ContainerID string
- Name string
- PerCPU []uint64
- CPU float64
- CPUNano uint64
- CPUSystemNano uint64
- SystemNano uint64
- MemUsage uint64
- MemLimit uint64
- MemPerc float64
- NetInput uint64
- NetOutput uint64
- BlockInput uint64
- BlockOutput uint64
- PIDs uint64
-}
diff --git a/libpod/stats_unsupported.go b/libpod/stats_unsupported.go
index ec19a89a1..6d21ae8f2 100644
--- a/libpod/stats_unsupported.go
+++ b/libpod/stats_unsupported.go
@@ -5,6 +5,6 @@ package libpod
import "github.com/containers/libpod/libpod/define"
// GetContainerStats gets the running stats for a given container
-func (c *Container) GetContainerStats(previousStats *ContainerStats) (*ContainerStats, error) {
+func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*define.ContainerStats, error) {
return nil, define.ErrOSNotSupported
}
diff --git a/libpod/util.go b/libpod/util.go
index 6457dac1c..bdfd153ed 100644
--- a/libpod/util.go
+++ b/libpod/util.go
@@ -9,12 +9,10 @@ import (
"os/exec"
"path/filepath"
"sort"
- "strconv"
"strings"
"time"
"github.com/containers/common/pkg/config"
-
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/utils"
"github.com/fsnotify/fsnotify"
@@ -36,24 +34,6 @@ func FuncTimer(funcName string) {
fmt.Printf("%s executed in %d ms\n", funcName, elapsed)
}
-// RemoveScientificNotationFromFloat returns a float without any
-// scientific notation if the number has any.
-// golang does not handle conversion of float64s that have scientific
-// notation in them and otherwise stinks. please replace this if you have
-// a better implementation.
-func RemoveScientificNotationFromFloat(x float64) (float64, error) {
- bigNum := strconv.FormatFloat(x, 'g', -1, 64)
- breakPoint := strings.IndexAny(bigNum, "Ee")
- if breakPoint > 0 {
- bigNum = bigNum[:breakPoint]
- }
- result, err := strconv.ParseFloat(bigNum, 64)
- if err != nil {
- return x, errors.Wrapf(err, "unable to remove scientific number from calculations")
- }
- return result, nil
-}
-
// MountExists returns true if dest exists in the list of mounts
func MountExists(specMounts []spec.Mount, dest string) bool {
for _, m := range specMounts {
diff --git a/libpod/util_test.go b/libpod/util_test.go
index 227686c2b..4e18a7e4e 100644
--- a/libpod/util_test.go
+++ b/libpod/util_test.go
@@ -3,6 +3,7 @@ package libpod
import (
"testing"
+ "github.com/containers/libpod/utils"
"github.com/stretchr/testify/assert"
)
@@ -10,7 +11,7 @@ func TestRemoveScientificNotationFromFloat(t *testing.T) {
numbers := []float64{0.0, .5, 1.99999932, 1.04e+10}
results := []float64{0.0, .5, 1.99999932, 1.04}
for i, x := range numbers {
- result, err := RemoveScientificNotationFromFloat(x)
+ result, err := utils.RemoveScientificNotationFromFloat(x)
assert.NoError(t, err)
assert.Equal(t, result, results[i])
}