Compare commits

..

36 Commits

Author SHA1 Message Date
Bradley Cicenas
70bd2ae3a3 v0.7.2 2019-01-24 11:50:49 +00:00
Bradley Cicenas
665e8fdd06 move to go module 2018-12-01 17:50:47 +00:00
bradley
a39b7a3a3e Merge pull request #152 from barthr/master
Refactoring improvements based on linting issues
2018-10-26 09:00:02 -05:00
bartfokker
77f5e6b735 remove ignore of variable (unneeded when only index is needed) 2018-10-25 22:25:36 +02:00
bartfokker
3c83b7576b refactor string on multiple places to constant 2018-10-25 22:23:44 +02:00
bartfokker
8a0bd3cf8a remove unneeded cast 2018-10-25 22:22:28 +02:00
bartfokker
78caad2dbd depend on io.WriteCloser instead of net.Conn 2018-10-25 22:22:04 +02:00
bartfokker
8d8f1e72eb rename ConfigFile to File because config.ConfigFile stutters. Instead it's config.File 2018-10-25 22:21:08 +02:00
bartfokker
93556a1754 replace += with ++ 2018-10-25 22:17:53 +02:00
bartfokker
4d247f5272 replace unkeyed fiels with keyed fields when instantiating log struct 2018-10-25 22:17:05 +02:00
bartfokker
db3d7e8927 change strings.Index for strings.Contains 2018-10-25 22:14:00 +02:00
bartfokker
efef345665 remove unneeded fmt.Sprintf 2018-10-25 22:13:04 +02:00
bartfokker
f158fa742f simplify append operation by omitting loop 2018-10-25 22:12:46 +02:00
bartfokker
4d48245d7d improve boolean logic 2018-10-25 22:12:17 +02:00
bartfokker
6bee1b7f31 remove unneeded select for simple channel receive 2018-10-25 22:11:17 +02:00
bartfokker
7118e45f3a add vendor directory to gitignore 2018-10-25 22:04:40 +02:00
bradley
3405d19be8 Merge pull request #147 from serg-bloim/env-var
Display environment variables on single view page
2018-10-10 21:45:08 +08:00
Serhii Bilonozhko
9a185b2388 env-var 2018-10-05 17:35:22 -04:00
Bradley Cicenas
caf6fc63c1 add config toggle for full-row cursor 2018-09-17 01:33:52 +00:00
Bradley Cicenas
cf352f7c8a implement full-row cursor highlighting 2018-09-17 01:24:06 +00:00
bradley
ac5bed210f Merge pull request #143 from jphautin/add_networks_ips
add IP of networks in single view mode
2018-09-15 10:43:22 +09:00
Jean-Philippe
a72d43526f add IP of networks in single view mode 2018-09-06 21:01:16 +02:00
bradley
9eb2457aa4 Merge pull request #132 from xiechengsheng/fix-120
add support for alternative navigation
2018-06-30 08:31:44 +02:00
Bradley Cicenas
b83402b886 add TERM env var to Dockerfile 2018-06-28 11:19:07 +00:00
xiechengsheng
078564bd38 add support for alternative navigation
Signed-off-by: xiechengsheng <XIE1995@whut.edu.cn>
2018-06-28 16:40:26 +08:00
bradley
a2c08d312e Merge pull request #131 from xiechengsheng/add-pause-unpause
Feature: add more commands in container manager menu
2018-06-28 10:25:45 +02:00
xiechengsheng
f7a3d38d6b add more commands in container manager menu
Signed-off-by: xiechengsheng <XIE1995@whut.edu.cn>
2018-06-22 15:41:16 +08:00
Bradley Cicenas
a3b8585697 add requirement check to install script 2018-06-13 09:20:05 +00:00
bradley
2e526e9b86 Merge pull request #130 from felipeconti/master
Installing on /usr/local/bin as root
2018-06-13 11:04:34 +02:00
Felipe B. Conti
541fe70b78 Remove unnecessary treatment 2018-06-10 14:12:07 -03:00
Felipe Conti
c786b697bf Add function command_exists 2018-06-10 14:04:34 -03:00
Felipe Conti
aa6c00b083 Treatment to use root 2018-06-10 14:02:42 -03:00
Bradley Cicenas
17855e3d8e add container name to log view title 2018-05-10 09:53:59 +00:00
Bradley Cicenas
842809bef5 enable termbox alt input 2018-05-10 09:44:57 +00:00
Bradley Cicenas
4e567ee007 update README 2018-03-09 05:37:36 +00:00
Bradley Cicenas
56700e120b add go-winio dep 2018-03-09 05:28:11 +00:00
35 changed files with 356 additions and 269 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
ctop
.idea
.idea
/vendor/

View File

@@ -1,16 +1,17 @@
FROM quay.io/vektorcloud/go:1.10
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"]

165
Gopkg.lock generated
View File

@@ -1,165 +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/BurntSushi/toml"
packages = ["."]
revision = "b26d9c308763d68093482582cea63d69be07a0f0"
version = "v0.3.0"
[[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 = "master"
name = "github.com/gizak/termui"
packages = ["."]
revision = "cdc199d7ea432fd8187db35f0247285d6f5b0267"
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 = "e2050e41c8847748ec5288741c0b19a8cb26d084"
[[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 = "f46f5c696ecb0b0c42a38dac512df21fc1f5fb2bfda888434e005e69d1b6273b"
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -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 = "master"
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"

View File

@@ -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:

View File

@@ -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
```

View File

@@ -1 +1 @@
0.7.1
0.7.2

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)
}
}

View File

@@ -80,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
@@ -89,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())
}
}

View File

@@ -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
}

View File

@@ -4,4 +4,7 @@ type Manager interface {
Start() error
Stop() error
Remove() error
Pause() error
Unpause() error
Restart() error
}

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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
}
}
}

View File

@@ -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)

View File

@@ -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")

View File

@@ -57,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...)
}

View File

@@ -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") }

View File

@@ -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)
}

View File

@@ -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")
}

View File

@@ -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
View 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
}

View File

@@ -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 != "" {

View File

@@ -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
View 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

View File

@@ -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()

View File

@@ -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!"

View File

@@ -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"))
}

View File

@@ -95,6 +95,7 @@ func main() {
if err := ui.Init(); err != nil {
panic(err)
}
tm.SetInputMode(tm.InputAlt)
defer Shutdown()
// init grid, cursor, header

View File

@@ -132,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...)
@@ -157,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()
})
@@ -179,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) {

View File

@@ -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)