Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afbed43185 | ||
|
|
d083430c73 | ||
|
|
79f553ff0c | ||
|
|
a02551f5ec |
17
docker/calculation.go
Normal file
17
docker/calculation.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package docker
|
||||
|
||||
import "github.com/docker/docker/api/types"
|
||||
|
||||
func calculateMemUsageUnixNoCache(mem types.MemoryStats) float64 {
|
||||
// re implementation of the docker calculation
|
||||
// https://github.com/docker/cli/blob/53f8ed4bec07084db4208f55987a2ea94b7f01d6/cli/command/container/stats_helpers.go#L227-L249
|
||||
// cgroup v1
|
||||
if v, isCGroup := mem.Stats["total_inactive_file"]; isCGroup && v < mem.Usage {
|
||||
return float64(mem.Usage - v)
|
||||
}
|
||||
// cgroup v2
|
||||
if v := mem.Stats["inactive_file"]; v < mem.Usage {
|
||||
return float64(mem.Usage - v)
|
||||
}
|
||||
return float64(mem.Usage)
|
||||
}
|
||||
57
docker/calculation_test.go
Normal file
57
docker/calculation_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_calculateMemUsageUnixNoCache(t *testing.T) {
|
||||
type args struct {
|
||||
mem types.MemoryStats
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want float64
|
||||
}{
|
||||
{
|
||||
name: "with cgroup v1",
|
||||
args: args{
|
||||
mem: types.MemoryStats{
|
||||
Usage: 100,
|
||||
Stats: map[string]uint64{
|
||||
"total_inactive_file": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 99,
|
||||
},
|
||||
{
|
||||
name: "with cgroup v2",
|
||||
args: args{
|
||||
mem: types.MemoryStats{
|
||||
Usage: 100,
|
||||
Stats: map[string]uint64{
|
||||
"inactive_file": 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: 98,
|
||||
},
|
||||
{
|
||||
name: "without cgroup",
|
||||
args: args{
|
||||
mem: types.MemoryStats{
|
||||
Usage: 100,
|
||||
},
|
||||
},
|
||||
want: 100,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, calculateMemUsageUnixNoCache(tt.args.mem), "calculateMemUsageUnixNoCache(%v)", tt.args.mem)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ func (d *dockerClient) ContainerStats(ctx context.Context, id string, stats chan
|
||||
cpuDelta = float64(v.CPUStats.CPUUsage.TotalUsage) - float64(v.PreCPUStats.CPUUsage.TotalUsage)
|
||||
systemDelta = float64(v.CPUStats.SystemUsage) - float64(v.PreCPUStats.SystemUsage)
|
||||
cpuPercent = int64((cpuDelta / systemDelta) * float64(ncpus) * 100)
|
||||
memUsage = int64(v.MemoryStats.Usage - v.MemoryStats.Stats["cache"])
|
||||
memUsage = int64(calculateMemUsageUnixNoCache(v.MemoryStats))
|
||||
memPercent = int64(float64(memUsage) / float64(v.MemoryStats.Limit) * 100)
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM cypress/included:10.8.0
|
||||
FROM cypress/included:10.9.0
|
||||
|
||||
RUN apt install curl && curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dozzle",
|
||||
"version": "4.1.8",
|
||||
"version": "4.1.9",
|
||||
"description": "Realtime log viewer for docker containers. ",
|
||||
"homepage": "https://github.com/amir20/dozzle#readme",
|
||||
"bugs": {
|
||||
|
||||
Reference in New Issue
Block a user