mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
allow setting maximum duration on the graph
This commit is contained in:
parent
69b11cbfd2
commit
a017067824
5 changed files with 51 additions and 5 deletions
|
|
@ -39,6 +39,7 @@ type Container struct {
|
||||||
type RecordedStats struct {
|
type RecordedStats struct {
|
||||||
ClientStats ContainerStats
|
ClientStats ContainerStats
|
||||||
DerivedStats DerivedStats
|
DerivedStats DerivedStats
|
||||||
|
RecordedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type DerivedStats struct {
|
type DerivedStats struct {
|
||||||
|
|
@ -353,3 +354,18 @@ func (c *Container) Attach() (*exec.Cmd, error) {
|
||||||
func (c *Container) Top() (types.ContainerProcessList, error) {
|
func (c *Container) Top() (types.ContainerProcessList, error) {
|
||||||
return c.Client.ContainerTop(context.Background(), c.ID, []string{})
|
return c.Client.ContainerTop(context.Background(), c.ID, []string{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EraseOldHistory removes any history before the user-specified max duration
|
||||||
|
func (c *Container) EraseOldHistory() {
|
||||||
|
c.Log.Warn(c.Config.UserConfig.Stats.MaxDuration)
|
||||||
|
if c.Config.UserConfig.Stats.MaxDuration == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, stat := range c.StatHistory {
|
||||||
|
if time.Since(stat.RecordedAt) < c.Config.UserConfig.Stats.MaxDuration {
|
||||||
|
c.StatHistory = c.StatHistory[i:]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -197,15 +197,38 @@ func (c *Container) RenderStats(viewWidth int) (string, error) {
|
||||||
// PlotGraph returns the plotted graph based on the graph spec and the stat history
|
// PlotGraph returns the plotted graph based on the graph spec and the stat history
|
||||||
func (c *Container) PlotGraph(spec config.GraphConfig, width int) (string, error) {
|
func (c *Container) PlotGraph(spec config.GraphConfig, width int) (string, error) {
|
||||||
data := make([]float64, len(c.StatHistory))
|
data := make([]float64, len(c.StatHistory))
|
||||||
|
|
||||||
|
max := spec.Max
|
||||||
|
min := spec.Min
|
||||||
for i, stats := range c.StatHistory {
|
for i, stats := range c.StatHistory {
|
||||||
value, err := lookup.LookupString(stats, spec.StatPath)
|
value, err := lookup.LookupString(stats, spec.StatPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "Could not find key: " + spec.StatPath, nil
|
||||||
}
|
}
|
||||||
floatValue, err := getFloat(value.Interface())
|
floatValue, err := getFloat(value.Interface())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if spec.MinType == "" {
|
||||||
|
if i == 0 {
|
||||||
|
min = floatValue
|
||||||
|
} else {
|
||||||
|
if floatValue < min {
|
||||||
|
min = floatValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if spec.MaxType == "" {
|
||||||
|
if i == 0 {
|
||||||
|
max = floatValue
|
||||||
|
} else {
|
||||||
|
if floatValue > max {
|
||||||
|
max = floatValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data[i] = floatValue
|
data[i] = floatValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -213,8 +236,8 @@ func (c *Container) PlotGraph(spec config.GraphConfig, width int) (string, error
|
||||||
data,
|
data,
|
||||||
asciigraph.Height(spec.Height),
|
asciigraph.Height(spec.Height),
|
||||||
asciigraph.Width(width),
|
asciigraph.Width(width),
|
||||||
asciigraph.Min(spec.Min),
|
asciigraph.Min(min),
|
||||||
asciigraph.Max(spec.Max),
|
asciigraph.Max(max),
|
||||||
asciigraph.Caption(spec.Caption),
|
asciigraph.Caption(spec.Caption),
|
||||||
), nil
|
), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,11 +130,12 @@ func (c *DockerCommand) createClientStatMonitor(container *Container) {
|
||||||
CPUPercentage: stats.CalculateContainerCPUPercentage(),
|
CPUPercentage: stats.CalculateContainerCPUPercentage(),
|
||||||
MemoryPercentage: stats.CalculateContainerMemoryUsage(),
|
MemoryPercentage: stats.CalculateContainerMemoryUsage(),
|
||||||
},
|
},
|
||||||
|
RecordedAt: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ContainerMutex.Lock()
|
c.ContainerMutex.Lock()
|
||||||
// TODO: for now we never truncate the recorded stats, and we should
|
|
||||||
container.StatHistory = append(container.StatHistory, recordedStats)
|
container.StatHistory = append(container.StatHistory, recordedStats)
|
||||||
|
container.EraseOldHistory()
|
||||||
c.ContainerMutex.Unlock()
|
c.ContainerMutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package config
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/shibukawa/configdir"
|
"github.com/shibukawa/configdir"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
|
@ -123,10 +124,14 @@ type GraphConfig struct {
|
||||||
Caption string `yaml:"caption,omitempty"`
|
Caption string `yaml:"caption,omitempty"`
|
||||||
StatPath string `yaml:"statPath,omitempty"`
|
StatPath string `yaml:"statPath,omitempty"`
|
||||||
Color string `yaml:"color,omitempty"`
|
Color string `yaml:"color,omitempty"`
|
||||||
|
// MinType and MaxType are each one of "", "static". blank means the min/max of the data set will be used. "static" means the min/max specified will be used
|
||||||
|
MinType string `yaml:"minType,omitempty"`
|
||||||
|
MaxType string `yaml:"maxType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatsConfig struct {
|
type StatsConfig struct {
|
||||||
Graphs []GraphConfig
|
Graphs []GraphConfig
|
||||||
|
MaxDuration time.Duration `yaml:"maxDuration,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDefaultConfig returns the application default configuration
|
// GetDefaultConfig returns the application default configuration
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ func (gui *Gui) renderContainerConfig(mainView *gocui.View, container *commands.
|
||||||
func (gui *Gui) renderContainerStats(mainView *gocui.View, container *commands.Container) error {
|
func (gui *Gui) renderContainerStats(mainView *gocui.View, container *commands.Container) error {
|
||||||
mainView.Autoscroll = false
|
mainView.Autoscroll = false
|
||||||
mainView.Title = "Stats"
|
mainView.Title = "Stats"
|
||||||
|
mainView.Wrap = false
|
||||||
|
|
||||||
return gui.T.NewTickerTask(time.Second, func() {
|
return gui.T.NewTickerTask(time.Second, func() {
|
||||||
width, _ := mainView.Size()
|
width, _ := mainView.Size()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue