mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70bd2ae3a3 | ||
|
|
665e8fdd06 | ||
|
|
a39b7a3a3e | ||
|
|
77f5e6b735 | ||
|
|
3c83b7576b | ||
|
|
8a0bd3cf8a | ||
|
|
78caad2dbd | ||
|
|
8d8f1e72eb | ||
|
|
93556a1754 | ||
|
|
4d247f5272 | ||
|
|
db3d7e8927 | ||
|
|
efef345665 | ||
|
|
f158fa742f | ||
|
|
4d48245d7d | ||
|
|
6bee1b7f31 | ||
|
|
7118e45f3a | ||
|
|
3405d19be8 | ||
|
|
9a185b2388 | ||
|
|
caf6fc63c1 | ||
|
|
cf352f7c8a | ||
|
|
ac5bed210f | ||
|
|
a72d43526f | ||
|
|
9eb2457aa4 | ||
|
|
b83402b886 | ||
|
|
078564bd38 | ||
|
|
a2c08d312e | ||
|
|
f7a3d38d6b | ||
|
|
a3b8585697 | ||
|
|
2e526e9b86 | ||
|
|
541fe70b78 | ||
|
|
c786b697bf | ||
|
|
aa6c00b083 | ||
|
|
17855e3d8e | ||
|
|
842809bef5 | ||
|
|
4e567ee007 | ||
|
|
56700e120b | ||
|
|
5261444265 | ||
|
|
b3aa291182 | ||
|
|
051b474bf0 | ||
|
|
fac6632459 | ||
|
|
1c7cf98e58 | ||
|
|
44a54e070d | ||
|
|
10b9a6c013 | ||
|
|
a3b67e4607 | ||
|
|
ac1ce18143 | ||
|
|
01a305d326 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
ctop
|
||||
.idea
|
||||
.idea
|
||||
/vendor/
|
||||
11
Dockerfile
11
Dockerfile
@@ -1,16 +1,17 @@
|
||||
FROM quay.io/vektorcloud/go:1.9
|
||||
FROM quay.io/vektorcloud/go:1.11
|
||||
|
||||
RUN apk add --no-cache make
|
||||
|
||||
COPY Gopkg.* /go/src/github.com/bcicen/ctop/
|
||||
WORKDIR /go/src/github.com/bcicen/ctop/
|
||||
RUN dep ensure -vendor-only
|
||||
WORKDIR /app
|
||||
COPY go.mod .
|
||||
RUN go mod download
|
||||
|
||||
COPY . /go/src/github.com/bcicen/ctop
|
||||
COPY . .
|
||||
RUN make build && \
|
||||
mkdir -p /go/bin && \
|
||||
mv -v ctop /go/bin/
|
||||
|
||||
FROM scratch
|
||||
ENV TERM=linux
|
||||
COPY --from=0 /go/bin/ctop /ctop
|
||||
ENTRYPOINT ["/ctop"]
|
||||
|
||||
159
Gopkg.lock
generated
159
Gopkg.lock
generated
@@ -1,159 +0,0 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/Azure/go-ansiterm"
|
||||
packages = [".","winterm"]
|
||||
revision = "fa152c58bc15761d0200cb75fe958b89a9d4888e"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/Microsoft/go-winio"
|
||||
packages = ["."]
|
||||
revision = "fff283ad5116362ca252298cfc9b95828956d85d"
|
||||
version = "v0.3.8"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Nvveen/Gotty"
|
||||
packages = ["."]
|
||||
revision = "cd527374f1e5bff4938207604a14f2e38a9cf512"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/Sirupsen/logrus"
|
||||
packages = ["."]
|
||||
revision = "26709e2714106fb8ad40b773b711ebce25b78914"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/c9s/goprocinfo"
|
||||
packages = ["linux"]
|
||||
revision = "b34328d6e0cd139894ea7347d2624ccf31fa3c58"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/coreos/go-systemd"
|
||||
packages = ["dbus","util"]
|
||||
revision = "b4a58d95188dd092ae20072bac14cece0e67c388"
|
||||
version = "v4"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/docker/docker"
|
||||
packages = ["api/types","api/types/blkiodev","api/types/container","api/types/filters","api/types/mount","api/types/network","api/types/registry","api/types/strslice","api/types/swarm","api/types/versions","opts","pkg/archive","pkg/fileutils","pkg/homedir","pkg/idtools","pkg/ioutils","pkg/jsonlog","pkg/jsonmessage","pkg/longpath","pkg/mount","pkg/pools","pkg/promise","pkg/stdcopy","pkg/symlink","pkg/system","pkg/term","pkg/term/windows"]
|
||||
revision = "90d35abf7b3535c1c319c872900fbd76374e521c"
|
||||
version = "v17.05.0-ce-rc3"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/docker/go-connections"
|
||||
packages = ["nat"]
|
||||
revision = "a2afab9802043837035592f1c24827fb70766de9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/docker/go-units"
|
||||
packages = ["."]
|
||||
revision = "0dadbb0345b35ec7ef35e228dabb8de89a65bf52"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/fsouza/go-dockerclient"
|
||||
packages = ["."]
|
||||
revision = "318513eb1ab27495afbc67f671ba1080513d8aa0"
|
||||
|
||||
[[projects]]
|
||||
branch = "barchart-numfmt"
|
||||
name = "github.com/gizak/termui"
|
||||
packages = ["."]
|
||||
revision = "ea10e6ccee219e572ffad0ac1909f1a17f6db7d6"
|
||||
source = "https://github.com/bcicen/termui"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/godbus/dbus"
|
||||
packages = ["."]
|
||||
revision = "c7fdd8b5cd55e87b4e1f4e372cdb1db61dd6c66f"
|
||||
version = "v3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/golang/protobuf"
|
||||
packages = ["proto"]
|
||||
revision = "0a4f71a498b7c4812f64969510bcb4eca251e33a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/hashicorp/go-cleanhttp"
|
||||
packages = ["."]
|
||||
revision = "3573b8b52aa7b37b9358d966a898feb387f62437"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/jgautheron/codename-generator"
|
||||
packages = ["."]
|
||||
revision = "16d037c7cc3c9b552fe4af9828b7338d752dbaf9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/maruel/panicparse"
|
||||
packages = ["stack"]
|
||||
revision = "25bcac0d793cf4109483505a0d66e066a3a90a80"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-runewidth"
|
||||
packages = ["."]
|
||||
revision = "14207d285c6c197daabb5c9793d63e7af9ab2d50"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/go-wordwrap"
|
||||
packages = ["."]
|
||||
revision = "ad45545899c7b13c020ea92b2072220eefad42b8"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/nsf/termbox-go"
|
||||
packages = ["."]
|
||||
revision = "91bae1bb5fa9ee504905ecbe7043fa30e92feaa3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/nu7hatch/gouuid"
|
||||
packages = ["."]
|
||||
revision = "179d4d0c4d8d407a32af483c2354df1d2c91e6c3"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/op/go-logging"
|
||||
packages = ["."]
|
||||
revision = "b2cb9fa56473e98db8caba80237377e83fe44db5"
|
||||
version = "v1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/opencontainers/runc"
|
||||
packages = ["libcontainer","libcontainer/apparmor","libcontainer/cgroups","libcontainer/cgroups/fs","libcontainer/cgroups/systemd","libcontainer/configs","libcontainer/configs/validate","libcontainer/criurpc","libcontainer/keys","libcontainer/label","libcontainer/seccomp","libcontainer/selinux","libcontainer/stacktrace","libcontainer/system","libcontainer/user","libcontainer/utils"]
|
||||
revision = "baf6536d6259209c3edfa2b22237af82942d3dfa"
|
||||
version = "v0.1.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/seccomp/libseccomp-golang"
|
||||
packages = ["."]
|
||||
revision = "1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/syndtr/gocapability"
|
||||
packages = ["capability"]
|
||||
revision = "2c00daeb6c3b45114c80ac44119e7b8801fdd852"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/vishvananda/netlink"
|
||||
packages = [".","nl"]
|
||||
revision = "1e2e08e8a2dcdacaae3f14ac44c5cfa31361f270"
|
||||
|
||||
[[projects]]
|
||||
name = "golang.org/x/net"
|
||||
packages = ["context","context/ctxhttp"]
|
||||
revision = "a6577fac2d73be281a500b310739095313165611"
|
||||
|
||||
[[projects]]
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix","windows"]
|
||||
revision = "99f16d856c9836c42d24e7ab64ea72916925fa97"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "cf4dacc32111b22d72ac23189b826c8316ec265e55bf987338c7a00633af788e"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
47
Gopkg.toml
47
Gopkg.toml
@@ -1,47 +0,0 @@
|
||||
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/fsouza/go-dockerclient"
|
||||
revision = "318513eb1ab27495afbc67f671ba1080513d8aa0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "barchart-numfmt"
|
||||
name = "github.com/gizak/termui"
|
||||
source = "https://github.com/bcicen/termui"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/jgautheron/codename-generator"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/nu7hatch/gouuid"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/op/go-logging"
|
||||
version = "1.0.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/opencontainers/runc"
|
||||
version = "0.1.1"
|
||||
11
Makefile
11
Makefile
@@ -8,7 +8,7 @@ clean:
|
||||
rm -rf _build/ release/
|
||||
|
||||
build:
|
||||
dep ensure
|
||||
go mod download
|
||||
CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o ctop
|
||||
|
||||
build-dev:
|
||||
@@ -16,10 +16,11 @@ build-dev:
|
||||
|
||||
build-all:
|
||||
mkdir -p _build
|
||||
GOOS=darwin GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-darwin-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=arm64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm64
|
||||
GOOS=darwin GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-darwin-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=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
|
||||
|
||||
image:
|
||||
|
||||
@@ -20,7 +20,7 @@ Fetch the [latest release](https://github.com/bcicen/ctop/releases) for your pla
|
||||
#### Linux
|
||||
|
||||
```bash
|
||||
sudo wget https://github.com/bcicen/ctop/releases/download/v0.7/ctop-0.7-linux-amd64 -O /usr/local/bin/ctop
|
||||
sudo wget https://github.com/bcicen/ctop/releases/download/v0.7.2/ctop-0.7.2-linux-amd64 -O /usr/local/bin/ctop
|
||||
sudo chmod +x /usr/local/bin/ctop
|
||||
```
|
||||
|
||||
@@ -31,7 +31,7 @@ brew install ctop
|
||||
```
|
||||
or
|
||||
```bash
|
||||
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.7/ctop-0.7-darwin-amd64
|
||||
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.7.2/ctop-0.7.2-darwin-amd64
|
||||
sudo chmod +x /usr/local/bin/ctop
|
||||
```
|
||||
|
||||
@@ -63,7 +63,7 @@ While running, use `S` to save the current filters, sort field, and other option
|
||||
Option | Description
|
||||
--- | ---
|
||||
-a | show active containers only
|
||||
-f <string> | set an initial filter string
|
||||
-f \<string\> | set an initial filter string
|
||||
-h | display help dialog
|
||||
-i | invert default colors
|
||||
-r | reverse container sort order
|
||||
@@ -75,7 +75,7 @@ Option | Description
|
||||
|
||||
Key | Action
|
||||
--- | ---
|
||||
<enter> | Open container menu
|
||||
\<enter\> | Open container menu
|
||||
a | Toggle display of all (running and non-running) containers
|
||||
f | Filter displayed containers (`esc` to clear when open)
|
||||
H | Toggle ctop header
|
||||
|
||||
@@ -52,7 +52,7 @@ var ColorMap = map[string]ui.Attribute{
|
||||
|
||||
func InvertColorMap() {
|
||||
re := regexp.MustCompile(".*.fg")
|
||||
for k, _ := range ColorMap {
|
||||
for k := range ColorMap {
|
||||
if re.FindAllString(k, 1) != nil {
|
||||
ColorMap[k] = ui.ColorBlack
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ var (
|
||||
xdgRe = regexp.MustCompile("^XDG_*")
|
||||
)
|
||||
|
||||
type ConfigFile struct {
|
||||
type File struct {
|
||||
Options map[string]string `toml:"options"`
|
||||
Toggles map[string]bool `toml:"toggles"`
|
||||
}
|
||||
|
||||
func exportConfig() ConfigFile {
|
||||
c := ConfigFile{
|
||||
func exportConfig() File {
|
||||
c := File{
|
||||
Options: make(map[string]string),
|
||||
Toggles: make(map[string]bool),
|
||||
}
|
||||
@@ -33,7 +33,7 @@ func exportConfig() ConfigFile {
|
||||
}
|
||||
|
||||
func Read() error {
|
||||
var config ConfigFile
|
||||
var config File
|
||||
|
||||
path, err := getConfigPath()
|
||||
if err != nil {
|
||||
|
||||
@@ -5,17 +5,22 @@ var switches = []*Switch{
|
||||
&Switch{
|
||||
Key: "sortReversed",
|
||||
Val: false,
|
||||
Label: "Reverse Sort Order",
|
||||
Label: "Reverse sort order",
|
||||
},
|
||||
&Switch{
|
||||
Key: "allContainers",
|
||||
Val: true,
|
||||
Label: "Show All Containers",
|
||||
Label: "Show all containers",
|
||||
},
|
||||
&Switch{
|
||||
Key: "fullRowCursor",
|
||||
Val: true,
|
||||
Label: "Highlight entire cursor row (vs. name only)",
|
||||
},
|
||||
&Switch{
|
||||
Key: "enableHeader",
|
||||
Val: true,
|
||||
Label: "Enable Status Header",
|
||||
Label: "Enable status header",
|
||||
},
|
||||
&Switch{
|
||||
Key: "scaleCpu",
|
||||
@@ -56,7 +61,7 @@ func UpdateSwitch(k string, val bool) {
|
||||
// Toggle a boolean switch
|
||||
func Toggle(k string) {
|
||||
sw := GetSwitch(k)
|
||||
newVal := sw.Val != true
|
||||
newVal := !sw.Val
|
||||
log.Noticef("config change: %s: %t -> %t", k, sw.Val, newVal)
|
||||
sw.Val = newVal
|
||||
//log.Errorf("ignoring toggle for non-existant switch: %s", k)
|
||||
|
||||
@@ -48,7 +48,7 @@ func (l *DockerLogs) Stream() chan models.Log {
|
||||
for scanner.Scan() {
|
||||
parts := strings.Split(scanner.Text(), " ")
|
||||
ts := l.parseTime(parts[0])
|
||||
logCh <- models.Log{ts, strings.Join(parts[1:], " ")}
|
||||
logCh <- models.Log{Timestamp: ts, Message: strings.Join(parts[1:], " ")}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -62,10 +62,8 @@ func (l *DockerLogs) Stream() chan models.Log {
|
||||
}()
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case <-l.done:
|
||||
cancel()
|
||||
}
|
||||
<-l.done
|
||||
cancel()
|
||||
}()
|
||||
|
||||
log.Infof("log reader started for container: %s", l.id)
|
||||
|
||||
@@ -20,7 +20,7 @@ func (l *MockLogs) Stream() chan models.Log {
|
||||
case <-l.done:
|
||||
break
|
||||
default:
|
||||
logCh <- models.Log{time.Now(), mockLog}
|
||||
logCh <- models.Log{Timestamp: time.Now(), Message: mockLog}
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build !darwin
|
||||
// +build linux
|
||||
|
||||
package collector
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build !darwin
|
||||
// +build linux
|
||||
|
||||
package collector
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
api "github.com/fsouza/go-dockerclient"
|
||||
)
|
||||
|
||||
func init() { enabled["docker"] = NewDocker }
|
||||
|
||||
type Docker struct {
|
||||
client *api.Client
|
||||
containers map[string]*container.Container
|
||||
@@ -78,6 +80,17 @@ func portsFormat(ports map[api.Port][]api.PortBinding) string {
|
||||
return strings.Join(append(exposed, published...), "\n")
|
||||
}
|
||||
|
||||
func ipsFormat(networks map[string]api.ContainerNetwork) string {
|
||||
var ips []string
|
||||
|
||||
for k, v := range networks {
|
||||
s := fmt.Sprintf("%s:%s", k, v.IPAddress)
|
||||
ips = append(ips, s)
|
||||
}
|
||||
|
||||
return strings.Join(ips, "\n")
|
||||
}
|
||||
|
||||
func (cm *Docker) refresh(c *container.Container) {
|
||||
insp := cm.inspect(c.Id)
|
||||
// remove container if no longer exists
|
||||
@@ -87,16 +100,20 @@ func (cm *Docker) refresh(c *container.Container) {
|
||||
}
|
||||
c.SetMeta("name", shortName(insp.Name))
|
||||
c.SetMeta("image", insp.Config.Image)
|
||||
c.SetMeta("IPs", ipsFormat(insp.NetworkSettings.Networks))
|
||||
c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports))
|
||||
c.SetMeta("created", insp.Created.Format("Mon Jan 2 15:04:05 2006"))
|
||||
c.SetMeta("health", insp.State.Health.Status)
|
||||
for _, env := range insp.Config.Env {
|
||||
c.SetMeta("[ENV-VAR]", env)
|
||||
}
|
||||
c.SetState(insp.State.Status)
|
||||
}
|
||||
|
||||
func (cm *Docker) inspect(id string) *api.Container {
|
||||
c, err := cm.client.InspectContainer(id)
|
||||
if err != nil {
|
||||
if _, ok := err.(*api.NoSuchContainer); ok == false {
|
||||
if _, ok := err.(*api.NoSuchContainer); !ok {
|
||||
log.Errorf(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/bcicen/ctop/container"
|
||||
"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) {
|
||||
if _, ok := enabled[s]; !ok {
|
||||
msg := fmt.Sprintf("invalid connector type \"%s\"\nconnector must be one of:", s)
|
||||
for k, _ := range enabled {
|
||||
msg += fmt.Sprintf("\n %s", k)
|
||||
}
|
||||
return nil, fmt.Errorf(msg)
|
||||
if cfn, ok := enabled[s]; ok {
|
||||
return cfn(), nil
|
||||
}
|
||||
return enabled[s](), nil
|
||||
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
|
||||
}
|
||||
|
||||
type Connector interface {
|
||||
|
||||
@@ -42,3 +42,24 @@ func (dc *Docker) Remove() error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *Docker) Pause() error {
|
||||
if err := dc.client.PauseContainer(dc.id); err != nil {
|
||||
return fmt.Errorf("cannot pause container: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *Docker) Unpause() error {
|
||||
if err := dc.client.UnpauseContainer(dc.id); err != nil {
|
||||
return fmt.Errorf("cannot unpause container: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dc *Docker) Restart() error {
|
||||
if err := dc.client.RestartContainer(dc.id, 3); err != nil {
|
||||
return fmt.Errorf("cannot restart container: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,4 +4,7 @@ type Manager interface {
|
||||
Start() error
|
||||
Stop() error
|
||||
Remove() error
|
||||
Pause() error
|
||||
Unpause() error
|
||||
Restart() error
|
||||
}
|
||||
|
||||
@@ -17,3 +17,15 @@ func (m *Mock) Stop() error {
|
||||
func (m *Mock) Remove() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mock) Pause() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mock) Unpause() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Mock) Restart() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,3 +17,15 @@ func (rc *Runc) Stop() error {
|
||||
func (rc *Runc) Remove() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rc *Runc) Pause() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rc *Runc) Unpause() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rc *Runc) Restart() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ import (
|
||||
"github.com/nu7hatch/gouuid"
|
||||
)
|
||||
|
||||
func init() { enabled["mock"] = NewMock }
|
||||
|
||||
type Mock struct {
|
||||
containers container.Containers
|
||||
}
|
||||
|
||||
func NewMock() *Mock {
|
||||
func NewMock() Connector {
|
||||
cs := &Mock{}
|
||||
go cs.Init()
|
||||
go cs.Loop()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build !darwin
|
||||
// +build linux
|
||||
|
||||
package connector
|
||||
|
||||
@@ -17,6 +17,8 @@ import (
|
||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
||||
)
|
||||
|
||||
func init() { enabled["runc"] = NewRunc }
|
||||
|
||||
type RuncOpts struct {
|
||||
root string // runc root path
|
||||
systemdCgroups bool // use systemd cgroups
|
||||
|
||||
@@ -13,6 +13,10 @@ var (
|
||||
log = logging.Init()
|
||||
)
|
||||
|
||||
const (
|
||||
running = "running"
|
||||
)
|
||||
|
||||
// Metrics and metadata representing a container
|
||||
type Container struct {
|
||||
models.Metrics
|
||||
@@ -60,12 +64,12 @@ func (c *Container) GetMeta(k string) string {
|
||||
func (c *Container) SetState(s string) {
|
||||
c.SetMeta("state", s)
|
||||
// start collector, if needed
|
||||
if s == "running" && !c.collector.Running() {
|
||||
if s == running && !c.collector.Running() {
|
||||
c.collector.Start()
|
||||
c.Read(c.collector.Stream())
|
||||
}
|
||||
// stop collector, if needed
|
||||
if s != "running" && c.collector.Running() {
|
||||
if s != running && c.collector.Running() {
|
||||
c.collector.Stop()
|
||||
}
|
||||
}
|
||||
@@ -90,18 +94,18 @@ func (c *Container) Read(stream chan models.Metrics) {
|
||||
}
|
||||
|
||||
func (c *Container) Start() {
|
||||
if c.Meta["state"] != "running" {
|
||||
if c.Meta["state"] != running {
|
||||
if err := c.manager.Start(); err != nil {
|
||||
log.Warningf("container %s: %v", c.Id, err)
|
||||
log.StatusErr(err)
|
||||
return
|
||||
}
|
||||
c.SetState("running")
|
||||
c.SetState(running)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) Stop() {
|
||||
if c.Meta["state"] == "running" {
|
||||
if c.Meta["state"] == running {
|
||||
if err := c.manager.Stop(); err != nil {
|
||||
log.Warningf("container %s: %v", c.Id, err)
|
||||
log.StatusErr(err)
|
||||
@@ -117,3 +121,35 @@ func (c *Container) Remove() {
|
||||
log.StatusErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) Pause() {
|
||||
if c.Meta["state"] == running {
|
||||
if err := c.manager.Pause(); err != nil {
|
||||
log.Warningf("container %s: %v", c.Id, err)
|
||||
log.StatusErr(err)
|
||||
return
|
||||
}
|
||||
c.SetState("paused")
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) Unpause() {
|
||||
if c.Meta["state"] == "paused" {
|
||||
if err := c.manager.Unpause(); err != nil {
|
||||
log.Warningf("container %s: %v", c.Id, err)
|
||||
log.StatusErr(err)
|
||||
return
|
||||
}
|
||||
c.SetState(running)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) Restart() {
|
||||
if c.Meta["state"] == running {
|
||||
if err := c.manager.Restart(); err != nil {
|
||||
log.Warningf("container %s: %v", c.Id, err)
|
||||
log.StatusErr(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
cursor.go
20
cursor.go
@@ -57,11 +57,11 @@ func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
||||
// Set an initial cursor position, if possible
|
||||
func (gc *GridCursor) Reset() {
|
||||
for _, c := range gc.cSource.All() {
|
||||
c.Widgets.Name.UnHighlight()
|
||||
c.Widgets.UnHighlight()
|
||||
}
|
||||
if gc.Len() > 0 {
|
||||
gc.selectedID = gc.filtered[0].Id
|
||||
gc.filtered[0].Widgets.Name.Highlight()
|
||||
gc.filtered[0].Widgets.Highlight()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,9 @@ func (gc *GridCursor) Up() {
|
||||
active := gc.filtered[idx]
|
||||
next := gc.filtered[idx-1]
|
||||
|
||||
active.Widgets.Name.UnHighlight()
|
||||
active.Widgets.UnHighlight()
|
||||
gc.selectedID = next.Id
|
||||
next.Widgets.Name.Highlight()
|
||||
next.Widgets.Highlight()
|
||||
|
||||
gc.ScrollPage()
|
||||
ui.Render(cGrid)
|
||||
@@ -128,9 +128,9 @@ func (gc *GridCursor) Down() {
|
||||
active := gc.filtered[idx]
|
||||
next := gc.filtered[idx+1]
|
||||
|
||||
active.Widgets.Name.UnHighlight()
|
||||
active.Widgets.UnHighlight()
|
||||
gc.selectedID = next.Id
|
||||
next.Widgets.Name.Highlight()
|
||||
next.Widgets.Highlight()
|
||||
|
||||
gc.ScrollPage()
|
||||
ui.Render(cGrid)
|
||||
@@ -151,9 +151,9 @@ func (gc *GridCursor) PgUp() {
|
||||
active := gc.filtered[idx]
|
||||
next := gc.filtered[nextidx]
|
||||
|
||||
active.Widgets.Name.UnHighlight()
|
||||
active.Widgets.UnHighlight()
|
||||
gc.selectedID = next.Id
|
||||
next.Widgets.Name.Highlight()
|
||||
next.Widgets.Highlight()
|
||||
|
||||
cGrid.Align()
|
||||
ui.Render(cGrid)
|
||||
@@ -174,9 +174,9 @@ func (gc *GridCursor) PgDown() {
|
||||
active := gc.filtered[idx]
|
||||
next := gc.filtered[nextidx]
|
||||
|
||||
active.Widgets.Name.UnHighlight()
|
||||
active.Widgets.UnHighlight()
|
||||
gc.selectedID = next.Id
|
||||
next.Widgets.Name.Highlight()
|
||||
next.Widgets.Highlight()
|
||||
|
||||
cGrid.Align()
|
||||
ui.Render(cGrid)
|
||||
|
||||
@@ -23,6 +23,16 @@ func (w *GaugeCol) Reset() {
|
||||
w.Percent = 0
|
||||
}
|
||||
|
||||
func (w *GaugeCol) Highlight() {
|
||||
w.Bg = ui.ThemeAttr("par.text.fg")
|
||||
w.PercentColor = ui.ThemeAttr("par.text.hi")
|
||||
}
|
||||
|
||||
func (w *GaugeCol) UnHighlight() {
|
||||
w.Bg = ui.ThemeAttr("par.text.bg")
|
||||
w.PercentColor = ui.ThemeAttr("par.text.bg")
|
||||
}
|
||||
|
||||
func colorScale(n int) ui.Attribute {
|
||||
if n > 70 {
|
||||
return ui.ThemeAttr("status.danger")
|
||||
|
||||
@@ -23,10 +23,7 @@ func NewCompactGrid() *CompactGrid {
|
||||
func (cg *CompactGrid) Align() {
|
||||
y := cg.Y
|
||||
|
||||
if cg.Offset >= len(cg.Rows) {
|
||||
cg.Offset = 0
|
||||
}
|
||||
if cg.Offset < 0 {
|
||||
if cg.Offset >= len(cg.Rows) || cg.Offset < 0 {
|
||||
cg.Offset = 0
|
||||
}
|
||||
|
||||
@@ -60,7 +57,5 @@ func (cg *CompactGrid) Buffer() ui.Buffer {
|
||||
}
|
||||
|
||||
func (cg *CompactGrid) AddRows(rows ...ui.GridBufferer) {
|
||||
for _, r := range rows {
|
||||
cg.Rows = append(cg.Rows, r)
|
||||
}
|
||||
cg.Rows = append(cg.Rows, rows...)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package compact
|
||||
|
||||
import (
|
||||
"github.com/bcicen/ctop/config"
|
||||
"github.com/bcicen/ctop/logging"
|
||||
"github.com/bcicen/ctop/models"
|
||||
ui "github.com/gizak/termui"
|
||||
@@ -17,6 +18,7 @@ type Compact struct {
|
||||
Net *TextCol
|
||||
IO *TextCol
|
||||
Pids *TextCol
|
||||
Bg *RowBg
|
||||
X, Y int
|
||||
Width int
|
||||
Height int
|
||||
@@ -36,6 +38,7 @@ func NewCompact(id string) *Compact {
|
||||
Net: NewTextCol("-"),
|
||||
IO: NewTextCol("-"),
|
||||
Pids: NewTextCol("-"),
|
||||
Bg: NewRowBg(),
|
||||
X: 1,
|
||||
Height: 1,
|
||||
}
|
||||
@@ -90,6 +93,8 @@ func (row *Compact) SetY(y int) {
|
||||
if y == row.Y {
|
||||
return
|
||||
}
|
||||
|
||||
row.Bg.Y = y
|
||||
for _, col := range row.all() {
|
||||
col.SetY(y)
|
||||
}
|
||||
@@ -101,6 +106,10 @@ func (row *Compact) SetWidth(width int) {
|
||||
return
|
||||
}
|
||||
x := row.X
|
||||
|
||||
row.Bg.SetX(x + colWidths[0] + 1)
|
||||
row.Bg.SetWidth(width)
|
||||
|
||||
autoWidth := calcWidth(width)
|
||||
for n, col := range row.all() {
|
||||
if colWidths[n] != 0 {
|
||||
@@ -119,6 +128,7 @@ func (row *Compact) SetWidth(width int) {
|
||||
func (row *Compact) Buffer() ui.Buffer {
|
||||
buf := ui.NewBuffer()
|
||||
|
||||
buf.Merge(row.Bg.Buffer())
|
||||
buf.Merge(row.Status.Buffer())
|
||||
buf.Merge(row.Name.Buffer())
|
||||
buf.Merge(row.Cid.Buffer())
|
||||
@@ -142,3 +152,44 @@ func (row *Compact) all() []ui.GridBufferer {
|
||||
row.Pids,
|
||||
}
|
||||
}
|
||||
|
||||
func (row *Compact) Highlight() {
|
||||
row.Name.Highlight()
|
||||
if config.GetSwitchVal("fullRowCursor") {
|
||||
row.Bg.Highlight()
|
||||
row.Cid.Highlight()
|
||||
row.Cpu.Highlight()
|
||||
row.Mem.Highlight()
|
||||
row.Net.Highlight()
|
||||
row.IO.Highlight()
|
||||
row.Pids.Highlight()
|
||||
}
|
||||
}
|
||||
|
||||
func (row *Compact) UnHighlight() {
|
||||
row.Name.UnHighlight()
|
||||
if config.GetSwitchVal("fullRowCursor") {
|
||||
row.Bg.UnHighlight()
|
||||
row.Cid.UnHighlight()
|
||||
row.Cpu.UnHighlight()
|
||||
row.Mem.UnHighlight()
|
||||
row.Net.UnHighlight()
|
||||
row.IO.UnHighlight()
|
||||
row.Pids.UnHighlight()
|
||||
}
|
||||
}
|
||||
|
||||
type RowBg struct {
|
||||
*ui.Par
|
||||
}
|
||||
|
||||
func NewRowBg() *RowBg {
|
||||
bg := ui.NewPar("")
|
||||
bg.Height = 1
|
||||
bg.Border = false
|
||||
bg.Bg = ui.ThemeAttr("par.text.bg")
|
||||
return &RowBg{bg}
|
||||
}
|
||||
|
||||
func (w *RowBg) Highlight() { w.Bg = ui.ThemeAttr("par.text.fg") }
|
||||
func (w *RowBg) UnHighlight() { w.Bg = ui.ThemeAttr("par.text.bg") }
|
||||
|
||||
@@ -19,7 +19,7 @@ func (row *Compact) SetIO(read int64, write int64) {
|
||||
}
|
||||
|
||||
func (row *Compact) SetPids(val int) {
|
||||
label := fmt.Sprintf("%s", strconv.Itoa(val))
|
||||
label := strconv.Itoa(val)
|
||||
row.Pids.Set(label)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,13 @@ func NewTextCol(s string) *TextCol {
|
||||
}
|
||||
|
||||
func (w *TextCol) Highlight() {
|
||||
w.Bg = ui.ThemeAttr("par.text.fg")
|
||||
w.TextFgColor = ui.ThemeAttr("par.text.hi")
|
||||
w.TextBgColor = ui.ThemeAttr("par.text.fg")
|
||||
}
|
||||
|
||||
func (w *TextCol) UnHighlight() {
|
||||
w.Bg = ui.ThemeAttr("par.text.bg")
|
||||
w.TextFgColor = ui.ThemeAttr("par.text.fg")
|
||||
w.TextBgColor = ui.ThemeAttr("par.text.bg")
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package compact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
@@ -28,7 +29,7 @@ func calcWidth(width int) int {
|
||||
for _, w := range colWidths {
|
||||
width -= w
|
||||
if w == 0 {
|
||||
staticCols += 1
|
||||
staticCols++
|
||||
}
|
||||
}
|
||||
return (width - spacing) / staticCols
|
||||
|
||||
36
cwidgets/single/env.go
Normal file
36
cwidgets/single/env.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package single
|
||||
|
||||
import (
|
||||
ui "github.com/gizak/termui"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var envPattern = regexp.MustCompile(`(?P<KEY>[^=]+)=(?P<VALUJE>.*)`)
|
||||
|
||||
type Env struct {
|
||||
*ui.Table
|
||||
data map[string]string
|
||||
}
|
||||
|
||||
func NewEnv() *Env {
|
||||
p := ui.NewTable()
|
||||
p.Height = 4
|
||||
p.Width = colWidth[0]
|
||||
p.FgColor = ui.ThemeAttr("par.text.fg")
|
||||
p.Separator = false
|
||||
i := &Env{p, make(map[string]string)}
|
||||
i.BorderLabel = "Env"
|
||||
return i
|
||||
}
|
||||
|
||||
func (w *Env) Set(k, v string) {
|
||||
match := envPattern.FindStringSubmatch(v)
|
||||
key := match[1]
|
||||
value := match[2]
|
||||
w.data[key] = value
|
||||
|
||||
w.Rows = [][]string{}
|
||||
w.Rows = append(w.Rows, mkInfoRows(key, value)...)
|
||||
|
||||
w.Height = len(w.Rows) + 2
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
ui "github.com/gizak/termui"
|
||||
)
|
||||
|
||||
var displayInfo = []string{"id", "name", "image", "ports", "state", "created", "health"}
|
||||
var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "health"}
|
||||
|
||||
type Info struct {
|
||||
*ui.Table
|
||||
@@ -45,7 +45,7 @@ func mkInfoRows(k, v string) (rows [][]string) {
|
||||
// initial row with field name
|
||||
rows = append(rows, []string{k, lines[0]})
|
||||
|
||||
// append any additional lines in seperate row
|
||||
// append any additional lines in separate row
|
||||
if len(lines) > 1 {
|
||||
for _, line := range lines[1:] {
|
||||
if line != "" {
|
||||
|
||||
@@ -18,6 +18,7 @@ type Single struct {
|
||||
Cpu *Cpu
|
||||
Mem *Mem
|
||||
IO *IO
|
||||
Env *Env
|
||||
X, Y int
|
||||
Width int
|
||||
}
|
||||
@@ -32,6 +33,7 @@ func NewSingle(id string) *Single {
|
||||
Cpu: NewCpu(),
|
||||
Mem: NewMem(),
|
||||
IO: NewIO(),
|
||||
Env: NewEnv(),
|
||||
Width: ui.TermWidth(),
|
||||
}
|
||||
}
|
||||
@@ -52,8 +54,14 @@ func (e *Single) Down() {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Single) SetWidth(w int) { e.Width = w }
|
||||
func (e *Single) SetMeta(k, v string) { e.Info.Set(k, v) }
|
||||
func (e *Single) SetWidth(w int) { e.Width = w }
|
||||
func (e *Single) SetMeta(k, v string) {
|
||||
if k == "[ENV-VAR]" {
|
||||
e.Env.Set(k, v)
|
||||
} else {
|
||||
e.Info.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Single) SetMetrics(m models.Metrics) {
|
||||
e.Cpu.Update(m.CPUUtil)
|
||||
@@ -69,6 +77,7 @@ func (e *Single) GetHeight() (h int) {
|
||||
h += e.Cpu.Height
|
||||
h += e.Mem.Height
|
||||
h += e.IO.Height
|
||||
h += e.Env.Height
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -103,6 +112,7 @@ func (e *Single) Buffer() ui.Buffer {
|
||||
buf.Merge(e.Mem.Buffer())
|
||||
buf.Merge(e.Net.Buffer())
|
||||
buf.Merge(e.IO.Buffer())
|
||||
buf.Merge(e.Env.Buffer())
|
||||
return buf
|
||||
}
|
||||
|
||||
@@ -113,6 +123,7 @@ func (e *Single) all() []ui.GridBufferer {
|
||||
e.Mem,
|
||||
e.Net,
|
||||
e.IO,
|
||||
e.Env,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
41
go.mod
Normal file
41
go.mod
Normal file
@@ -0,0 +1,41 @@
|
||||
module github.com/bcicen/ctop
|
||||
|
||||
require (
|
||||
github.com/Azure/go-ansiterm v0.0.0-20160622173216-fa152c58bc15 // indirect
|
||||
github.com/BurntSushi/toml v0.3.0
|
||||
github.com/Microsoft/go-winio v0.3.8 // indirect
|
||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
|
||||
github.com/Sirupsen/logrus v0.0.0-20150423025312-26709e271410 // indirect
|
||||
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd
|
||||
github.com/coreos/go-systemd v0.0.0-20151104194251-b4a58d95188d // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/docker/docker v0.0.0-20170502054910-90d35abf7b35 // indirect
|
||||
github.com/docker/go-connections v0.0.0-20170301234100-a2afab980204 // indirect
|
||||
github.com/docker/go-units v0.3.2 // indirect
|
||||
github.com/fsouza/go-dockerclient v0.0.0-20170307141636-318513eb1ab2
|
||||
github.com/gizak/termui v2.3.0+incompatible
|
||||
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55 // indirect
|
||||
github.com/golang/protobuf v0.0.0-20170712042213-0a4f71a498b7 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.0.0-20170211013415-3573b8b52aa7 // indirect
|
||||
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/maruel/panicparse v0.0.0-20170227222818-25bcac0d793c // indirect
|
||||
github.com/maruel/ut v1.0.0 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.0-20170201023540-14207d285c6c // indirect
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||
github.com/nsf/termbox-go v0.0.0-20180303152453-e2050e41c884
|
||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
||||
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473
|
||||
github.com/opencontainers/runc v0.1.1
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/seccomp/libseccomp-golang v0.0.0-20150813023252-1b506fc7c24e // indirect
|
||||
github.com/stretchr/testify v1.2.2 // indirect
|
||||
github.com/syndtr/gocapability v0.0.0-20150716010906-2c00daeb6c3b // indirect
|
||||
github.com/vishvananda/netlink v0.0.0-20150820014904-1e2e08e8a2dc // indirect
|
||||
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect
|
||||
golang.org/x/net v0.0.0-20170308210134-a6577fac2d73 // indirect
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
|
||||
golang.org/x/sys v0.0.0-20170308153327-99f16d856c98 // indirect
|
||||
)
|
||||
|
||||
replace github.com/gizak/termui => github.com/bcicen/termui v0.0.0-20180326052246-4eb80249d3f5
|
||||
8
grid.go
8
grid.go
@@ -104,6 +104,14 @@ func Display() bool {
|
||||
menu = ContainerMenu
|
||||
ui.StopLoop()
|
||||
})
|
||||
ui.Handle("/sys/kbd/<left>", func(ui.Event) {
|
||||
menu = LogMenu
|
||||
ui.StopLoop()
|
||||
})
|
||||
ui.Handle("/sys/kbd/<right>", func(ui.Event) {
|
||||
menu = SingleView
|
||||
ui.StopLoop()
|
||||
})
|
||||
ui.Handle("/sys/kbd/l", func(ui.Event) {
|
||||
menu = LogMenu
|
||||
ui.StopLoop()
|
||||
|
||||
26
install.sh
26
install.sh
@@ -5,6 +5,10 @@ KERNEL=$(uname -s)
|
||||
|
||||
function output() { echo -e "\033[32mctop-install\033[0m $@"; }
|
||||
|
||||
function command_exists() {
|
||||
command -v "$@" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
# extract github download url matching pattern
|
||||
function extract_url() {
|
||||
match=$1; shift
|
||||
@@ -28,6 +32,26 @@ case $KERNEL in
|
||||
;;
|
||||
esac
|
||||
|
||||
for req in curl wget; do
|
||||
command_exists $req || {
|
||||
output "missing required $req binary"
|
||||
req_failed=1
|
||||
}
|
||||
done
|
||||
[ "$req_failed" == 1 ] && exit 1
|
||||
|
||||
sh_c='sh -c'
|
||||
if [ "$CURRENT_USER" != 'root' ]; then
|
||||
if command_exists sudo; then
|
||||
sh_c='sudo -E sh -c'
|
||||
elif command_exists su; then
|
||||
sh_c='su -c'
|
||||
else
|
||||
output "Error: this installer needs the ability to run commands as root. We are unable to find either "sudo" or "su" available to make this happen."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/ctop.XXXXX")
|
||||
cd ${TMP}
|
||||
|
||||
@@ -55,6 +79,6 @@ wget -q --show-progress $url
|
||||
|
||||
output "installing to /usr/local/bin"
|
||||
chmod +x ctop-*
|
||||
sudo mv ctop-* /usr/local/bin/ctop
|
||||
$sh_c "mv ctop-* /usr/local/bin/ctop"
|
||||
|
||||
output "done!"
|
||||
|
||||
@@ -2,6 +2,7 @@ package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
)
|
||||
@@ -56,13 +57,13 @@ func StopServer() {
|
||||
}
|
||||
}
|
||||
|
||||
func handler(conn net.Conn) {
|
||||
func handler(wc io.WriteCloser) {
|
||||
server.wg.Add(1)
|
||||
defer server.wg.Done()
|
||||
defer conn.Close()
|
||||
defer wc.Close()
|
||||
for msg := range Log.tail() {
|
||||
msg = fmt.Sprintf("%s\n", msg)
|
||||
conn.Write([]byte(msg))
|
||||
wc.Write([]byte(msg))
|
||||
}
|
||||
conn.Write([]byte("bye\n"))
|
||||
wc.Write([]byte("bye\n"))
|
||||
}
|
||||
|
||||
6
main.go
6
main.go
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/bcicen/ctop/config"
|
||||
"github.com/bcicen/ctop/connector"
|
||||
@@ -94,6 +95,7 @@ func main() {
|
||||
if err := ui.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tm.SetInputMode(tm.InputAlt)
|
||||
|
||||
defer Shutdown()
|
||||
// init grid, cursor, header
|
||||
@@ -138,7 +140,7 @@ func panicExit() {
|
||||
}
|
||||
}
|
||||
|
||||
var helpMsg = `ctop - container metric viewer
|
||||
var helpMsg = `ctop - interactive container viewer
|
||||
|
||||
usage: ctop [options]
|
||||
|
||||
@@ -148,4 +150,6 @@ options:
|
||||
func printHelp() {
|
||||
fmt.Println(helpMsg)
|
||||
flag.PrintDefaults()
|
||||
fmt.Printf("\navailable connectors: ")
|
||||
fmt.Println(strings.Join(connector.Enabled(), ", "))
|
||||
}
|
||||
|
||||
18
menus.go
18
menus.go
@@ -37,7 +37,10 @@ func HelpMenu() MenuFn {
|
||||
m := menu.NewMenu()
|
||||
m.BorderLabel = "Help"
|
||||
m.AddItems(helpDialog...)
|
||||
ui.Render(m)
|
||||
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||
ui.Clear()
|
||||
ui.Render(m)
|
||||
})
|
||||
ui.Handle("/sys/kbd/", func(ui.Event) {
|
||||
ui.StopLoop()
|
||||
})
|
||||
@@ -129,11 +132,16 @@ func ContainerMenu() MenuFn {
|
||||
|
||||
if c.Meta["state"] == "running" {
|
||||
items = append(items, menu.Item{Val: "stop", Label: "stop"})
|
||||
items = append(items, menu.Item{Val: "pause", Label: "pause"})
|
||||
items = append(items, menu.Item{Val: "restart", Label: "restart"})
|
||||
}
|
||||
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
|
||||
items = append(items, menu.Item{Val: "start", Label: "start"})
|
||||
items = append(items, menu.Item{Val: "remove", Label: "remove"})
|
||||
}
|
||||
if c.Meta["state"] == "paused" {
|
||||
items = append(items, menu.Item{Val: "unpause", Label: "unpause"})
|
||||
}
|
||||
items = append(items, menu.Item{Val: "cancel", Label: "cancel"})
|
||||
|
||||
m.AddItems(items...)
|
||||
@@ -154,6 +162,12 @@ func ContainerMenu() MenuFn {
|
||||
nextMenu = Confirm(confirmTxt("stop", c.GetMeta("name")), c.Stop)
|
||||
case "remove":
|
||||
nextMenu = Confirm(confirmTxt("remove", c.GetMeta("name")), c.Remove)
|
||||
case "pause":
|
||||
nextMenu = Confirm(confirmTxt("pause", c.GetMeta("name")), c.Pause)
|
||||
case "unpause":
|
||||
nextMenu = Confirm(confirmTxt("unpause", c.GetMeta("name")), c.Unpause)
|
||||
case "restart":
|
||||
nextMenu = Confirm(confirmTxt("restart", c.GetMeta("name")), c.Restart)
|
||||
}
|
||||
ui.StopLoop()
|
||||
})
|
||||
@@ -176,7 +190,7 @@ func LogMenu() MenuFn {
|
||||
|
||||
logs, quit := logReader(c)
|
||||
m := widgets.NewTextView(logs)
|
||||
m.BorderLabel = "Logs"
|
||||
m.BorderLabel = fmt.Sprintf("Logs [%s]", c.GetMeta("name"))
|
||||
ui.Render(m)
|
||||
|
||||
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||
|
||||
@@ -77,7 +77,7 @@ func (i *Input) KeyPress(e ui.Event) {
|
||||
if len(i.Data) >= i.MaxLen {
|
||||
return
|
||||
}
|
||||
if strings.Index(input_chars, ch) > -1 {
|
||||
if strings.Contains(input_chars, ch) {
|
||||
i.Data += ch
|
||||
i.stream <- i.Data
|
||||
ui.Render(i)
|
||||
|
||||
Reference in New Issue
Block a user