mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
rename metrics subpackage
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
api "github.com/fsouza/go-dockerclient"
|
api "github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Docker collector
|
// Docker collector
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
metrics.Metrics
|
models.Metrics
|
||||||
id string
|
id string
|
||||||
client *api.Client
|
client *api.Client
|
||||||
running bool
|
running bool
|
||||||
stream chan metrics.Metrics
|
stream chan models.Metrics
|
||||||
done chan bool
|
done chan bool
|
||||||
lastCpu float64
|
lastCpu float64
|
||||||
lastSysCpu float64
|
lastSysCpu float64
|
||||||
@@ -19,7 +19,7 @@ type Docker struct {
|
|||||||
|
|
||||||
func NewDocker(client *api.Client, id string) *Docker {
|
func NewDocker(client *api.Client, id string) *Docker {
|
||||||
return &Docker{
|
return &Docker{
|
||||||
Metrics: metrics.Metrics{},
|
Metrics: models.Metrics{},
|
||||||
id: id,
|
id: id,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ func NewDocker(client *api.Client, id string) *Docker {
|
|||||||
|
|
||||||
func (c *Docker) Start() {
|
func (c *Docker) Start() {
|
||||||
c.done = make(chan bool)
|
c.done = make(chan bool)
|
||||||
c.stream = make(chan metrics.Metrics)
|
c.stream = make(chan models.Metrics)
|
||||||
stats := make(chan *api.Stats)
|
stats := make(chan *api.Stats)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -61,7 +61,7 @@ func (c *Docker) Running() bool {
|
|||||||
return c.running
|
return c.running
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Docker) Stream() chan metrics.Metrics {
|
func (c *Docker) Stream() chan models.Metrics {
|
||||||
return c.stream
|
return c.stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mock collector
|
// Mock collector
|
||||||
type Mock struct {
|
type Mock struct {
|
||||||
metrics.Metrics
|
models.Metrics
|
||||||
stream chan metrics.Metrics
|
stream chan models.Metrics
|
||||||
done bool
|
done bool
|
||||||
running bool
|
running bool
|
||||||
aggression int64
|
aggression int64
|
||||||
@@ -20,7 +20,7 @@ type Mock struct {
|
|||||||
|
|
||||||
func NewMock(a int64) *Mock {
|
func NewMock(a int64) *Mock {
|
||||||
c := &Mock{
|
c := &Mock{
|
||||||
Metrics: metrics.Metrics{},
|
Metrics: models.Metrics{},
|
||||||
aggression: a,
|
aggression: a,
|
||||||
}
|
}
|
||||||
c.MemLimit = 2147483648
|
c.MemLimit = 2147483648
|
||||||
@@ -33,7 +33,7 @@ func (c *Mock) Running() bool {
|
|||||||
|
|
||||||
func (c *Mock) Start() {
|
func (c *Mock) Start() {
|
||||||
c.done = false
|
c.done = false
|
||||||
c.stream = make(chan metrics.Metrics)
|
c.stream = make(chan models.Metrics)
|
||||||
go c.run()
|
go c.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ func (c *Mock) Stop() {
|
|||||||
c.done = true
|
c.done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Mock) Stream() chan metrics.Metrics {
|
func (c *Mock) Stream() chan models.Metrics {
|
||||||
return c.stream
|
return c.stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,17 +5,17 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Runc collector
|
// Runc collector
|
||||||
type Runc struct {
|
type Runc struct {
|
||||||
metrics.Metrics
|
models.Metrics
|
||||||
id string
|
id string
|
||||||
libc libcontainer.Container
|
libc libcontainer.Container
|
||||||
stream chan metrics.Metrics
|
stream chan models.Metrics
|
||||||
done bool
|
done bool
|
||||||
running bool
|
running bool
|
||||||
interval int // collection interval, in seconds
|
interval int // collection interval, in seconds
|
||||||
@@ -25,7 +25,7 @@ type Runc struct {
|
|||||||
|
|
||||||
func NewRunc(libc libcontainer.Container) *Runc {
|
func NewRunc(libc libcontainer.Container) *Runc {
|
||||||
c := &Runc{
|
c := &Runc{
|
||||||
Metrics: metrics.Metrics{},
|
Metrics: models.Metrics{},
|
||||||
id: libc.ID(),
|
id: libc.ID(),
|
||||||
libc: libc,
|
libc: libc,
|
||||||
interval: 1,
|
interval: 1,
|
||||||
@@ -39,7 +39,7 @@ func (c *Runc) Running() bool {
|
|||||||
|
|
||||||
func (c *Runc) Start() {
|
func (c *Runc) Start() {
|
||||||
c.done = false
|
c.done = false
|
||||||
c.stream = make(chan metrics.Metrics)
|
c.stream = make(chan models.Metrics)
|
||||||
go c.run()
|
go c.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ func (c *Runc) Stop() {
|
|||||||
c.done = true
|
c.done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Runc) Stream() chan metrics.Metrics {
|
func (c *Runc) Stream() chan models.Metrics {
|
||||||
return c.stream
|
return c.stream
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/bcicen/ctop/cwidgets"
|
"github.com/bcicen/ctop/cwidgets"
|
||||||
"github.com/bcicen/ctop/cwidgets/compact"
|
"github.com/bcicen/ctop/cwidgets/compact"
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -13,19 +13,19 @@ var (
|
|||||||
|
|
||||||
// Metrics and metadata representing a container
|
// Metrics and metadata representing a container
|
||||||
type Container struct {
|
type Container struct {
|
||||||
metrics.Metrics
|
models.Metrics
|
||||||
Id string
|
Id string
|
||||||
Meta map[string]string
|
Meta map[string]string
|
||||||
Widgets *compact.Compact
|
Widgets *compact.Compact
|
||||||
Display bool // display this container in compact view
|
Display bool // display this container in compact view
|
||||||
updater cwidgets.WidgetUpdater
|
updater cwidgets.WidgetUpdater
|
||||||
collector metrics.Collector
|
collector models.Collector
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(id string, collector metrics.Collector) *Container {
|
func New(id string, collector models.Collector) *Container {
|
||||||
widgets := compact.NewCompact(id)
|
widgets := compact.NewCompact(id)
|
||||||
return &Container{
|
return &Container{
|
||||||
Metrics: metrics.NewMetrics(),
|
Metrics: models.NewMetrics(),
|
||||||
Id: id,
|
Id: id,
|
||||||
Meta: make(map[string]string),
|
Meta: make(map[string]string),
|
||||||
Widgets: widgets,
|
Widgets: widgets,
|
||||||
@@ -67,14 +67,14 @@ func (c *Container) SetState(s string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read metric stream, updating widgets
|
// Read metric stream, updating widgets
|
||||||
func (c *Container) Read(stream chan metrics.Metrics) {
|
func (c *Container) Read(stream chan models.Metrics) {
|
||||||
go func() {
|
go func() {
|
||||||
for metrics := range stream {
|
for metrics := range stream {
|
||||||
c.Metrics = metrics
|
c.Metrics = metrics
|
||||||
c.updater.SetMetrics(metrics)
|
c.updater.SetMetrics(metrics)
|
||||||
}
|
}
|
||||||
log.Infof("reader stopped for container: %s", c.Id)
|
log.Infof("reader stopped for container: %s", c.Id)
|
||||||
c.Metrics = metrics.NewMetrics()
|
c.Metrics = models.NewMetrics()
|
||||||
c.Widgets.Reset()
|
c.Widgets.Reset()
|
||||||
}()
|
}()
|
||||||
log.Infof("reader started for container: %s", c.Id)
|
log.Infof("reader started for container: %s", c.Id)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package compact
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ func (row *Compact) SetMeta(k, v string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (row *Compact) SetMetrics(m metrics.Metrics) {
|
func (row *Compact) SetMetrics(m models.Metrics) {
|
||||||
row.SetCPU(m.CPUUtil)
|
row.SetCPU(m.CPUUtil)
|
||||||
row.SetNet(m.NetRx, m.NetTx)
|
row.SetNet(m.NetRx, m.NetTx)
|
||||||
row.SetMem(m.MemUsage, m.MemLimit, m.MemPercent)
|
row.SetMem(m.MemUsage, m.MemLimit, m.MemPercent)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package expanded
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ func (e *Expanded) Down() {
|
|||||||
func (e *Expanded) SetWidth(w int) { e.Width = w }
|
func (e *Expanded) SetWidth(w int) { e.Width = w }
|
||||||
func (e *Expanded) SetMeta(k, v string) { e.Info.Set(k, v) }
|
func (e *Expanded) SetMeta(k, v string) { e.Info.Set(k, v) }
|
||||||
|
|
||||||
func (e *Expanded) SetMetrics(m metrics.Metrics) {
|
func (e *Expanded) SetMetrics(m models.Metrics) {
|
||||||
e.Cpu.Update(m.CPUUtil)
|
e.Cpu.Update(m.CPUUtil)
|
||||||
e.Net.Update(m.NetRx, m.NetTx)
|
e.Net.Update(m.NetRx, m.NetTx)
|
||||||
e.Mem.Update(int(m.MemUsage), int(m.MemLimit))
|
e.Mem.Update(int(m.MemUsage), int(m.MemLimit))
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ package cwidgets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
"github.com/bcicen/ctop/metrics"
|
"github.com/bcicen/ctop/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Init()
|
var log = logging.Init()
|
||||||
|
|
||||||
type WidgetUpdater interface {
|
type WidgetUpdater interface {
|
||||||
SetMeta(string, string)
|
SetMeta(string, string)
|
||||||
SetMetrics(metrics.Metrics)
|
SetMetrics(models.Metrics)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package metrics
|
package models
|
||||||
|
|
||||||
type Metrics struct {
|
type Metrics struct {
|
||||||
CPUUtil int
|
CPUUtil int
|
||||||
Reference in New Issue
Block a user