mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 23:26:45 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5261444265 | ||
|
|
b3aa291182 | ||
|
|
051b474bf0 | ||
|
|
fac6632459 | ||
|
|
1c7cf98e58 | ||
|
|
44a54e070d | ||
|
|
10b9a6c013 | ||
|
|
a3b67e4607 | ||
|
|
ac1ce18143 | ||
|
|
01a305d326 |
@@ -1,4 +1,4 @@
|
|||||||
FROM quay.io/vektorcloud/go:1.9
|
FROM quay.io/vektorcloud/go:1.10
|
||||||
|
|
||||||
RUN apk add --no-cache make
|
RUN apk add --no-cache make
|
||||||
|
|
||||||
|
|||||||
14
Gopkg.lock
generated
14
Gopkg.lock
generated
@@ -6,6 +6,12 @@
|
|||||||
packages = [".","winterm"]
|
packages = [".","winterm"]
|
||||||
revision = "fa152c58bc15761d0200cb75fe958b89a9d4888e"
|
revision = "fa152c58bc15761d0200cb75fe958b89a9d4888e"
|
||||||
|
|
||||||
|
[[projects]]
|
||||||
|
name = "github.com/BurntSushi/toml"
|
||||||
|
packages = ["."]
|
||||||
|
revision = "b26d9c308763d68093482582cea63d69be07a0f0"
|
||||||
|
version = "v0.3.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/Microsoft/go-winio"
|
name = "github.com/Microsoft/go-winio"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
@@ -57,10 +63,10 @@
|
|||||||
revision = "318513eb1ab27495afbc67f671ba1080513d8aa0"
|
revision = "318513eb1ab27495afbc67f671ba1080513d8aa0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "barchart-numfmt"
|
branch = "master"
|
||||||
name = "github.com/gizak/termui"
|
name = "github.com/gizak/termui"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "ea10e6ccee219e572ffad0ac1909f1a17f6db7d6"
|
revision = "cdc199d7ea432fd8187db35f0247285d6f5b0267"
|
||||||
source = "https://github.com/bcicen/termui"
|
source = "https://github.com/bcicen/termui"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
@@ -106,7 +112,7 @@
|
|||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/nsf/termbox-go"
|
name = "github.com/nsf/termbox-go"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "91bae1bb5fa9ee504905ecbe7043fa30e92feaa3"
|
revision = "e2050e41c8847748ec5288741c0b19a8cb26d084"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
@@ -154,6 +160,6 @@
|
|||||||
[solve-meta]
|
[solve-meta]
|
||||||
analyzer-name = "dep"
|
analyzer-name = "dep"
|
||||||
analyzer-version = 1
|
analyzer-version = 1
|
||||||
inputs-digest = "cf4dacc32111b22d72ac23189b826c8316ec265e55bf987338c7a00633af788e"
|
inputs-digest = "f46f5c696ecb0b0c42a38dac512df21fc1f5fb2bfda888434e005e69d1b6273b"
|
||||||
solver-name = "gps-cdcl"
|
solver-name = "gps-cdcl"
|
||||||
solver-version = 1
|
solver-version = 1
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
revision = "318513eb1ab27495afbc67f671ba1080513d8aa0"
|
revision = "318513eb1ab27495afbc67f671ba1080513d8aa0"
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
branch = "barchart-numfmt"
|
branch = "master"
|
||||||
name = "github.com/gizak/termui"
|
name = "github.com/gizak/termui"
|
||||||
source = "https://github.com/bcicen/termui"
|
source = "https://github.com/bcicen/termui"
|
||||||
|
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -20,6 +20,7 @@ build-all:
|
|||||||
GOOS=linux GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-amd64
|
GOOS=linux GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-amd64
|
||||||
GOOS=linux GOARCH=arm go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm
|
GOOS=linux GOARCH=arm go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm
|
||||||
GOOS=linux GOARCH=arm64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm64
|
GOOS=linux GOARCH=arm64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm64
|
||||||
|
GOOS=windows GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-windows-amd64
|
||||||
cd _build; sha256sum * > sha256sums.txt
|
cd _build; sha256sum * > sha256sums.txt
|
||||||
|
|
||||||
image:
|
image:
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ While running, use `S` to save the current filters, sort field, and other option
|
|||||||
Option | Description
|
Option | Description
|
||||||
--- | ---
|
--- | ---
|
||||||
-a | show active containers only
|
-a | show active containers only
|
||||||
-f <string> | set an initial filter string
|
-f \<string\> | set an initial filter string
|
||||||
-h | display help dialog
|
-h | display help dialog
|
||||||
-i | invert default colors
|
-i | invert default colors
|
||||||
-r | reverse container sort order
|
-r | reverse container sort order
|
||||||
@@ -75,7 +75,7 @@ Option | Description
|
|||||||
|
|
||||||
Key | Action
|
Key | Action
|
||||||
--- | ---
|
--- | ---
|
||||||
<enter> | Open container menu
|
\<enter\> | Open container menu
|
||||||
a | Toggle display of all (running and non-running) containers
|
a | Toggle display of all (running and non-running) containers
|
||||||
f | Filter displayed containers (`esc` to clear when open)
|
f | Filter displayed containers (`esc` to clear when open)
|
||||||
H | Toggle ctop header
|
H | Toggle ctop header
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !darwin
|
// +build linux
|
||||||
|
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !darwin
|
// +build linux
|
||||||
|
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
api "github.com/fsouza/go-dockerclient"
|
api "github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() { enabled["docker"] = NewDocker }
|
||||||
|
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
client *api.Client
|
client *api.Client
|
||||||
containers map[string]*container.Container
|
containers map[string]*container.Container
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
// +build !linux
|
|
||||||
|
|
||||||
package connector
|
|
||||||
|
|
||||||
var enabled = map[string]func() Connector{
|
|
||||||
"docker": NewDocker,
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// +build !darwin
|
|
||||||
|
|
||||||
package connector
|
|
||||||
|
|
||||||
var enabled = map[string]func() Connector{
|
|
||||||
"docker": NewDocker,
|
|
||||||
"runc": NewRunc,
|
|
||||||
}
|
|
||||||
@@ -2,22 +2,31 @@ package connector
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/container"
|
"github.com/bcicen/ctop/container"
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logging.Init()
|
var (
|
||||||
|
log = logging.Init()
|
||||||
|
enabled = make(map[string]func() Connector)
|
||||||
|
)
|
||||||
|
|
||||||
|
// return names for all enabled connectors on the current platform
|
||||||
|
func Enabled() (a []string) {
|
||||||
|
for k, _ := range enabled {
|
||||||
|
a = append(a, k)
|
||||||
|
}
|
||||||
|
sort.Strings(a)
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
func ByName(s string) (Connector, error) {
|
func ByName(s string) (Connector, error) {
|
||||||
if _, ok := enabled[s]; !ok {
|
if cfn, ok := enabled[s]; ok {
|
||||||
msg := fmt.Sprintf("invalid connector type \"%s\"\nconnector must be one of:", s)
|
return cfn(), nil
|
||||||
for k, _ := range enabled {
|
|
||||||
msg += fmt.Sprintf("\n %s", k)
|
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf(msg)
|
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
|
||||||
}
|
|
||||||
return enabled[s](), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Connector interface {
|
type Connector interface {
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ import (
|
|||||||
"github.com/nu7hatch/gouuid"
|
"github.com/nu7hatch/gouuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() { enabled["mock"] = NewMock }
|
||||||
|
|
||||||
type Mock struct {
|
type Mock struct {
|
||||||
containers container.Containers
|
containers container.Containers
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMock() *Mock {
|
func NewMock() Connector {
|
||||||
cs := &Mock{}
|
cs := &Mock{}
|
||||||
go cs.Init()
|
go cs.Init()
|
||||||
go cs.Loop()
|
go cs.Loop()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !darwin
|
// +build linux
|
||||||
|
|
||||||
package connector
|
package connector
|
||||||
|
|
||||||
@@ -17,6 +17,8 @@ import (
|
|||||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() { enabled["runc"] = NewRunc }
|
||||||
|
|
||||||
type RuncOpts struct {
|
type RuncOpts struct {
|
||||||
root string // runc root path
|
root string // runc root path
|
||||||
systemdCgroups bool // use systemd cgroups
|
systemdCgroups bool // use systemd cgroups
|
||||||
|
|||||||
@@ -23,10 +23,7 @@ func NewCompactGrid() *CompactGrid {
|
|||||||
func (cg *CompactGrid) Align() {
|
func (cg *CompactGrid) Align() {
|
||||||
y := cg.Y
|
y := cg.Y
|
||||||
|
|
||||||
if cg.Offset >= len(cg.Rows) {
|
if cg.Offset >= len(cg.Rows) || cg.Offset < 0 {
|
||||||
cg.Offset = 0
|
|
||||||
}
|
|
||||||
if cg.Offset < 0 {
|
|
||||||
cg.Offset = 0
|
cg.Offset = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
5
main.go
5
main.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/config"
|
"github.com/bcicen/ctop/config"
|
||||||
"github.com/bcicen/ctop/connector"
|
"github.com/bcicen/ctop/connector"
|
||||||
@@ -138,7 +139,7 @@ func panicExit() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var helpMsg = `ctop - container metric viewer
|
var helpMsg = `ctop - interactive container viewer
|
||||||
|
|
||||||
usage: ctop [options]
|
usage: ctop [options]
|
||||||
|
|
||||||
@@ -148,4 +149,6 @@ options:
|
|||||||
func printHelp() {
|
func printHelp() {
|
||||||
fmt.Println(helpMsg)
|
fmt.Println(helpMsg)
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
|
fmt.Printf("\navailable connectors: ")
|
||||||
|
fmt.Println(strings.Join(connector.Enabled(), ", "))
|
||||||
}
|
}
|
||||||
|
|||||||
3
menus.go
3
menus.go
@@ -37,7 +37,10 @@ func HelpMenu() MenuFn {
|
|||||||
m := menu.NewMenu()
|
m := menu.NewMenu()
|
||||||
m.BorderLabel = "Help"
|
m.BorderLabel = "Help"
|
||||||
m.AddItems(helpDialog...)
|
m.AddItems(helpDialog...)
|
||||||
|
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||||
|
ui.Clear()
|
||||||
ui.Render(m)
|
ui.Render(m)
|
||||||
|
})
|
||||||
ui.Handle("/sys/kbd/", func(ui.Event) {
|
ui.Handle("/sys/kbd/", func(ui.Event) {
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user