mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
Merge 68c2d3ad42 into 7e7aadc207
This commit is contained in:
commit
999050b276
4 changed files with 34 additions and 9 deletions
|
|
@ -16,6 +16,8 @@ type RecordedStats struct {
|
||||||
type DerivedStats struct {
|
type DerivedStats struct {
|
||||||
CPUPercentage float64
|
CPUPercentage float64
|
||||||
MemoryPercentage float64
|
MemoryPercentage float64
|
||||||
|
MemoryUsed int
|
||||||
|
MemoryLimit int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStats autogenerated at https://mholt.github.io/json-to-go/
|
// ContainerStats autogenerated at https://mholt.github.io/json-to-go/
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,8 @@ func (c *DockerCommand) CreateClientStatMonitor(container *Container) {
|
||||||
DerivedStats: DerivedStats{
|
DerivedStats: DerivedStats{
|
||||||
CPUPercentage: stats.CalculateContainerCPUPercentage(),
|
CPUPercentage: stats.CalculateContainerCPUPercentage(),
|
||||||
MemoryPercentage: stats.CalculateContainerMemoryUsage(),
|
MemoryPercentage: stats.CalculateContainerMemoryUsage(),
|
||||||
|
MemoryUsed: stats.MemoryStats.Usage,
|
||||||
|
MemoryLimit: stats.MemoryStats.Limit,
|
||||||
},
|
},
|
||||||
RecordedAt: time.Now(),
|
RecordedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,11 @@ import (
|
||||||
"github.com/jesseduffield/yaml"
|
"github.com/jesseduffield/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CPUCaption = "CPU (%)"
|
||||||
|
MemoryCaption = "Memory (%)"
|
||||||
|
)
|
||||||
|
|
||||||
// UserConfig holds all of the user-configurable options
|
// UserConfig holds all of the user-configurable options
|
||||||
type UserConfig struct {
|
type UserConfig struct {
|
||||||
// Gui is for configuring visual things like colors and whether we show or
|
// Gui is for configuring visual things like colors and whether we show or
|
||||||
|
|
@ -460,12 +465,12 @@ func GetDefaultConfig() UserConfig {
|
||||||
MaxDuration: duration,
|
MaxDuration: duration,
|
||||||
Graphs: []GraphConfig{
|
Graphs: []GraphConfig{
|
||||||
{
|
{
|
||||||
Caption: "CPU (%)",
|
Caption: CPUCaption,
|
||||||
StatPath: "DerivedStats.CPUPercentage",
|
StatPath: "DerivedStats.CPUPercentage",
|
||||||
Color: "cyan",
|
Color: "cyan",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Caption: "Memory (%)",
|
Caption: MemoryCaption,
|
||||||
StatPath: "DerivedStats.MemoryPercentage",
|
StatPath: "DerivedStats.MemoryPercentage",
|
||||||
Color: "green",
|
Color: "green",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,8 @@ func plotGraph(container *commands.Container, spec config.GraphConfig, width int
|
||||||
container.StatsMutex.Lock()
|
container.StatsMutex.Lock()
|
||||||
defer container.StatsMutex.Unlock()
|
defer container.StatsMutex.Unlock()
|
||||||
|
|
||||||
data := make([]float64, len(container.StatHistory))
|
dataLength := len(container.StatHistory)
|
||||||
|
data := make([]float64, dataLength)
|
||||||
|
|
||||||
for i, stats := range container.StatHistory {
|
for i, stats := range container.StatHistory {
|
||||||
value, err := lookup.LookupString(stats, spec.StatPath)
|
value, err := lookup.LookupString(stats, spec.StatPath)
|
||||||
|
|
@ -88,12 +89,27 @@ func plotGraph(container *commands.Container, spec config.GraphConfig, width int
|
||||||
height = spec.Height
|
height = spec.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
caption := fmt.Sprintf(
|
memoryUsed := utils.FormatDecimalBytes(container.StatHistory[dataLength-1].DerivedStats.MemoryUsed)
|
||||||
"%s: %0.2f (%v)",
|
memoryLimit := utils.FormatDecimalBytes(int(container.StatHistory[dataLength-1].DerivedStats.MemoryLimit))
|
||||||
spec.Caption,
|
var caption string
|
||||||
data[len(data)-1],
|
switch spec.Caption {
|
||||||
time.Since(container.StatHistory[0].RecordedAt).Round(time.Second),
|
case config.CPUCaption:
|
||||||
)
|
caption = fmt.Sprintf(
|
||||||
|
"%s: %0.2f (%v)",
|
||||||
|
spec.Caption,
|
||||||
|
data[dataLength-1],
|
||||||
|
time.Since(container.StatHistory[0].RecordedAt).Round(time.Second),
|
||||||
|
)
|
||||||
|
case config.MemoryCaption:
|
||||||
|
caption = fmt.Sprintf(
|
||||||
|
"%s: %s / %s (%0.2f) (%v)",
|
||||||
|
spec.Caption,
|
||||||
|
memoryUsed,
|
||||||
|
memoryLimit,
|
||||||
|
data[dataLength-1],
|
||||||
|
time.Since(container.StatHistory[0].RecordedAt).Round(time.Second),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return asciigraph.Plot(
|
return asciigraph.Plot(
|
||||||
data,
|
data,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue