Compare commits

...

318 Commits

Author SHA1 Message Date
bradley 59f00dd6aa
Merge pull request #296 from utix/patch-1
Fix running icon
2022-08-01 06:32:57 -05:00
bradley 06265407b2
Merge pull request #306 from jnishwanth/patch-1
updated README.md
2022-08-01 06:24:33 -05:00
bradley a08150ea9c
Merge pull request #303 from wdiazux/master
Fix apt-key is deprecated
2022-08-01 06:23:25 -05:00
Alex Stelmachonak 6bf41ea05f
Add Windows-specific intructions and badge for scoop (#295) 2022-08-01 07:21:06 -04:00
Jeya Nishwanth 3dff9970ad
updated README.md
`ctop` has been added to the arch community repository. Hence can be installed without the AUR now!
2022-06-12 03:07:41 +05:30
William Diaz 458ef62f80 Required packages to set up the repository 2022-05-21 23:06:07 -06:00
William Diaz a821deb3b4 Fix apt-key is deprecated 2022-05-21 22:48:46 -06:00
Aurélien Lajoie dacd3be920
Fix running icon
Use ▶ for running status
2022-04-26 19:10:52 +02:00
Bradley Cicenas 222a7d77b2 Squashed commit of the following:
commit 9968c504a5
Author: Florian Vahl <florian@flova.de>
Date:   Tue Feb 1 00:37:31 2022 +0100

    Fix formating (Spaces -> Tabs)

commit 6b8840647e
Author: Florian <florian@flova.de>
Date:   Tue Feb 1 00:27:44 2022 +0100

    Use better duration formating

commit 815dc6ec84
Author: Florian <florian@flova.de>
Date:   Tue Feb 1 00:27:04 2022 +0100

    Fix date formating in 'created' col

commit 05b17798f8
Author: Florian <florian@flova.de>
Date:   Tue Feb 1 00:26:08 2022 +0100

    Add fix from #275 for uptime of running containers
2022-03-30 14:13:10 -04:00
Bradley Cicenas 9bc26c8296 update dockerfile base image -> go1.18 2022-03-24 08:14:39 -04:00
Bradley Cicenas 5271cf6d90
update go.mod go1.17 -> go1.18 2022-03-24 11:53:43 +00:00
Bradley Cicenas a8e1fb7246
update circleci image to go1.18 2022-03-23 17:50:10 +00:00
Bradley Cicenas d60b215611
go mod tidy 2022-03-23 17:47:39 +00:00
Bradley Cicenas 79242c7de5 update go.mod 1.15 -> 1.17 2022-03-23 13:47:16 -04:00
Bradley Cicenas 6dcb62f172 remove termui fork dependency 2022-03-23 13:46:53 -04:00
DasSkelett 163060b3fa
Update runc to 1.1.0 to get newer x/sys and fix Go 1.18 build (#292)
* Update runc to 1.1.0 to get newer x/sys

...to fix building on Darwin with Go 1.18.

This required some code changes as opencontainers unfortunately introduced breaking changes in a minor revision.
However, those changes were to simpify the libcontainer factory initialization.

* Switch CircleCI image to cimg/go, update remote Docker version to 20.10
2022-03-23 13:46:40 -04:00
Bradley Cicenas acbf17a4fd
prevent index out of range panic on empty value env strings 2022-03-23 17:06:47 +00:00
Bradley Cicenas 021b1710a3
update readme 2022-03-22 13:45:12 +00:00
Bradley Cicenas 2d43cd146f
update readme version 2022-03-22 12:51:01 +00:00
Bradley Cicenas 11a1cb10f4
v0.7.7 2022-03-22 12:00:27 +00:00
Bradley Cicenas f83e73d1ea Merge branch 'dependabot/go_modules/github.com/opencontainers/runc-1.0.3' 2022-01-06 17:13:56 -05:00
Bradley Cicenas 1f91033beb Merge branch 'master' into dependabot/go_modules/github.com/opencontainers/runc-1.0.3 2022-01-06 17:13:20 -05:00
Bradley Cicenas da09b95d29
prevent panic on container IDs < 12 chars 2022-01-06 22:12:35 +00:00
Florian Vahl 350cb09338
Fix cpu count estimation (#281)
* Fix query for the number of cpu cores.

* Fix formating

* Fix formating again...
2021-12-29 11:56:22 -05:00
dependabot[bot] d8542c894c
Bump github.com/opencontainers/runc from 1.0.0-rc95 to 1.0.3
Bumps [github.com/opencontainers/runc](https://github.com/opencontainers/runc) from 1.0.0-rc95 to 1.0.3.
- [Release notes](https://github.com/opencontainers/runc/releases)
- [Commits](https://github.com/opencontainers/runc/compare/v1.0.0-rc95...v1.0.3)

---
updated-dependencies:
- dependency-name: github.com/opencontainers/runc
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-08 01:45:57 +00:00
Bradley Cicenas be23d85eda Merge remote-tracking branch 'stokito/browser' 2021-10-24 10:40:43 -04:00
bradley 2047e3fa52
Merge pull request #272 from bcicen/dependabot/go_modules/github.com/opencontainers/runc-1.0.0-rc95
Bump github.com/opencontainers/runc from 1.0.0-rc93 to 1.0.0-rc95
2021-10-24 10:35:37 -04:00
dependabot[bot] 4b653e71f6
Bump github.com/opencontainers/runc from 1.0.0-rc93 to 1.0.0-rc95
Bumps [github.com/opencontainers/runc](https://github.com/opencontainers/runc) from 1.0.0-rc93 to 1.0.0-rc95.
- [Release notes](https://github.com/opencontainers/runc/releases)
- [Commits](https://github.com/opencontainers/runc/compare/v1.0.0-rc93...v1.0.0-rc95)

---
updated-dependencies:
- dependency-name: github.com/opencontainers/runc
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-07-27 17:42:05 +00:00
Bradley Cicenas c145cf404a
match release tag to title 2021-07-01 19:32:32 +00:00
bradley 52f52a1163
Merge pull request #268 from neikei/patch-1
Added support for ppc64le
2021-06-13 10:25:11 -04:00
bradley 94f1f3f558
Merge pull request #269 from Quintenps/master
Update README.md (Fixed release download url)
2021-06-13 10:23:07 -04:00
Quinten Peels 3d5a1c0682
Update README.md
Fixed release download url in readme
2021-06-13 16:07:58 +02:00
neikei 1c3577ad4e
Added support for ppc64le 2021-06-13 15:12:27 +02:00
Bradley Cicenas b48a5cf2f9
go mod tidy 2021-06-11 18:07:31 +00:00
Bradley Cicenas 9f8f38f9d7 Merge remote-tracking branch 'remotes/stokito/events_filter' 2021-06-11 14:04:53 -04:00
bradley 2b898fb216
Merge pull request #267 from frol-kr/bugfix/issue-254-crushes-when-container-logs-opened
#254-handling-with-wrong-log-format
2021-06-11 13:46:42 -04:00
Frol Kryuchkov 99be3b979e #254-handling-with-wrong-log-format 2021-06-11 17:22:34 +03:00
bradley 29f9abf35c
Merge pull request #236 from stokito/status_unicode
Use more clear status marks
2021-06-10 22:06:40 -04:00
bradley 82e731e577
Merge pull request #239 from stokito/cpu_color
CPU upper: > 70% yellow/warn and > 90% is red/danger
2021-06-10 22:04:54 -04:00
Bradley Cicenas a603c1b58c Merge remote-tracking branch 'remotes/stokito/uptime' 2021-06-10 22:01:45 -04:00
Bradley Cicenas 8f0c9f5048
v0.7.6 2021-06-11 01:23:43 +00:00
bradley 15708224a7
Merge pull request #262 from judaew/patch-1
Add install variant via MacPorts
2021-06-10 21:19:16 -04:00
bradley 442e70b8df
Merge pull request #264 from garsue/use-runewidth-to-increment-textview-x
Use go-runewidth to increment x in TextView
2021-06-10 21:18:33 -04:00
garsue c58a609349 Update go.sum 2021-05-29 22:01:26 +09:00
garsue 78b038e687 Use runewidth to increment x in TextView 2021-05-29 19:48:02 +09:00
Vadim-Valdis Yudaev 2d937aca08 Add install variant via MacPorts 2021-05-20 17:09:14 +03:00
Sergey Ponomarev 77c9001ed1 optimize health_status event handling 2021-02-04 09:37:44 +02:00
Sergey Ponomarev d98ce102b1 Filter events 2021-02-04 09:22:57 +02:00
Sergey Ponomarev cfa43f809e Update go-dockerclient and opencontainers/runc
The go-dockerclient v1.7.0 now has an ability to specify events filter. But it's dependencies are also updated.
One of those dependencies is mountinfo and the same dependency is used by opencontainers/runc.
The problem is that mountinfo changed it's API and if we just update dockerclient then build is broken.
So we have to update both opencontainers/runc and go-dockerclient
2021-02-04 08:59:06 +02:00
bradley 0094cba5ea
Merge pull request #244 from stokito/fix_243
#243 Fix bug: show ENV variables
2020-12-14 12:29:25 -05:00
bradley 537bb2adfa
Merge pull request #247 from stokito/more_columns
More columns
2020-12-14 12:25:17 -05:00
Sergey Ponomarev 8dce3ece2b Open in browser: show menu item only if web port is published 2020-12-12 21:50:08 +02:00
Sergey Ponomarev dd92e85d45 Open in browser
Most containers expose some http port. We can open it in browser.
For simplicity we can just open first container's published port.
We'll determine the ip:port on container creation and store to meta "Web Port".
To open browser on any platform was added a new dependency github.com/pkg/browser which is very small
2020-12-12 21:21:53 +02:00
Sergey Ponomarev 491cd85b4d Additional columns 2020-12-11 21:58:37 +02:00
Sergey Ponomarev 9545dfba31 Extract MetaCol 2020-12-11 20:59:35 +02:00
Sergey Ponomarev cdcb8b6d99 columns.go: remove redundant type 2020-12-11 20:32:22 +02:00
bradley b562c923b3
Merge pull request #242 from stokito/awesome
Add Alternatives section
2020-12-09 16:10:09 -05:00
Sergey Ponomarev f2c28c5fb0 #243 Fix bug: show ENV variables
Previously only last env variable is shown
2020-12-09 23:06:14 +02:00
Sergey Ponomarev ac76b2eac1 Add Alternatives section
This may help users to find more specific tool than ctop
2020-11-30 17:25:40 +02:00
bradley b32f90fa4a
Merge pull request #240 from stokito/name_width
#128 Set column Name to fixed width 30
2020-11-29 09:19:07 -05:00
bradley bec78c90b5
Merge pull request #238 from stokito/leftovers
Use standard Go functions
2020-11-29 09:06:13 -05:00
Bradley Cicenas 043f4bd3f3
update dockerfile to go 1.15 2020-11-28 20:30:02 +00:00
Sergey Ponomarev c2401cb33a #128 Set column Name to fixed width 30 2020-11-27 23:12:16 +02:00
Sergey Ponomarev fa254c652c Columns settings: add hint for re-order columns 2020-11-27 22:34:55 +02:00
Sergey Ponomarev a59c7aab3c Fix: enable pause [p] only for running or paused container 2020-11-27 22:28:58 +02:00
Sergey Ponomarev 4e44c9d5f7 file.go use filepath.Dir() 2020-11-26 12:08:55 +02:00
Sergey Ponomarev 948e7cc9d0 docker_logs.go use SplitN(2) 2020-11-26 12:08:36 +02:00
Sergey Ponomarev 4850f817f3 status.go: use more clear status marks 2020-11-25 22:29:10 +02:00
Sergey Ponomarev 10c49018a6 status.go: make logic more explicit 2020-11-25 22:21:19 +02:00
Sergey Ponomarev 6c662d91fb docker.go shortName() use TrimPrefix() 2020-11-25 19:17:07 +02:00
Sergey Ponomarev b4a63f8c60 docker_logs.go: use time.RFC3339Nano constant 2020-11-24 22:19:29 +02:00
Sergey Ponomarev 4973bc83ff cpu color: make threshold upper: > 70% warn and > 90% is danger 2020-11-24 00:51:09 +02:00
Bradley Cicenas 87d135909f rename cpus column 2020-11-23 17:48:56 -05:00
Sergey Ponomarev 7632420ecc cpu color: check lower values first
this is simpler to understand and faster for usual containers
2020-11-24 00:22:25 +02:00
Sergey Ponomarev 4fbc998a41 status.go: simplify Buffer()
s.health and s.status are always have only one element with a single char length
2020-11-23 15:23:07 +02:00
bradley 117c3bc7b5
Merge pull request #234 from stokito/refresh
docker connector: refresh() delete container only if it not found but keep on failures
2020-11-22 19:00:31 -05:00
bradley b1171f6c3e
Merge pull request #235 from stokito/cpu_scale
#207 Replace scaleCpu option with dedicated column CPU Scaled
2020-11-21 12:19:43 -05:00
Sergey Ponomarev 9a41252764 #207 CPU unscaled column changes color according to system total usage
If container uses two cores then CPU column will be always red even if we have dozens of other free cores and CPUS is 1%
2020-11-20 23:24:13 +02:00
Sergey Ponomarev f377dcaee2 #207 Replace scaleCpu option with dedicated column CPU Scaled
The new column is disabled by default.
2020-11-20 23:08:19 +02:00
Sergey Ponomarev 65e9c6dff6 docker connector: refresh() delete container only if it not found but keep on failures
If inspect() call was failed due to connection problems then container will be removed anyway as like ot wasn't found.
This is probably almost never happens in real life but still some missed logic bug
2020-11-20 19:44:09 +02:00
Sergey Ponomarev df0d8b7892 #187 "created" action is handled separately in watchEvents() 2020-11-20 19:26:02 +02:00
bradley 2792e72d18
Merge pull request #233 from stokito/exec_shell
Exec shell config
2020-11-20 11:22:59 -05:00
bradley 68d6da5c61
Merge pull request #231 from stokito/log_file
Log to file
2020-11-20 08:30:13 -05:00
Sergey Ponomarev 53a6b36bf5 exec shell: detect default shell
Instead of using configured shell (e.g. bash) we can autodetect default container user's shell and execute it.
This is much safer because not all containers may have installed shell that is configured in ctop.
2020-11-20 10:42:52 +02:00
Sergey Ponomarev 5ec02f760e exec shell: remove shell config or option
The option is never worked and can't properly work because almost all containers anyway using Ash/Dash from /bin/sh
2020-11-20 10:39:28 +02:00
Sergey Ponomarev 83a422933a exec shell: on error show a status message instead of fatal exit 2020-11-20 10:33:44 +02:00
Sergey Ponomarev 7679d4a7fd exec shell: fix shell config
Currently each time when ctop started it overwrites "shell" config with default value of program argument.
This means that in fact default shell config is never worked at all.
2020-11-20 10:31:00 +02:00
Sergey Ponomarev e34afceb5f logging: log to file
New env var CTOP_DEBUG_FILE to specify a path to log file
2020-11-19 20:11:46 +02:00
bradley ddfff03c05
Merge pull request #229 from stokito/events
Improve docker events handling
2020-11-19 11:27:09 -05:00
Sergey Ponomarev 29d90cfdd9 logging: start server after log is configured
Without this "logging server started" is written to stderr
2020-11-19 11:21:27 +02:00
Sergey Ponomarev ba126e6e7c events handling: early skipping of extremely frequent exec_* events
The exec_create, exec_start, exec_die and other events are generated by health checks
2020-11-18 23:04:29 +02:00
Sergey Ponomarev 009201ed0c actionToStatus: catch more generic die instead of kill 2020-11-18 23:04:29 +02:00
Sergey Ponomarev 2c07cab59c logging: skip timer events e.g. /timer/1s
Each second we receive the timer event which makes little sense but log is bloated with the event.
To make logs more readable we can disable logging of this event
2020-11-18 23:04:29 +02:00
bradley fd06992236
Merge pull request #230 from stokito/skip_timer_logging
logging: skip timer events e.g. /timer/1s
2020-11-18 09:40:33 -05:00
Sergey Ponomarev e64edbdc36 logging: skip timer events e.g. /timer/1s
Each second we receive the timer event which makes little sense but log is bloated with the event.
To make logs more readable we can disable logging of this event
2020-11-18 11:25:20 +02:00
Sergey Ponomarev 4c280cee56 Improve docker events handling: separate channel for status updates
Instead of calling a heavy inspect api call we can easily changing status just by knowing an action.
Let's do this in a separate channel decouple UI update from basic event loop.
2020-11-17 22:00:03 +02:00
Sergey Ponomarev b65e970a83 Improve docker events handling
Firstly check health updates because it will be a lot of them especially when a container is unstable.
Clearly handle create event to create a container even if it wasn't started.
Instead of die event handle more precise events like oom, kill and only then trigger refresh.
Lookup the state from a map.
2020-11-17 21:50:25 +02:00
Sergey Ponomarev 957cabba2d docker.go: watchEvents() optimize actionName extraction
Split(e.Action, ":") creates and array but we can avoid this.
2020-11-17 12:06:34 +02:00
Sergey Ponomarev 5aacdc3772 docker.go: logging of events
Add log.IsEnabledFor(logging.DEBUG) guard to avoid unnecessary memory allocations. Debug level is usually disabled.
Inline "destroy"
2020-11-17 11:42:45 +02:00
Bradley Cicenas 99d9aeec98
set running = false when mock,runc collectors stopped 2020-11-13 21:43:11 +00:00
bradley 44600fca45
Merge pull request #201 from vcmkrtchyan/master
Fix freeze when container is started/stopped multiple times
2020-11-13 16:42:16 -05:00
bradley 9aaba5dfca
Merge pull request #223 from stokito/trim
file.go: remove duplicated trim
2020-11-13 15:40:01 -05:00
Bradley Cicenas 0bd8efe800
fix makefile release 2020-11-13 20:35:40 +00:00
Sergey Ponomarev 3a29c94833 Use percent() function to calc CPU usage 2020-11-13 11:02:14 +02:00
Sergey Ponomarev a22d99fefb file.go: remove duplicated trim
The s var was already trimmed on line 67
2020-11-12 21:23:18 +02:00
Bradley Cicenas c971d26d42
v0.7.5 2020-11-06 16:59:24 +00:00
Bradley Cicenas de380ff810
add arch section to readme 2020-11-06 16:56:17 +00:00
bradley e7e2478468
Merge pull request #222 from azlux/master
Readme : fix link
2020-11-05 13:44:35 -05:00
azlux 42c80c2395
fix link 2020-11-05 19:24:50 +01:00
bradley d22bbc3420
Merge pull request #221 from azlux/master
Add apt azlux's repository
2020-11-05 13:16:22 -05:00
azlux bdfb98265d
Add apt azlux's repository 2020-11-05 10:54:10 +01:00
Bradley Cicenas af1908fb27 update make release to use ghub cli 2020-11-03 07:55:39 -05:00
bradley 73a976c6fe
Merge pull request #220 from stokito/single_view_trunc_id
Single Container View: truncate ID
2020-11-03 07:55:00 -05:00
Sergey Ponomarev 2bcfc365f7 Single Container View: truncate ID
Truncation Id inside of NewSingle() doesn't work.
It even doesn't have any effect.
Instead truncate the ID inside of NewMeta() call
2020-11-03 14:11:58 +02:00
bradley ecc7bf4081
Merge pull request #219 from bcicen/text-col-setter
add textcol setter, static CID column width
2020-10-31 10:53:42 -04:00
Bradley Cicenas 68e4c32c1b
add textcol setter, static CID column width 2020-10-31 14:52:30 +00:00
bradley a63f05b430
Merge pull request #211 from stokito/truncate_column
text.go: to do not manually truncate id and name columns
2020-10-31 10:40:52 -04:00
Bradley Cicenas 426dd2c985
update dockerclient -> v1.6.6 2020-10-26 19:30:33 +00:00
bradley 0fb627a529
Merge pull request #214 from whalehub/static-binaries
Makefile: Add CGO_ENABLED=0 to generate statically linked binaries
2020-10-26 15:11:02 -04:00
Aaron c8f74a47a1
Makefile: Add CGO_ENABLED=0 to generate statically linked binaries
Signed-off-by: Aaron <admin@datahoarder.dev>
2020-10-26 16:14:57 +01:00
Sergey Ponomarev c984b270db #135 Add uptime column 2020-10-26 16:32:51 +02:00
Sergey Ponomarev 41c04fefa2 text.go: to do not manually truncate id and name columns
This truncation is already handled by termui
2020-10-26 15:43:55 +02:00
bradley 5b2d180f60
Merge pull request #210 from bcicen/fix-config-encoding
Fix config encoding
2020-10-26 09:04:07 -04:00
Bradley Cicenas 2fdbb91f87
ensure existing config file is removed prior to writing 2020-10-26 13:04:00 +00:00
Bradley Cicenas c0703db094
add health check to mock connector 2020-10-26 12:02:31 +00:00
Bradley Cicenas 53ec5c911a
return static error on unimplemented manager actions 2020-10-26 11:38:17 +00:00
Bradley Cicenas c5038e2edd
aggregate io r/w across all reported stats volumes 2020-10-25 17:42:20 +00:00
Bradley Cicenas e1a52a314d
v0.7.4, update docs 2020-10-25 16:55:44 +00:00
Bradley Cicenas bbecbc66b9
fix byte format for compact view (short) 2020-10-25 16:02:31 +00:00
Bradley Cicenas 192d3eaa7a Merge branch '0.7.4-dev' into master 2020-10-25 11:41:49 -04:00
Bradley Cicenas d34de844e0 add column config key to help menu 2020-10-25 10:31:51 -04:00
Bradley Cicenas a8e235beca commit missing compact column, row files 2020-10-25 10:31:51 -04:00
Bradley Cicenas ed194e8c04 update to go 1.13 2020-10-25 10:31:51 -04:00
Bradley Cicenas 09566a4043 add optional tooltip to menu widget 2020-10-25 10:31:51 -04:00
Bradley Cicenas f11a705b8b add padding to column menu 2020-10-25 10:31:51 -04:00
Bradley Cicenas 6fe6e7c316 truncate id in compact widget 2020-10-25 10:31:51 -04:00
Bradley Cicenas 9aa104fbc6 handle single kv pair given to NewMeta 2020-10-25 10:31:51 -04:00
Bradley Cicenas 7c6b5c54dc init column config menu 2020-10-25 10:31:51 -04:00
Bradley Cicenas ffb96f4e90 handle empty entries in column config 2020-10-25 10:31:51 -04:00
Bradley Cicenas fc9bd9e5ca refactor column config 2020-10-25 10:31:51 -04:00
Bradley Cicenas c7a8bfa26f integrate widget order, toggling into global config and compact grid 2020-10-25 10:31:51 -04:00
Bradley Cicenas 6b79e5a370 remove unused static col width 2020-10-25 10:31:51 -04:00
Bradley Cicenas 54fc5ac5c6 Revert "shows total memory usage"
This reverts commit 1271ce96e8.
2020-10-25 10:31:51 -04:00
Bradley Cicenas eb8237cbb1 continuing compact widget refactor 2020-10-25 10:31:51 -04:00
Bradley Cicenas 60875b179c initial refactor of all column widgets to standard interface 2020-10-25 10:31:19 -04:00
Marcos Diez 15c5c31726 shows total memory usage 2020-10-25 10:23:31 -04:00
Bradley Cicenas ea5968edce update sig 2020-10-25 10:23:30 -04:00
Bradley Cicenas c0db41ebcb Revert "shows total memory usage"
This reverts commit 1271ce96e8.
2020-10-25 10:23:30 -04:00
Bradley Cicenas dc14c79edf add run-dev to makefile 2020-10-25 10:23:30 -04:00
Bradley Cicenas 0ca5235ae5 continuing compact widget refactor 2020-10-25 10:23:30 -04:00
Bradley Cicenas 8427b0c81d initial refactor of all column widgets to standard interface 2020-10-25 10:23:30 -04:00
Marcos Diez 9bcf2c2c7a shows total memory usage 2020-10-25 10:23:30 -04:00
Bradley Cicenas 03a0da3230
update go version, deps for runc v1.0.0-rc92 2020-10-25 14:22:47 +00:00
Bradley Cicenas 4d7d69d4cf
refactor byte unit formatting, add unit-specific display precision 2020-10-25 14:08:06 +00:00
bradley fae9deb1d9
Merge pull request #203 from kerolloz/patch-1
enhance README.md
2020-08-28 07:29:46 -04:00
Kerollos Magdy 8027b990f8 enhance README.md 2020-07-30 16:18:24 +02:00
Vahe Mkrtchyan 4a0e80ffdf Fix freeze when container is started/stopped multiple times 2020-07-23 15:23:19 +04:00
Bradley Cicenas c446fb0e11 Merge branch 'master' of github.com:bcicen/ctop into 1.8-dev 2020-01-03 13:50:46 -05:00
Bradley Cicenas 4741b276e4
v0.7.3 2020-01-03 18:37:30 +00:00
Bradley Cicenas d60b16aad1
add column config key to help menu 2020-01-03 13:21:57 +00:00
Bradley Cicenas f704898212
commit missing compact column, row files 2020-01-03 13:20:31 +00:00
Bradley Cicenas 1523cc80ca
update to go 1.13 2020-01-03 13:18:01 +00:00
Bradley Cicenas b16561dccb Merge branch 'refactor-widgets' 2020-01-03 08:04:51 -05:00
Bradley Cicenas bf3b89a010
add optional tooltip to menu widget 2020-01-03 12:53:25 +00:00
Bradley Cicenas 5585a22962
add padding to column menu 2020-01-03 12:25:54 +00:00
Bradley Cicenas ca5d40b7cc
truncate id in compact widget 2020-01-03 12:07:54 +00:00
Bradley Cicenas 50d1c29d57
handle single kv pair given to NewMeta 2020-01-03 12:07:21 +00:00
Bradley Cicenas 22a5607012
init column config menu 2020-01-02 23:02:53 +00:00
Bradley Cicenas 6e60fc905e
handle empty entries in column config 2020-01-02 19:29:20 +00:00
Bradley Cicenas 118b89240d
refactor column config 2020-01-02 19:28:51 +00:00
Bradley Cicenas ee25f80a9c
integrate widget order, toggling into global config and compact grid 2020-01-02 14:00:55 +00:00
Bradley Cicenas 416eb5c363 update sig 2019-12-30 08:39:03 -05:00
Bradley Cicenas 746da760fb Revert "shows total memory usage"
This reverts commit 1271ce96e8.
2019-12-30 08:39:03 -05:00
Bradley Cicenas cc6f706c4b add run-dev to makefile 2019-12-30 08:39:03 -05:00
Bradley Cicenas 1ca40bb7e1 continuing compact widget refactor 2019-12-30 08:39:03 -05:00
Bradley Cicenas 918ccdbe39 initial refactor of all column widgets to standard interface 2019-12-30 08:39:03 -05:00
Marcos Diez 8fcd14e097 shows total memory usage 2019-12-30 08:39:03 -05:00
bradley 9dd12103fc
Merge pull request #186 from alexislefebvre/patch-1
Format options and keybindings as code
2019-12-30 08:31:49 -05:00
Alexis Lefebvre c38942c7ed
Format options and keybindings as code 2019-11-21 17:34:53 +01:00
Bradley Cicenas d34b9c2bf6 remove unused static col width 2019-11-11 22:04:25 +00:00
Bradley Cicenas a60861437f Merge branch 'refactor-widgets' 2019-11-06 07:33:42 -05:00
Bradley Cicenas 4b391e900c use raw log stream in docker log collector 2019-11-06 07:32:29 -05:00
Bradley Cicenas 4460162380
go 1.13 2019-11-06 12:32:03 +00:00
Bradley Cicenas d56cc9475a
update sig 2019-11-06 12:31:57 +00:00
bradley 4584cf34f5
Merge pull request #178 from rvolosatovs/feature/go-sum
Add go.sum
2019-10-03 07:35:26 -04:00
Roman Volosatovs 1ce07448ce
go.sum: Add 2019-09-10 20:22:25 +02:00
Bradley Cicenas c8e896e371 Revert "shows total memory usage"
This reverts commit 1271ce96e8.
2019-07-03 11:27:17 +00:00
Bradley Cicenas db2c832bd7 add run-dev to makefile 2019-07-05 19:09:30 -04:00
Bradley Cicenas 7fdcd7bbf1 continuing compact widget refactor 2019-07-05 19:09:30 -04:00
Bradley Cicenas 923edb967e initial refactor of all column widgets to standard interface 2019-07-05 19:08:16 -04:00
Marcos Diez 1271ce96e8 shows total memory usage 2019-07-05 19:07:13 -04:00
Bradley Cicenas d8c7dd4c5c move image to go 1.12 2019-06-29 15:15:13 -04:00
Bradley Cicenas b7d81485f9 update dockerclient, runc deps 2019-06-29 15:15:13 -04:00
bradley 8946c4b03b
Merge pull request #169 from captn3m0/patch-1
Switches to a read-only socket mount
2019-06-29 14:32:08 -04:00
Bradley Cicenas 331f50f03e update status doc image 2019-06-22 18:44:07 +00:00
Bradley Cicenas 4c4f041b40 improve health check visibility 2019-06-22 18:42:48 +00:00
Bradley Cicenas c8ac331652 fix timer 2019-05-22 17:39:37 +00:00
Bradley Cicenas 0a5a4c9062 add multi-line scrolling support, timestamps to error view 2019-05-22 17:38:01 +00:00
Bradley Cicenas 98fcfe8b6f refactor connectors for retry logic, add error view 2019-05-22 16:58:55 +00:00
bradley 42f095cd85
Merge pull request #170 from fr05t1k/exec
Enable cursor
2019-05-13 12:24:41 -04:00
Stanislav Pavlovichev 73986d2732 Enable cursor 2019-05-13 15:47:22 +03:00
Bradley Cicenas c1d4615cc0 Merge branch 'fr05t1k-exec' 2019-05-12 16:26:51 -04:00
Bradley Cicenas d187e8c623 drop potentially empty initial frames during exec attach 2019-05-12 20:23:54 +00:00
Bradley Cicenas b8c38d09ef add exec shortcut key to container menu 2019-05-12 20:23:29 +00:00
Bradley Cicenas d7384db373 Merge branch 'exec' of https://github.com/fr05t1k/ctop into fr05t1k-exec 2019-05-12 15:31:33 -04:00
Nemo 1b441db189
Switches to a read-only socket mount 2019-04-17 00:43:15 +05:30
bradley 0479d42e31
Merge pull request #168 from CodeLingoBot/rewrite
Fix function comments based on best practices from Effective Go
2019-03-07 09:41:02 +05:30
CodeLingo Bot b401e7b17e Fix function comments based on best practices from Effective Go
Signed-off-by: CodeLingo Bot <bot@codelingo.io>
2019-03-07 02:33:29 +00:00
Bradley Cicenas 9592de82a0 add keyboard shortcuts to container menu 2019-01-24 14:06:40 +00:00
bradley 29fa8cf3e7
Update status.md 2019-01-24 08:02:52 -05:00
bradley c49939f965
Update status.md 2019-01-24 08:02:13 -05:00
bradley 2f7bc2a172
Update status.md 2019-01-24 08:00:51 -05:00
Bradley Cicenas 7b4d4db049 add status indicator doc 2019-01-24 12:50:59 +00:00
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
Stanislav Pavlovichev 101ddad692 Fixed a problem with rendering 2018-10-28 13:43:24 +02:00
Stanislav Pavlovichev ca35ef2aab Unnecessary loop stopping 2018-10-28 12:07:43 +02:00
Stanislav Pavlovichev d59c91a461 Do not allow to close /dev/stdin 2018-10-26 17:08:33 +03: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
Stanislav Pavlovichev a26fc9169c Ability to change Shell 2018-10-25 21:58:33 +03:00
Stanislav Pavlovichev 967a87a65f Exec using API 2018-10-13 08:33:53 +03:00
Stanislav Pavlovichev e68f7ba96a fix: handlers used to work after "exec sh" command
feature: hot key for "exec sh"
2018-10-12 10:03:27 +03: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
Stanislav Pavlovichev f27de1c29e Exec Sh Feature 2018-10-07 16:46:32 +03: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
Bradley Cicenas 5261444265 v0.7.1 2018-03-09 05:19:34 +00:00
Bradley Cicenas b3aa291182 update termbox-go dependency 2018-03-09 05:15:55 +00:00
Bradley Cicenas 051b474bf0 dep updates 2018-02-23 13:57:59 +09:30
Bradley Cicenas fac6632459 build image from go 1.10 2018-02-22 14:58:21 +09:30
Bradley Cicenas 1c7cf98e58 handle window resize in help dialog 2018-02-02 15:21:33 +00:00
Bradley Cicenas 44a54e070d combine conditionals 2018-02-01 16:55:23 +00:00
Bradley Cicenas 10b9a6c013 include windows build 2018-01-31 17:05:54 +00:00
Bradley Cicenas a3b67e4607 add available connectors to help dialog 2018-01-30 07:54:13 -03:00
Bradley Cicenas ac1ce18143 refactor enabled connectors 2018-01-29 12:47:10 +00:00
bradley 01a305d326
Update README.md
escape brackets
2018-01-11 15:58:37 -03:00
Bradley Cicenas 233259be40 v0.7 2018-01-11 15:32:34 -03:00
Bradley Cicenas 107def9ccc add status err messages to start/stop/remove 2018-01-11 15:27:30 -03:00
Bradley Cicenas d46ce783c2 add statusline widget, status messages to logging 2018-01-11 15:19:01 -03:00
Bradley Cicenas d743472b16 add support for config file, keybinding for exporting active config 2018-01-11 13:15:18 -03:00
Bradley Cicenas d785b263f4 add scale-cpu switch 2018-01-11 12:19:00 -03:00
Bradley Cicenas 6d37a4e333 enable remove action for "created" state containers 2018-01-11 11:40:21 -03:00
Bradley Cicenas eb49e51ffb prevent recursive/nested running menus, handle all within main Display() loop 2018-01-11 11:23:28 -03:00
Bradley Cicenas 734d4bfc0c add optional subtext to menu widget 2018-01-11 10:56:00 -03:00
Bradley Cicenas 0e75bbda58 add confirmation dialog for container management actions 2018-01-11 10:26:58 -03:00
Bradley Cicenas 8b5eb21ac3 add logs to container menu 2018-01-10 18:10:11 -03:00
Bradley Cicenas c958e4c34e move keybinding for single view, add single view to container menu 2018-01-10 15:45:14 -03:00
Bradley Cicenas ab48d830d1 import formatting 2017-12-13 09:20:14 +08:00
bradley 915579c0a4
Merge pull request #110 from HotelsDotCom/master
added option to toggle log timestamp in the log view, closes #107
2017-12-13 09:16:33 +08:00
Peter Reisinger 0a6e6f02a4 added option to toggle log timestamp in the log view, closes #107 2017-12-08 11:35:04 +00:00
Bradley Cicenas a135f45844 add simple output fn to installer script 2017-12-08 09:37:54 +08:00
Bradley Cicenas b39b91774d add checksum validation to installer script 2017-12-05 17:50:00 +08:00
Bradley Cicenas 2275248813 init simple installer script 2017-12-02 20:49:37 +00:00
bradley 75f4a91f11
Merge pull request #108 from HotelsDotCom/master
line wrapping in log view, closes #106
2017-12-01 21:47:05 -05:00
Peter Reisinger d0b5c6c854 added test for text view split line 2017-12-01 15:51:55 +00:00
Peter Reisinger bd8940ae0a line wrapping in log view, closes #106 2017-12-01 15:29:11 +00:00
Bradley Cicenas 1be64f0d11 define flag vars in block 2017-11-29 03:03:46 +00:00
Bradley Cicenas 1c8f4b3a35 add logging for log reader start/stop 2017-11-28 09:38:32 -05:00
Bradley Cicenas 3e5176a79c add NewDockerLogs constructor method 2017-11-28 09:36:28 -05:00
Bradley Cicenas 53c0f2a9df add resize handling to log view 2017-11-28 08:55:29 -05:00
Bradley Cicenas 28389aa38c gofmt 2017-11-28 08:40:43 -05:00
bradley fb5c825cf6
Merge pull request #105 from HotelsDotCom/master
Added 'view logs binding'
2017-11-26 12:41:57 -05:00
Peter Reisinger a0e0da1da9 Added 'view logs binding' 2017-11-25 18:30:50 +00:00
Bradley Cicenas a826859202 gofmt 2017-11-22 09:27:38 -05:00
Bradley Cicenas 71b4a1de94 add runc manager placeholder 2017-11-22 09:26:01 -05:00
bradley 93a2e4b1ca
Merge pull request #104 from HotelsDotCom/master
added container menu - closes #28
2017-11-22 08:22:37 -06:00
Peter Reisinger 436266b1a4 added container menu closes #28 2017-11-20 11:09:36 +00:00
Bradley Cicenas 19427e33a0 add checksum verify to make release 2017-11-19 15:06:29 +00:00
Bradley Cicenas 48d683be77 add checksum generation to makefile 2017-11-18 07:51:15 +00:00
bradley e1ec264345 Merge pull request #90 from bcicen/godep
Move from Glide -> Dep
2017-09-03 11:10:59 +09:00
Bradley Cicenas 9aad2efdb0 update build docs with dep link 2017-09-03 10:53:01 +09:00
Bradley Cicenas f6595a02c4 replace glide with godep 2017-09-03 10:33:14 +09:00
Bradley Cicenas 92ca9bf7eb remove textcol coloring 2017-08-28 10:48:13 +09:00
Bradley Cicenas 05242a83f0 refactor status widget, include health indicator 2017-08-28 10:45:14 +09:00
Bradley Cicenas add44c0f18 add common status colors to global theme 2017-08-28 08:46:01 +09:00
Bradley Cicenas a1ebf3f90e remove duplicate inspect, trigger refresh on "health_status" events 2017-08-28 08:29:59 +09:00
Alexandr Kozlenkov 626d50d3e9 Added health row to Info Single mode.
Change color status logic.

Highlight health status for Name column:
- starting - yellow
- healthy - green
- unhealthy - magenta

reformat

Fixed misprint

Removed unused colors of state widget.

Moved changes to another branch

Removed unused colors of state widget.

Remove swarm changes from master

Remove swarm changes from master

Remove swarm changes from master
2017-08-28 07:55:43 +09:00
bradley eaa7ad85f8 Merge pull request #87 from mavimo/patch-1
Update version in readme
2017-08-25 14:22:04 +09:00
Marco Vito Moscaritolo be9be0b2d1 Update version in readme
SSIA
2017-08-24 12:27:15 +02:00
bradley f196999c67 Merge pull request #86 from kentaost/runc-root-description
update RUNC_ROOT description to adjust to runC man
2017-08-22 15:22:19 +09:00
Kenta Tada e674ec4f33 update RUNC_ROOT description to adjust to runC man 2017-08-21 21:36:45 +09:00
Bradley Cicenas f23805550f remove deprecated -e option 2017-08-19 14:33:56 +09:00
Bradley Cicenas 55a356bbec omit cache from memory usage stat 2017-08-11 16:44:52 +02:00
Bradley Cicenas 954aaeb06b rename Memory widget 2017-08-09 14:05:45 +02:00
Bradley Cicenas 27e272c58f rename expanded -> single view 2017-08-05 13:28:20 +02:00
Bradley Cicenas 3ed9912bcb update circleci 2017-06-29 14:02:52 +00:00
Bradley Cicenas e0f6563a39 move circleci config to 2.0 2017-06-29 14:02:52 +00:00
Bradley Cicenas caa64724d0 fix release dirname 2017-06-29 14:02:52 +00:00
82 changed files with 3532 additions and 888 deletions

19
.circleci/config.yml Normal file
View File

@ -0,0 +1,19 @@
version: 2
jobs:
build:
working_directory: ~/build
docker:
- image: cimg/go:1.18
steps:
- checkout
- setup_remote_docker:
version: 20.10.11
- run: make image
- deploy:
command: |
if [[ "$CIRCLE_BRANCH" == "master" ]]; then
docker tag ctop quay.io/vektorlab/ctop:latest
docker tag ctop quay.io/vektorlab/ctop:$(cat VERSION)
docker login -u $DOCKER_USER -p $DOCKER_PASS quay.io
docker push quay.io/vektorlab/ctop
fi

4
.gitignore vendored
View File

@ -1,2 +1,4 @@
ctop
.idea
.idea
/vendor/
*.log

View File

@ -1,16 +1,17 @@
FROM quay.io/vektorcloud/go:1.8
FROM quay.io/vektorcloud/go:1.18
RUN apk add --no-cache make
COPY glide.* /go/src/github.com/bcicen/ctop/
WORKDIR /go/src/github.com/bcicen/ctop/
RUN glide install
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"]

View File

@ -1,34 +1,37 @@
NAME=ctop
VERSION=$(shell cat VERSION)
BUILD=$(shell git rev-parse --short HEAD)
EXT_LD_FLAGS="-Wl,--allow-multiple-definition"
LD_FLAGS="-w -X main.version=$(VERSION) -X main.build=$(BUILD) -extldflags=$(EXT_LD_FLAGS)"
LD_FLAGS="-w -X main.version=$(VERSION) -X main.build=$(BUILD)"
clean:
rm -rf _build/ _release/
rm -rf _build/ release/
build:
glide install
go mod download
CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o ctop
build-dev:
go build -ldflags "-w -X main.version=$(VERSION)-dev -X main.build=$(BUILD) -extldflags=$(EXT_LD_FLAGS)"
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
mkdir -p _build
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-darwin-amd64
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-amd64
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm64
GOOS=linux GOARCH=ppc64le CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-ppc64le
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-windows-amd64
cd _build; sha256sum * > sha256sums.txt
run-dev:
rm -f ctop.sock ctop
go build -ldflags $(LD_FLAGS) -o ctop
CTOP_DEBUG=1 ./ctop
image:
docker build -t ctop -f Dockerfile .
release:
mkdir _release
go get github.com/progrium/gh-release/...
cp _build/* _release
gh-release create bcicen/$(NAME) $(VERSION) \
$(shell git rev-parse --abbrev-ref HEAD) $(VERSION)
mkdir release
cp _build/* release
cd release; sha256sum --quiet --check sha256sums.txt && \
gh release create v$(VERSION) -d -t v$(VERSION) *
.PHONY: build

100
README.md
View File

@ -2,14 +2,14 @@
#
![release][release] ![homebrew][homebrew]
![release][release] ![homebrew][homebrew] ![macports][macports] ![scoop][scoop]
Top-like interface for container metrics
`ctop` provides a concise and condensed overview of real-time metrics for multiple containers:
<p align="center"><img src="_docs/img/grid.gif" alt="ctop"/></p>
as well as an [expanded view][expanded_view] for inspecting a specific container.
as well as a [single container view][single_view] for inspecting a specific container.
`ctop` comes with built-in support for Docker and runC; connectors for other container and cluster systems are planned for future releases.
@ -17,10 +17,32 @@ as well as an [expanded view][expanded_view] for inspecting a specific container
Fetch the [latest release](https://github.com/bcicen/ctop/releases) for your platform:
#### Linux
#### Debian/Ubuntu
Maintained by a [third party](https://packages.azlux.fr/)
```bash
sudo apt-get install ca-certificates curl gnupg lsb-release
curl -fsSL https://azlux.fr/repo.gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/azlux-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian \
$(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/azlux.list >/dev/null
sudo apt-get update
sudo apt-get install docker-ctop
```
#### Arch
```bash
sudo wget https://github.com/bcicen/ctop/releases/download/v0.6.0/ctop-0.6.0-linux-amd64 -O /usr/local/bin/ctop
sudo pacman -S ctop
```
_`ctop` is also available for Arch in the [AUR](https://aur.archlinux.org/packages/ctop-bin/)_
#### Linux (Generic)
```bash
sudo wget https://github.com/bcicen/ctop/releases/download/v0.7.7/ctop-0.7.7-linux-amd64 -O /usr/local/bin/ctop
sudo chmod +x /usr/local/bin/ctop
```
@ -31,21 +53,31 @@ brew install ctop
```
or
```bash
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.6.0/ctop-0.6.0-darwin-amd64
sudo port install ctop
```
or
```bash
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.7.7/ctop-0.7.7-darwin-amd64
sudo chmod +x /usr/local/bin/ctop
```
#### Windows
`ctop` is available in [scoop](https://scoop.sh/):
```powershell
scoop install ctop
```
#### Docker
```bash
docker run --rm -ti \
--name=ctop \
-v /var/run/docker.sock:/var/run/docker.sock \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
quay.io/vektorlab/ctop:latest
```
`ctop` is also available for Arch in the [AUR](https://aur.archlinux.org/packages/ctop-bin/)
## Building
Build steps can be found [here][build].
@ -54,32 +86,50 @@ Build steps can be found [here][build].
`ctop` requires no arguments and uses Docker host variables by default. See [connectors][connectors] for further configuration options.
### Config file
While running, use `S` to save the current filters, sort field, and other options to a default config path (`~/.config/ctop/config` on XDG systems, else `~/.ctop`).
Config file values will be loaded and applied the next time `ctop` is started.
### Options
Option | Description
--- | ---
-a | show active containers only
-f <string> | set an initial filter string
-h | display help dialog
-i | invert default colors
-r | reverse container sort order
-s | select initial container sort field
-v | output version information and exit
`-a` | show active containers only
`-f <string>` | set an initial filter string
`-h` | display help dialog
`-i` | invert default colors
`-r` | reverse container sort order
`-s` | select initial container sort field
`-v` | output version information and exit
### Keybindings
Key | Action
--- | ---
a | Toggle display of all (running and non-running) containers
f | Filter displayed containers (`esc` to clear when open)
H | Toggle ctop header
h | Open help dialog
s | Select container sort field
r | Reverse container sort order
q | Quit ctop
| Key | Action |
| :----------------------: | ---------------------------------------------------------- |
| <kbd>&lt;ENTER&gt;</kbd> | Open container menu |
| <kbd>a</kbd> | Toggle display of all (running and non-running) containers |
| <kbd>f</kbd> | Filter displayed containers (`esc` to clear when open) |
| <kbd>H</kbd> | Toggle ctop header |
| <kbd>h</kbd> | Open help dialog |
| <kbd>s</kbd> | Select container sort field |
| <kbd>r</kbd> | Reverse container sort order |
| <kbd>o</kbd> | Open single view |
| <kbd>l</kbd> | View container logs (`t` to toggle timestamp when open) |
| <kbd>e</kbd> | Exec Shell |
| <kbd>c</kbd> | Configure columns |
| <kbd>S</kbd> | Save current configuration to file |
| <kbd>q</kbd> | Quit ctop |
[build]: _docs/build.md
[connectors]: _docs/connectors.md
[expanded_view]: _docs/expanded.md
[single_view]: _docs/single.md
[release]: https://img.shields.io/github/release/bcicen/ctop.svg "ctop"
[homebrew]: https://img.shields.io/homebrew/v/ctop.svg "ctop"
[macports]: https://repology.org/badge/version-for-repo/macports/ctop.svg?header=macports "ctop"
[scoop]: https://img.shields.io/scoop/v/ctop?bucket=main "ctop"
## Alternatives
See [Awesome Docker list](https://github.com/veggiemonk/awesome-docker/blob/master/README.md#terminal) for similar tools to work with Docker.

View File

@ -1 +1 @@
0.6.1
0.7.7

View File

@ -1,10 +1,8 @@
# Build
To build `ctop` from source, ensure you have a recent version of [glide](https://github.com/Masterminds/glide) installed and run:
To build `ctop` from source, simply clone the repo and run:
```bash
go get github.com/bcicen/ctop && \
cd $GOPATH/src/github.com/bcicen/ctop && \
make build
```
@ -16,5 +14,8 @@ make image
Now you can run your local image:
```bash
docker run -ti --name ctop --rm -v /var/run/docker.sock:/var/run/docker.sock ctop
docker run --rm -ti \
--name ctop \
-v /var/run/docker.sock:/var/run/docker.sock \
ctop:latest
```

View File

@ -1,4 +1,4 @@
# connectors
# Connectors
`ctop` comes with the below native connectors, enabled via the `--connector` option.
@ -16,11 +16,11 @@ DOCKER_HOST | Daemon socket to connect to (default: `unix://var/run/docker.sock`
## RunC
Using this connector requires full privileges to the local runC root dir (default: `/run/runc`)
Using this connector requires full privileges to the local runC root dir of container state (default: `/run/runc`)
#### Options
Var | Description
--- | ---
RUNC_ROOT | path to runc root (default: `/run/runc`)
RUNC_ROOT | path to runc root for container state (default: `/run/runc`)
RUNC_SYSTEMD_CGROUP | if set, enable systemd cgroups

View File

@ -54,3 +54,18 @@ CTOP_DEBUG=1 CTOP_DEBUG_TCP=1 ./ctop
```
A TCP listener for streaming log messages will be started on the default listen address(`0.0.0.0:9000`)
## Log to file
You can also log to a file by specifying `CTOP_DEBUG_FILE=/path/to/ctop.log` environment variable:
```sh
CTOP_DEBUG=1 CTOP_DEBUG_FILE=ctop.log ./ctop
```
This is useful for GoLand to see logs right in debug panel:
* Edit Run configuration
* Go to Logs tab
* Specify this log file in "Log file to be shown in console".
Then during debugging you'll see the log tab in debug panel:
![Debug in GoLand](img/goland_debug.png)

View File

@ -1,4 +0,0 @@
# Expanded View
ctop provides an expanded, rolling view for following container metrics
<p align="center"><img width="80%" src="img/expanded.gif" alt="ctop"/></p>

BIN
_docs/img/goland_debug.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

View File

Before

Width:  |  Height:  |  Size: 549 KiB

After

Width:  |  Height:  |  Size: 549 KiB

BIN
_docs/img/status.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

4
_docs/single.md Normal file
View File

@ -0,0 +1,4 @@
# Single Container View
ctop provides a rolling, single container view for following metrics
<p align="center"><img width="80%" src="img/single.gif" alt="ctop"/></p>

30
_docs/status.md Normal file
View File

@ -0,0 +1,30 @@
# Status Indicator
The `ctop` grid view provides a compact status indicator to convey container state
<img width="200px" src="img/status.png" alt="ctop"/>
### Status
<span align="center">
Appearance | Description
--- | ---
red | container is stopped
green | container is running
▮▮ | container is paused
</span>
### Health
If the container is configured with a health check, a `+` will appear next to the indicator
<span align="center">
Appearance | Description
--- | ---
red | health check in failed state
yellow | health check in starting state
green | health check in OK state
</span>

View File

@ -1,23 +0,0 @@
machine:
services:
- docker
environment:
IMAGE_NAME: quay.io/vektorlab/ctop
dependencies:
override:
- docker info
- make image
test:
override:
- docker run -ti ctop -v
deployment:
hub:
branch: master
commands:
- docker tag ctop ${IMAGE_NAME}:latest
- docker tag ctop ${IMAGE_NAME}:$(cat VERSION)
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
- docker push ${IMAGE_NAME}

View File

@ -45,11 +45,14 @@ var ColorMap = map[string]ui.Attribute{
"par.text.hi": ui.ColorBlack,
"sparkline.line.fg": ui.ColorGreen,
"sparkline.title.fg": ui.ColorWhite,
"status.ok": ui.ColorGreen,
"status.warn": ui.ColorYellow,
"status.danger": ui.ColorRed,
}
func InvertColorMap() {
re := regexp.MustCompile(".*.fg")
for k, _ := range ColorMap {
for k := range ColorMap {
if re.FindAllString(k, 1) != nil {
ColorMap[k] = ui.ColorBlack
}

175
config/columns.go Normal file
View File

@ -0,0 +1,175 @@
package config
import (
"strings"
)
// defaults
var defaultColumns = []Column{
{
Name: "status",
Label: "Status Indicator",
Enabled: true,
},
{
Name: "name",
Label: "Container Name",
Enabled: true,
},
{
Name: "id",
Label: "Container ID",
Enabled: true,
},
{
Name: "image",
Label: "Image name",
Enabled: false,
},
{
Name: "ports",
Label: "Exposed ports",
Enabled: false,
},
{
Name: "IPs",
Label: "Exposed IPs",
Enabled: false,
},
{
Name: "created",
Label: "Date created",
Enabled: false,
},
{
Name: "cpu",
Label: "CPU Usage",
Enabled: true,
},
{
Name: "cpus",
Label: "CPU Usage (% of system total)",
Enabled: false,
},
{
Name: "mem",
Label: "Memory Usage",
Enabled: true,
},
{
Name: "net",
Label: "Network RX/TX",
Enabled: true,
},
{
Name: "io",
Label: "Disk IO Read/Write",
Enabled: true,
},
{
Name: "pids",
Label: "Container PID Count",
Enabled: true,
},
Column{
Name: "uptime",
Label: "Running uptime duration",
Enabled: true,
},
}
type Column struct {
Name string
Label string
Enabled bool
}
// ColumnsString returns an ordered and comma-delimited string of currently enabled Columns
func ColumnsString() string { return strings.Join(EnabledColumns(), ",") }
// EnabledColumns returns an ordered array of enabled column names
func EnabledColumns() (a []string) {
lock.RLock()
defer lock.RUnlock()
for _, col := range GlobalColumns {
if col.Enabled {
a = append(a, col.Name)
}
}
return a
}
// ColumnToggle toggles the enabled status of a given column name
func ColumnToggle(name string) {
col := GlobalColumns[colIndex(name)]
col.Enabled = !col.Enabled
log.Noticef("config change [column-%s]: %t -> %t", col.Name, !col.Enabled, col.Enabled)
}
// ColumnLeft moves the column with given name up one position, if possible
func ColumnLeft(name string) {
idx := colIndex(name)
if idx > 0 {
swapCols(idx, idx-1)
}
}
// ColumnRight moves the column with given name up one position, if possible
func ColumnRight(name string) {
idx := colIndex(name)
if idx < len(GlobalColumns)-1 {
swapCols(idx, idx+1)
}
}
// Set Column order and enabled status from one or more provided Column names
func SetColumns(names []string) {
var (
n int
curColStr = ColumnsString()
newColumns = make([]*Column, len(GlobalColumns))
)
lock.Lock()
// add enabled columns by name
for _, name := range names {
newColumns[n] = popColumn(name)
newColumns[n].Enabled = true
n++
}
// extend with omitted columns as disabled
for _, col := range GlobalColumns {
newColumns[n] = col
newColumns[n].Enabled = false
n++
}
GlobalColumns = newColumns
lock.Unlock()
log.Noticef("config change [columns]: %s -> %s", curColStr, ColumnsString())
}
func swapCols(i, j int) { GlobalColumns[i], GlobalColumns[j] = GlobalColumns[j], GlobalColumns[i] }
func popColumn(name string) *Column {
idx := colIndex(name)
if idx < 0 {
panic("no such column name: " + name)
}
col := GlobalColumns[idx]
GlobalColumns = append(GlobalColumns[:idx], GlobalColumns[idx+1:]...)
return col
}
// return index of column with given name, if any
func colIndex(name string) int {
for n, c := range GlobalColumns {
if c.Name == name {
return n
}
}
return -1
}

144
config/file.go Normal file
View File

@ -0,0 +1,144 @@
package config
import (
"fmt"
"os"
"path/filepath"
"regexp"
"strings"
"github.com/BurntSushi/toml"
)
var (
xdgRe = regexp.MustCompile("^XDG_*")
)
type File struct {
Options map[string]string `toml:"options"`
Toggles map[string]bool `toml:"toggles"`
}
func exportConfig() File {
// update columns param from working config
Update("columns", ColumnsString())
lock.RLock()
defer lock.RUnlock()
c := File{
Options: make(map[string]string),
Toggles: make(map[string]bool),
}
for _, p := range GlobalParams {
c.Options[p.Key] = p.Val
}
for _, sw := range GlobalSwitches {
c.Toggles[sw.Key] = sw.Val
}
return c
}
//
func Read() error {
var config File
path, err := getConfigPath()
if err != nil {
return err
}
if _, err := toml.DecodeFile(path, &config); err != nil {
return err
}
for k, v := range config.Options {
Update(k, v)
}
for k, v := range config.Toggles {
UpdateSwitch(k, v)
}
// set working column config, if provided
colStr := GetVal("columns")
if len(colStr) > 0 {
var colNames []string
for _, s := range strings.Split(colStr, ",") {
s = strings.TrimSpace(s)
if s != "" {
colNames = append(colNames, s)
}
}
SetColumns(colNames)
}
return nil
}
func Write() (path string, err error) {
path, err = getConfigPath()
if err != nil {
return path, err
}
cfgdir := filepath.Dir(path)
// create config dir if not exist
if _, err := os.Stat(cfgdir); err != nil {
err = os.MkdirAll(cfgdir, 0755)
if err != nil {
return path, fmt.Errorf("failed to create config dir [%s]: %s", cfgdir, err)
}
}
// remove prior to writing new file
if err := os.Remove(path); err != nil {
if !os.IsNotExist(err) {
return path, err
}
}
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
return path, fmt.Errorf("failed to open config for writing: %s", err)
}
writer := toml.NewEncoder(file)
err = writer.Encode(exportConfig())
if err != nil {
return path, fmt.Errorf("failed to write config: %s", err)
}
return path, nil
}
// determine config path from environment
func getConfigPath() (path string, err error) {
homeDir, ok := os.LookupEnv("HOME")
if !ok {
return path, fmt.Errorf("$HOME not set")
}
// use xdg config home if possible
if xdgSupport() {
xdgHome, ok := os.LookupEnv("XDG_CONFIG_HOME")
if !ok {
xdgHome = fmt.Sprintf("%s/.config", homeDir)
}
path = fmt.Sprintf("%s/ctop/config", xdgHome)
} else {
path = fmt.Sprintf("%s/.ctop", homeDir)
}
return path, nil
}
// test for environemnt supporting XDG spec
func xdgSupport() bool {
for _, e := range os.Environ() {
if xdgRe.FindAllString(e, 1) != nil {
return true
}
}
return false
}

View File

@ -3,6 +3,7 @@ package config
import (
"fmt"
"os"
"sync"
"github.com/bcicen/ctop/logging"
)
@ -10,17 +11,24 @@ import (
var (
GlobalParams []*Param
GlobalSwitches []*Switch
GlobalColumns []*Column
lock sync.RWMutex
log = logging.Init()
)
func Init() {
for _, p := range params {
for _, p := range defaultParams {
GlobalParams = append(GlobalParams, p)
log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
log.Infof("loaded default config param [%s]: %s", quote(p.Key), quote(p.Val))
}
for _, s := range switches {
for _, s := range defaultSwitches {
GlobalSwitches = append(GlobalSwitches, s)
log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)
log.Infof("loaded default config switch [%s]: %t", quote(s.Key), s.Val)
}
for _, c := range defaultColumns {
x := c
GlobalColumns = append(GlobalColumns, &x)
log.Infof("loaded default widget config [%s]: %t", quote(x.Name), x.Enabled)
}
}

View File

@ -1,7 +1,7 @@
package config
// defaults
var params = []*Param{
var defaultParams = []*Param{
&Param{
Key: "filterStr",
Val: "",
@ -12,6 +12,11 @@ var params = []*Param{
Val: "state",
Label: "Container Sort Field",
},
&Param{
Key: "columns",
Val: "status,name,id,cpu,mem,net,io,pids,uptime",
Label: "Enabled Columns",
},
}
type Param struct {
@ -22,6 +27,9 @@ type Param struct {
// Get Param by key
func Get(k string) *Param {
lock.RLock()
defer lock.RUnlock()
for _, p := range GlobalParams {
if p.Key == k {
return p
@ -30,7 +38,7 @@ func Get(k string) *Param {
return &Param{} // default
}
// Get Param value by key
// GetVal gets Param value by key
func GetVal(k string) string {
return Get(k).Val
}
@ -38,7 +46,10 @@ func GetVal(k string) string {
// Set param value
func Update(k, v string) {
p := Get(k)
log.Noticef("config change: %s: %s -> %s", k, quote(p.Val), quote(v))
log.Noticef("config change [%s]: %s -> %s", k, quote(p.Val), quote(v))
lock.Lock()
defer lock.Unlock()
p.Val = v
// log.Errorf("ignoring update for non-existant parameter: %s", k)
}

View File

@ -1,21 +1,26 @@
package config
// defaults
var switches = []*Switch{
var defaultSwitches = []*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",
},
}
@ -25,8 +30,11 @@ type Switch struct {
Label string
}
// Return Switch by key
// GetSwitch returns Switch by key
func GetSwitch(k string) *Switch {
lock.RLock()
defer lock.RUnlock()
for _, sw := range GlobalSwitches {
if sw.Key == k {
return sw
@ -35,16 +43,31 @@ func GetSwitch(k string) *Switch {
return &Switch{} // default
}
// Return Switch value by key
// GetSwitchVal returns Switch value by key
func GetSwitchVal(k string) bool {
return GetSwitch(k).Val
}
func UpdateSwitch(k string, val bool) {
sw := GetSwitch(k)
lock.Lock()
defer lock.Unlock()
if sw.Val != val {
log.Noticef("config change [%s]: %t -> %t", k, sw.Val, val)
sw.Val = val
}
}
// Toggle a boolean switch
func Toggle(k string) {
sw := GetSwitch(k)
newVal := sw.Val != true
log.Noticef("config change: %s: %t -> %t", k, sw.Val, newVal)
sw.Val = newVal
lock.Lock()
defer lock.Unlock()
sw.Val = !sw.Val
log.Noticef("config change [%s]: %t -> %t", k, !sw.Val, sw.Val)
//log.Errorf("ignoring toggle for non-existant switch: %s", k)
}

View File

@ -66,30 +66,35 @@ func (c *Docker) Stream() chan models.Metrics {
}
func (c *Docker) Logs() LogCollector {
return &DockerLogs{c.id, c.client, make(chan bool)}
return NewDockerLogs(c.id, c.client)
}
// Stop collector
func (c *Docker) Stop() {
c.running = false
c.done <- true
}
func (c *Docker) ReadCPU(stats *api.Stats) {
ncpus := float64(len(stats.CPUStats.CPUUsage.PercpuUsage))
ncpus := uint8(stats.CPUStats.OnlineCPUs)
if ncpus == 0 {
ncpus = uint8(len(stats.CPUStats.CPUUsage.PercpuUsage))
}
total := float64(stats.CPUStats.CPUUsage.TotalUsage)
system := float64(stats.CPUStats.SystemCPUUsage)
cpudiff := total - c.lastCpu
syscpudiff := system - c.lastSysCpu
c.CPUUtil = round((cpudiff / syscpudiff * 100) * ncpus)
c.NCpus = ncpus
c.CPUUtil = percent(cpudiff, syscpudiff)
c.lastCpu = total
c.lastSysCpu = system
c.Pids = int(stats.PidsStats.Current)
}
func (c *Docker) ReadMem(stats *api.Stats) {
c.MemUsage = int64(stats.MemoryStats.Usage)
c.MemUsage = int64(stats.MemoryStats.Usage - stats.MemoryStats.Stats.Cache)
c.MemLimit = int64(stats.MemoryStats.Limit)
c.MemPercent = percent(float64(c.MemUsage), float64(c.MemLimit))
}
@ -107,10 +112,10 @@ func (c *Docker) ReadIO(stats *api.Stats) {
var read, write int64
for _, blk := range stats.BlkioStats.IOServiceBytesRecursive {
if blk.Op == "Read" {
read = int64(blk.Value)
read += int64(blk.Value)
}
if blk.Op == "Write" {
write = int64(blk.Value)
write += int64(blk.Value)
}
}
c.IOBytesRead, c.IOBytesWrite = read, write

View File

@ -17,6 +17,14 @@ type DockerLogs struct {
done chan bool
}
func NewDockerLogs(id string, client *api.Client) *DockerLogs {
return &DockerLogs{
id: id,
client: client,
done: make(chan bool),
}
}
func (l *DockerLogs) Stream() chan models.Log {
r, w := io.Pipe()
logCh := make(chan models.Log)
@ -26,21 +34,28 @@ func (l *DockerLogs) Stream() chan models.Log {
Context: ctx,
Container: l.id,
OutputStream: w,
ErrorStream: w,
Stdout: true,
Stderr: true,
Tail: "10",
Follow: true,
Timestamps: true,
//ErrorStream: w,
Stdout: true,
Stderr: true,
Tail: "20",
Follow: true,
Timestamps: true,
RawTerminal: true,
}
// read io pipe into channel
go func() {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
parts := strings.Split(scanner.Text(), " ")
ts := l.parseTime(parts[0])
logCh <- models.Log{ts, strings.Join(parts[1:], " ")}
parts := strings.SplitN(scanner.Text(), " ", 2)
if len(parts) == 0 {
continue
}
if len(parts) < 2 {
logCh <- models.Log{Timestamp: l.parseTime(""), Message: parts[0]}
} else {
logCh <- models.Log{Timestamp: l.parseTime(parts[0]), Message: parts[1]}
}
}
}()
@ -50,25 +65,41 @@ func (l *DockerLogs) Stream() chan models.Log {
if err != nil {
log.Errorf("error reading container logs: %s", err)
}
log.Infof("log reader stopped for container: %s", l.id)
}()
go func() {
select {
case <-l.done:
cancel()
}
<-l.done
cancel()
}()
log.Infof("log reader started for container: %s", l.id)
return logCh
}
func (l *DockerLogs) Stop() { l.done <- true }
func (l *DockerLogs) parseTime(s string) time.Time {
ts, err := time.Parse("2006-01-02T15:04:05.000000000Z", s)
if err != nil {
log.Errorf("failed to parse container log: %s", err)
ts = time.Now()
ts, err := time.Parse(time.RFC3339Nano, s)
if err == nil {
return ts
}
return ts
ts, err2 := time.Parse(time.RFC3339Nano, l.stripPfx(s))
if err2 == nil {
return ts
}
log.Errorf("failed to parse container log: %s", err)
log.Errorf("failed to parse container log2: %s", err2)
return time.Now()
}
// attempt to strip message header prefix from a given raw docker log string
func (l *DockerLogs) stripPfx(s string) string {
b := []byte(s)
if len(b) > 8 {
return string(b[8:])
}
return s
}

View File

@ -1,3 +1,4 @@
//go:build !release
// +build !release
package collector
@ -38,6 +39,7 @@ func (c *Mock) Start() {
}
func (c *Mock) Stop() {
c.running = false
c.done = true
}

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

@ -1,16 +1,18 @@
// +build !darwin
//go:build linux
// +build linux
package collector
import (
linuxproc "github.com/c9s/goprocinfo/linux"
"github.com/opencontainers/runc/libcontainer/system"
)
var sysMemTotal = getSysMemTotal()
var clockTicksPerSecond = uint64(system.GetClockTicks())
const nanoSecondsPerSecond = 1e9
const (
clockTicksPerSecond uint64 = 100
nanoSecondsPerSecond = 1e9
)
func getSysMemTotal() int64 {
stat, err := linuxproc.ReadMemInfo("/proc/meminfo")

View File

@ -1,13 +1,16 @@
// +build !darwin
//go:build linux
// +build linux
package collector
import (
"time"
"github.com/bcicen/ctop/models"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/types"
"github.com/bcicen/ctop/models"
)
// Runc collector
@ -44,6 +47,7 @@ func (c *Runc) Start() {
}
func (c *Runc) Stop() {
c.running = false
c.done = true
}
@ -83,14 +87,15 @@ func (c *Runc) run() {
func (c *Runc) ReadCPU(stats *cgroups.Stats) {
u := stats.CpuStats.CpuUsage
ncpus := float64(len(u.PercpuUsage))
ncpus := uint8(len(u.PercpuUsage))
total := float64(u.TotalUsage)
system := float64(getSysCPUUsage())
cpudiff := total - c.lastCpu
syscpudiff := system - c.lastSysCpu
c.CPUUtil = round((cpudiff / syscpudiff * 100) * ncpus)
c.NCpus = ncpus
c.CPUUtil = percent(cpudiff, syscpudiff)
c.lastCpu = total
c.lastSysCpu = system
c.Pids = int(stats.PidsStats.Current)
@ -105,7 +110,7 @@ func (c *Runc) ReadMem(stats *cgroups.Stats) {
c.MemPercent = percent(float64(c.MemUsage), float64(c.MemLimit))
}
func (c *Runc) ReadNet(interfaces []*libcontainer.NetworkInterface) {
func (c *Runc) ReadNet(interfaces []*types.NetworkInterface) {
var rx, tx int64
for _, network := range interfaces {
rx += int64(network.RxBytes)

View File

@ -4,56 +4,124 @@ import (
"fmt"
"strings"
"sync"
"time"
"github.com/op/go-logging"
"github.com/hako/durafmt"
"github.com/bcicen/ctop/connector/collector"
"github.com/bcicen/ctop/connector/manager"
"github.com/bcicen/ctop/container"
api "github.com/fsouza/go-dockerclient"
)
func init() { enabled["docker"] = NewDocker }
var actionToStatus = map[string]string{
"start": "running",
"die": "exited",
"stop": "exited",
"pause": "paused",
"unpause": "running",
}
type StatusUpdate struct {
Cid string
Field string // "status" or "health"
Status string
}
type Docker struct {
client *api.Client
containers map[string]*container.Container
needsRefresh chan string // container IDs requiring refresh
statuses chan StatusUpdate
closed chan struct{}
lock sync.RWMutex
}
func NewDocker() Connector {
func NewDocker() (Connector, error) {
// init docker client
client, err := api.NewClientFromEnv()
if err != nil {
panic(err)
return nil, err
}
cm := &Docker{
client: client,
containers: make(map[string]*container.Container),
needsRefresh: make(chan string, 60),
statuses: make(chan StatusUpdate, 60),
closed: make(chan struct{}),
lock: sync.RWMutex{},
}
// query info as pre-flight healthcheck
info, err := client.Info()
if err != nil {
return nil, err
}
log.Debugf("docker-connector ID: %s", info.ID)
log.Debugf("docker-connector Driver: %s", info.Driver)
log.Debugf("docker-connector Images: %d", info.Images)
log.Debugf("docker-connector Name: %s", info.Name)
log.Debugf("docker-connector ServerVersion: %s", info.ServerVersion)
go cm.Loop()
go cm.LoopStatuses()
cm.refreshAll()
go cm.watchEvents()
return cm
return cm, nil
}
// Docker implements Connector
func (cm *Docker) Wait() struct{} { return <-cm.closed }
// Docker events watcher
func (cm *Docker) watchEvents() {
log.Info("docker event listener starting")
events := make(chan *api.APIEvents)
cm.client.AddEventListener(events)
opts := api.EventsOptions{Filters: map[string][]string{
"type": {"container"},
"event": {"create", "start", "health_status", "pause", "unpause", "stop", "die", "destroy"},
},
}
cm.client.AddEventListenerWithOptions(opts, events)
for e := range events {
if e.Type != "container" {
continue
}
switch e.Action {
case "start", "die", "pause", "unpause":
log.Debugf("handling docker event: action=%s id=%s", e.Action, e.ID)
actionName := e.Action
switch actionName {
// most frequent event is a health checks
case "health_status: healthy", "health_status: unhealthy":
sepIdx := strings.Index(actionName, ": ")
healthStatus := e.Action[sepIdx+2:]
if log.IsEnabledFor(logging.DEBUG) {
log.Debugf("handling docker event: action=health_status id=%s %s", e.ID, healthStatus)
}
cm.statuses <- StatusUpdate{e.ID, "health", healthStatus}
case "create":
if log.IsEnabledFor(logging.DEBUG) {
log.Debugf("handling docker event: action=create id=%s", e.ID)
}
cm.needsRefresh <- e.ID
case "destroy":
log.Debugf("handling docker event: action=%s id=%s", e.Action, e.ID)
if log.IsEnabledFor(logging.DEBUG) {
log.Debugf("handling docker event: action=destroy id=%s", e.ID)
}
cm.delByID(e.ID)
default:
// check if this action changes status e.g. start -> running
status := actionToStatus[actionName]
if status != "" {
if log.IsEnabledFor(logging.DEBUG) {
log.Debugf("handling docker event: action=%s id=%s %s", actionName, e.ID, status)
}
cm.statuses <- StatusUpdate{e.ID, "status", status}
}
}
}
log.Info("docker event listener exited")
close(cm.closed)
}
func portsFormat(ports map[api.Port][]api.PortBinding) string {
@ -74,28 +142,79 @@ func portsFormat(ports map[api.Port][]api.PortBinding) string {
return strings.Join(append(exposed, published...), "\n")
}
func webPort(ports map[api.Port][]api.PortBinding) string {
for _, v := range ports {
if len(v) == 0 {
continue
}
for _, binding := range v {
publishedIp := binding.HostIP
if publishedIp == "0.0.0.0" {
publishedIp = "localhost"
}
publishedWebPort := fmt.Sprintf("%s:%s", publishedIp, binding.HostPort)
return publishedWebPort
}
}
return ""
}
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)
insp, found, failed := cm.inspect(c.Id)
if failed {
return
}
// remove container if no longer exists
if insp == nil {
if !found {
cm.delByID(c.Id)
return
}
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"))
webPort := webPort(insp.NetworkSettings.Ports)
if webPort != "" {
c.SetMeta("Web Port", webPort)
}
c.SetMeta("created", insp.Created.Format("Mon Jan 02 15:04:05 2006"))
c.SetMeta("uptime", calcUptime(insp))
c.SetMeta("health", insp.State.Health.Status)
c.SetMeta("[ENV-VAR]", strings.Join(insp.Config.Env, ";"))
c.SetState(insp.State.Status)
}
func (cm *Docker) inspect(id string) *api.Container {
func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bool) {
c, err := cm.client.InspectContainer(id)
if err != nil {
if _, ok := err.(*api.NoSuchContainer); ok == false {
log.Errorf(err.Error())
if _, notFound := err.(*api.NoSuchContainer); notFound {
return c, false, false
}
// other error e.g. connection failed
log.Errorf("%s (%T)", err.Error(), err)
return c, false, true
}
return c
return c, true, false
}
func calcUptime(insp *api.Container) string {
endTime := insp.State.FinishedAt
if endTime.IsZero() || insp.State.Running {
endTime = time.Now()
}
uptime := endTime.Sub(insp.State.StartedAt)
return durafmt.Parse(uptime).LimitFirstN(1).String()
}
// Mark all container IDs for refresh
@ -103,7 +222,8 @@ func (cm *Docker) refreshAll() {
opts := api.ListContainersOptions{All: true}
allContainers, err := cm.client.ListContainers(opts)
if err != nil {
panic(err)
log.Errorf("%s (%T)", err.Error(), err)
return
}
for _, i := range allContainers {
@ -115,21 +235,46 @@ func (cm *Docker) refreshAll() {
}
func (cm *Docker) Loop() {
for id := range cm.needsRefresh {
c := cm.MustGet(id)
cm.refresh(c)
for {
select {
case id := <-cm.needsRefresh:
c := cm.MustGet(id)
cm.refresh(c)
case <-cm.closed:
return
}
}
}
// Get a single container, creating one anew if not existing
func (cm *Docker) LoopStatuses() {
for {
select {
case statusUpdate := <-cm.statuses:
c, _ := cm.Get(statusUpdate.Cid)
if c != nil {
if statusUpdate.Field == "health" {
c.SetMeta("health", statusUpdate.Status)
} else {
c.SetState(statusUpdate.Status)
}
}
case <-cm.closed:
return
}
}
}
// MustGet gets a single container, creating one anew if not existing
func (cm *Docker) MustGet(id string) *container.Container {
c, ok := cm.Get(id)
// append container struct for new containers
if !ok {
// create collector
collector := collector.NewDocker(cm.client, id)
// create manager
manager := manager.NewDocker(cm.client, id)
// create container
c = container.New(id, collector)
c = container.New(id, collector, manager)
cm.lock.Lock()
cm.containers[id] = c
cm.lock.Unlock()
@ -137,7 +282,7 @@ func (cm *Docker) MustGet(id string) *container.Container {
return c
}
// Get a single container, by ID
// Docker implements Connector
func (cm *Docker) Get(id string) (*container.Container, bool) {
cm.lock.Lock()
c, ok := cm.containers[id]
@ -153,12 +298,13 @@ func (cm *Docker) delByID(id string) {
log.Infof("removed dead container: %s", id)
}
// Return array of all containers, sorted by field
// Docker implements Connector
func (cm *Docker) All() (containers container.Containers) {
cm.lock.Lock()
for _, c := range cm.containers {
containers = append(containers, c)
}
containers.Sort()
containers.Filter()
cm.lock.Unlock()
@ -167,5 +313,5 @@ func (cm *Docker) All() (containers container.Containers) {
// use primary container name
func shortName(name string) string {
return strings.Replace(name, "/", "", 1)
return strings.TrimPrefix(name, "/")
}

View File

@ -1,7 +0,0 @@
// +build !linux
package connector
var enabled = map[string]func() Connector{
"docker": NewDocker,
}

View File

@ -1,8 +0,0 @@
// +build !darwin
package connector
var enabled = map[string]func() Connector{
"docker": NewDocker,
"runc": NewRunc,
}

View File

@ -2,25 +2,103 @@ package connector
import (
"fmt"
"sort"
"sync"
"time"
"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/logging"
)
var log = logging.Init()
var (
log = logging.Init()
enabled = make(map[string]ConnectorFn)
)
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)
}
return enabled[s](), nil
}
type ConnectorFn func() (Connector, error)
type Connector interface {
// All returns a pre-sorted container.Containers of all discovered containers
All() container.Containers
// Get returns a single container.Container by ID
Get(string) (*container.Container, bool)
// Wait blocks until the underlying connection is lost
Wait() struct{}
}
// ConnectorSuper provides initial connection and retry on failure for
// an undlerying Connector type
type ConnectorSuper struct {
conn Connector
connFn ConnectorFn
err error
lock sync.RWMutex
}
func NewConnectorSuper(connFn ConnectorFn) *ConnectorSuper {
cs := &ConnectorSuper{
connFn: connFn,
err: fmt.Errorf("connecting..."),
}
go cs.loop()
return cs
}
// Get returns the underlying Connector, or nil and an error
// if the Connector is not yet initialized or is disconnected.
func (cs *ConnectorSuper) Get() (Connector, error) {
cs.lock.RLock()
defer cs.lock.RUnlock()
if cs.err != nil {
return nil, cs.err
}
return cs.conn, nil
}
func (cs *ConnectorSuper) setError(err error) {
cs.lock.Lock()
defer cs.lock.Unlock()
cs.err = err
}
func (cs *ConnectorSuper) loop() {
const interval = 3
for {
log.Infof("initializing connector")
conn, err := cs.connFn()
if err != nil {
cs.setError(err)
log.Errorf("failed to initialize connector: %s (%T)", err, err)
log.Errorf("retrying in %ds", interval)
time.Sleep(interval * time.Second)
} else {
cs.conn = conn
cs.setError(nil)
log.Infof("successfully initialized connector")
// wait until connection closed
cs.conn.Wait()
cs.setError(fmt.Errorf("attempting to reconnect..."))
log.Infof("connector closed")
}
}
}
// Enabled returns 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
}
// ByName returns a ConnectorSuper for a given name, or error if the connector
// does not exists on the current platform
func ByName(s string) (*ConnectorSuper, error) {
if cfn, ok := enabled[s]; ok {
return NewConnectorSuper(cfn), nil
}
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
}

150
connector/manager/docker.go Normal file
View File

@ -0,0 +1,150 @@
package manager
import (
"fmt"
api "github.com/fsouza/go-dockerclient"
"github.com/pkg/errors"
"io"
"os"
)
type Docker struct {
id string
client *api.Client
}
func NewDocker(client *api.Client, id string) *Docker {
return &Docker{
id: id,
client: client,
}
}
// Do not allow to close reader (i.e. /dev/stdin which docker client tries to close after command execution)
type noClosableReader struct {
io.Reader
}
func (w *noClosableReader) Read(p []byte) (n int, err error) {
return w.Reader.Read(p)
}
const (
STDIN = 0
STDOUT = 1
STDERR = 2
)
var wrongFrameFormat = errors.New("Wrong frame format")
// A frame has a Header and a Payload
// Header: [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
// STREAM_TYPE can be:
// 0: stdin (is written on stdout)
// 1: stdout
// 2: stderr
// SIZE1, SIZE2, SIZE3, SIZE4 are the four bytes of the uint32 size encoded as big endian.
// But we don't use size, because we don't need to find the end of frame.
type frameWriter struct {
stdout io.Writer
stderr io.Writer
stdin io.Writer
}
func (w *frameWriter) Write(p []byte) (n int, err error) {
// drop initial empty frames
if len(p) == 0 {
return 0, nil
}
if len(p) > 8 {
var targetWriter io.Writer
switch p[0] {
case STDIN:
targetWriter = w.stdin
break
case STDOUT:
targetWriter = w.stdout
break
case STDERR:
targetWriter = w.stderr
break
default:
return 0, wrongFrameFormat
}
n, err := targetWriter.Write(p[8:])
return n + 8, err
}
return 0, wrongFrameFormat
}
func (dc *Docker) Exec(cmd []string) error {
execCmd, err := dc.client.CreateExec(api.CreateExecOptions{
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
Cmd: cmd,
Container: dc.id,
Tty: true,
})
if err != nil {
return err
}
return dc.client.StartExec(execCmd.ID, api.StartExecOptions{
InputStream: &noClosableReader{os.Stdin},
OutputStream: &frameWriter{os.Stdout, os.Stderr, os.Stdin},
ErrorStream: os.Stderr,
RawTerminal: true,
})
}
func (dc *Docker) Start() error {
c, err := dc.client.InspectContainer(dc.id)
if err != nil {
return fmt.Errorf("cannot inspect container: %v", err)
}
if err := dc.client.StartContainer(c.ID, c.HostConfig); err != nil {
return fmt.Errorf("cannot start container: %v", err)
}
return nil
}
func (dc *Docker) Stop() error {
if err := dc.client.StopContainer(dc.id, 3); err != nil {
return fmt.Errorf("cannot stop container: %v", err)
}
return nil
}
func (dc *Docker) Remove() error {
if err := dc.client.RemoveContainer(api.RemoveContainerOptions{ID: dc.id}); err != nil {
return fmt.Errorf("cannot remove container: %v", err)
}
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
}

15
connector/manager/main.go Normal file
View File

@ -0,0 +1,15 @@
package manager
import "errors"
var ActionNotImplErr = errors.New("action not implemented")
type Manager interface {
Start() error
Stop() error
Remove() error
Pause() error
Unpause() error
Restart() error
Exec(cmd []string) error
}

35
connector/manager/mock.go Normal file
View File

@ -0,0 +1,35 @@
package manager
type Mock struct{}
func NewMock() *Mock {
return &Mock{}
}
func (m *Mock) Start() error {
return ActionNotImplErr
}
func (m *Mock) Stop() error {
return ActionNotImplErr
}
func (m *Mock) Remove() error {
return ActionNotImplErr
}
func (m *Mock) Pause() error {
return ActionNotImplErr
}
func (m *Mock) Unpause() error {
return ActionNotImplErr
}
func (m *Mock) Restart() error {
return ActionNotImplErr
}
func (m *Mock) Exec(cmd []string) error {
return ActionNotImplErr
}

35
connector/manager/runc.go Normal file
View File

@ -0,0 +1,35 @@
package manager
type Runc struct{}
func NewRunc() *Runc {
return &Runc{}
}
func (rc *Runc) Start() error {
return ActionNotImplErr
}
func (rc *Runc) Stop() error {
return ActionNotImplErr
}
func (rc *Runc) Remove() error {
return ActionNotImplErr
}
func (rc *Runc) Pause() error {
return ActionNotImplErr
}
func (rc *Runc) Unpause() error {
return ActionNotImplErr
}
func (rc *Runc) Restart() error {
return ActionNotImplErr
}
func (rc *Runc) Exec(cmd []string) error {
return ActionNotImplErr
}

View File

@ -1,3 +1,4 @@
//go:build !release
// +build !release
package connector
@ -8,20 +9,23 @@ import (
"time"
"github.com/bcicen/ctop/connector/collector"
"github.com/bcicen/ctop/connector/manager"
"github.com/bcicen/ctop/container"
"github.com/jgautheron/codename-generator"
"github.com/nu7hatch/gouuid"
)
func init() { enabled["mock"] = NewMock }
type Mock struct {
containers container.Containers
}
func NewMock() *Mock {
func NewMock() (Connector, error) {
cs := &Mock{}
go cs.Init()
go cs.Loop()
return cs
return cs, nil
}
// Create Mock containers
@ -29,20 +33,46 @@ func (cs *Mock) Init() {
rand.Seed(int64(time.Now().Nanosecond()))
for i := 0; i < 4; i++ {
cs.makeContainer(3)
cs.makeContainer(3, true)
}
for i := 0; i < 16; i++ {
cs.makeContainer(1)
cs.makeContainer(1, false)
}
}
func (cs *Mock) makeContainer(aggression int64) {
func (cs *Mock) Wait() struct{} {
ch := make(chan struct{})
go func() {
time.Sleep(30 * time.Second)
close(ch)
}()
return <-ch
}
var healthStates = []string{"starting", "healthy", "unhealthy"}
func (cs *Mock) makeContainer(aggression int64, health bool) {
collector := collector.NewMock(aggression)
c := container.New(makeID(), collector)
manager := manager.NewMock()
c := container.New(makeID(), collector, manager)
c.SetMeta("name", makeName())
c.SetState(makeState())
if health {
var i int
c.SetMeta("health", healthStates[i])
go func() {
for {
i++
if i >= len(healthStates) {
i = 0
}
c.SetMeta("health", healthStates[i])
time.Sleep(12 * time.Second)
}
}()
}
cs.containers = append(cs.containers, c)
}
@ -69,7 +99,7 @@ func (cs *Mock) Get(id string) (*container.Container, bool) {
return nil, false
}
// Return array of all containers, sorted by field
// All returns array of all containers, sorted by field
func (cs *Mock) All() container.Containers {
cs.containers.Sort()
cs.containers.Filter()

View File

@ -1,9 +1,10 @@
// +build !darwin
//go:build linux
// +build linux
package connector
import (
"fmt"
"errors"
"io/ioutil"
"os"
"path/filepath"
@ -11,11 +12,13 @@ import (
"time"
"github.com/bcicen/ctop/connector/collector"
"github.com/bcicen/ctop/connector/manager"
"github.com/bcicen/ctop/container"
"github.com/opencontainers/runc/libcontainer"
"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
@ -51,35 +54,44 @@ type Runc struct {
factory libcontainer.Factory
containers map[string]*container.Container
libContainers map[string]libcontainer.Container
closed chan struct{}
needsRefresh chan string // container IDs requiring refresh
lock sync.RWMutex
}
func NewRunc() Connector {
func NewRunc() (Connector, error) {
opts, err := NewRuncOpts()
runcFailOnErr(err)
if err != nil {
return nil, err
}
factory, err := getFactory(opts)
runcFailOnErr(err)
factory, err := libcontainer.New(opts.root)
if err != nil {
return nil, err
}
cm := &Runc{
opts: opts,
factory: factory,
containers: make(map[string]*container.Container),
libContainers: make(map[string]libcontainer.Container),
needsRefresh: make(chan string, 60),
closed: make(chan struct{}),
lock: sync.RWMutex{},
}
go func() {
for {
cm.refreshAll()
time.Sleep(5 * time.Second)
select {
case <-cm.closed:
return
case <-time.After(5 * time.Second):
cm.refreshAll()
}
}
}()
go cm.Loop()
return cm
return cm, nil
}
func (cm *Runc) GetLibc(id string) libcontainer.Container {
@ -92,7 +104,7 @@ func (cm *Runc) GetLibc(id string) libcontainer.Container {
libc, err := cm.factory.Load(id)
if err != nil {
// remove container if no longer exists
if lerr, ok := err.(libcontainer.Error); ok && lerr.Code() == libcontainer.ContainerNotExists {
if errors.Is(err, libcontainer.ErrNotExist) {
cm.delByID(id)
} else {
log.Warningf("failed to read container: %s\n", err)
@ -138,7 +150,11 @@ func (cm *Runc) refresh(id string) {
// Read runc root, creating any new containers
func (cm *Runc) refreshAll() {
list, err := ioutil.ReadDir(cm.opts.root)
runcFailOnErr(err)
if err != nil {
log.Errorf("%s (%T)", err.Error(), err)
close(cm.closed)
return
}
for _, i := range list {
if i.IsDir() {
@ -153,7 +169,7 @@ func (cm *Runc) refreshAll() {
}
// queue all existing containers for refresh
for id, _ := range cm.containers {
for id := range cm.containers {
cm.needsRefresh <- id
}
log.Debugf("queued %d containers for refresh", len(cm.containers))
@ -165,7 +181,7 @@ func (cm *Runc) Loop() {
}
}
// Get a single ctop container in the map matching libc container, creating one anew if not existing
// MustGet gets a single ctop container in the map matching libc container, creating one anew if not existing
func (cm *Runc) MustGet(id string) *container.Container {
c, ok := cm.Get(id)
if !ok {
@ -175,7 +191,8 @@ func (cm *Runc) MustGet(id string) *container.Container {
collector := collector.NewRunc(libc)
// create container
c = container.New(id, collector)
manager := manager.NewRunc()
c = container.New(id, collector, manager)
name := libc.ID()
// set initial metadata
@ -195,14 +212,6 @@ func (cm *Runc) MustGet(id string) *container.Container {
return c
}
// Get a single container, by ID
func (cm *Runc) Get(id string) (*container.Container, bool) {
cm.lock.Lock()
defer cm.lock.Unlock()
c, ok := cm.containers[id]
return c, ok
}
// Remove containers by ID
func (cm *Runc) delByID(id string) {
cm.lock.Lock()
@ -212,7 +221,18 @@ func (cm *Runc) delByID(id string) {
log.Infof("removed dead container: %s", id)
}
// Return array of all containers, sorted by field
// Runc implements Connector
func (cm *Runc) Wait() struct{} { return <-cm.closed }
// Runc implements Connector
func (cm *Runc) Get(id string) (*container.Container, bool) {
cm.lock.Lock()
defer cm.lock.Unlock()
c, ok := cm.containers[id]
return c, ok
}
// Runc implements Connector
func (cm *Runc) All() (containers container.Containers) {
cm.lock.Lock()
for _, c := range cm.containers {
@ -223,21 +243,3 @@ func (cm *Runc) All() (containers container.Containers) {
cm.lock.Unlock()
return containers
}
func getFactory(opts RuncOpts) (libcontainer.Factory, error) {
cgroupManager := libcontainer.Cgroupfs
if opts.systemdCgroups {
if systemd.UseSystemd() {
cgroupManager = libcontainer.SystemdCgroups
} else {
return nil, fmt.Errorf("systemd cgroup enabled, but systemd support for managing cgroups is not available")
}
}
return libcontainer.New(opts.root, cgroupManager)
}
func runcFailOnErr(err error) {
if err != nil {
panic(fmt.Errorf("fatal runc error: %s", err))
}
}

View File

@ -2,6 +2,7 @@ package container
import (
"github.com/bcicen/ctop/connector/collector"
"github.com/bcicen/ctop/connector/manager"
"github.com/bcicen/ctop/cwidgets"
"github.com/bcicen/ctop/cwidgets/compact"
"github.com/bcicen/ctop/logging"
@ -12,62 +13,73 @@ var (
log = logging.Init()
)
const (
running = "running"
)
// Metrics and metadata representing a container
type Container struct {
models.Metrics
Id string
Meta map[string]string
Widgets *compact.Compact
Meta models.Meta
Widgets *compact.CompactRow
Display bool // display this container in compact view
updater cwidgets.WidgetUpdater
collector collector.Collector
manager manager.Manager
}
func New(id string, collector collector.Collector) *Container {
widgets := compact.NewCompact(id)
func New(id string, collector collector.Collector, manager manager.Manager) *Container {
widgets := compact.NewCompactRow()
shortID := id
if len(shortID) > 12 {
shortID = shortID[0:12]
}
return &Container{
Metrics: models.NewMetrics(),
Id: id,
Meta: make(map[string]string),
Meta: models.NewMeta("id", shortID),
Widgets: widgets,
updater: widgets,
collector: collector,
manager: manager,
}
}
func (c *Container) RecreateWidgets() {
c.SetUpdater(cwidgets.NullWidgetUpdater{})
c.Widgets = compact.NewCompactRow()
c.SetUpdater(c.Widgets)
}
func (c *Container) SetUpdater(u cwidgets.WidgetUpdater) {
c.updater = u
for k, v := range c.Meta {
c.updater.SetMeta(k, v)
}
c.updater.SetMeta(c.Meta)
}
func (c *Container) SetMeta(k, v string) {
c.Meta[k] = v
c.updater.SetMeta(k, v)
c.updater.SetMeta(c.Meta)
}
func (c *Container) GetMeta(k string) string {
if v, ok := c.Meta[k]; ok {
return v
}
return ""
return c.Meta.Get(k)
}
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()
}
}
// Return container log collector
// Logs returns container log collector
func (c *Container) Logs() collector.LogCollector {
return c.collector.Logs()
}
@ -85,3 +97,68 @@ func (c *Container) Read(stream chan models.Metrics) {
}()
log.Infof("reader started for container: %s", c.Id)
}
func (c *Container) Start() {
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)
}
}
func (c *Container) Stop() {
if c.Meta["state"] == running {
if err := c.manager.Stop(); err != nil {
log.Warningf("container %s: %v", c.Id, err)
log.StatusErr(err)
return
}
c.SetState("exited")
}
}
func (c *Container) Remove() {
if err := c.manager.Remove(); err != nil {
log.Warningf("container %s: %v", c.Id, err)
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
}
}
}
func (c *Container) Exec(cmd []string) error {
return c.manager.Exec(cmd)
}

View File

@ -79,6 +79,15 @@ var Sorters = map[string]sortMethod{
}
return stateMap[c1state] > stateMap[c2state]
},
"uptime": func(c1, c2 *Container) bool {
// Use secondary sort method if equal values
c1Uptime := c1.GetMeta("uptime")
c2Uptime := c2.GetMeta("uptime")
if c1Uptime == c2Uptime {
return nameSorter(c1, c2)
}
return c1Uptime > c2Uptime
},
}
func SortFields() (fields []string) {

View File

@ -11,7 +11,7 @@ import (
type GridCursor struct {
selectedID string // id of currently selected container
filtered container.Containers
cSource connector.Connector
cSuper *connector.ConnectorSuper
isScrolling bool // toggled when actively scrolling
}
@ -25,14 +25,20 @@ func (gc *GridCursor) Selected() *container.Container {
return nil
}
// Refresh containers from source
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
// Refresh containers from source, returning whether the quantity of
// containers has changed and any error
func (gc *GridCursor) RefreshContainers() (bool, error) {
oldLen := gc.Len()
// Containers filtered by display bool
gc.filtered = container.Containers{}
cSource, err := gc.cSuper.Get()
if err != nil {
return true, err
}
// filter Containers by display bool
var cursorVisible bool
for _, c := range gc.cSource.All() {
for _, c := range cSource.All() {
if c.Display {
if c.Id == gc.selectedID {
cursorVisible = true
@ -41,31 +47,30 @@ func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
}
}
if oldLen != gc.Len() {
lenChanged = true
if !cursorVisible || gc.selectedID == "" {
gc.Reset()
}
if !cursorVisible {
gc.Reset()
}
if gc.selectedID == "" {
gc.Reset()
}
return lenChanged
return oldLen != gc.Len(), nil
}
// Set an initial cursor position, if possible
func (gc *GridCursor) Reset() {
for _, c := range gc.cSource.All() {
c.Widgets.Name.UnHighlight()
cSource, err := gc.cSuper.Get()
if err != nil {
return
}
for _, c := range cSource.All() {
c.Widgets.UnHighlight()
}
if gc.Len() > 0 {
gc.selectedID = gc.filtered[0].Id
gc.filtered[0].Widgets.Name.Highlight()
gc.filtered[0].Widgets.Highlight()
}
}
// Return current cursor index
// Idx returns current cursor index
func (gc *GridCursor) Idx() int {
for n, c := range gc.filtered {
if c.Id == gc.selectedID {
@ -109,9 +114,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 +133,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 +156,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 +179,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

@ -0,0 +1,55 @@
package compact
import (
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
var (
allCols = map[string]NewCompactColFn{
"status": NewStatus,
"name": NewNameCol,
"id": NewCIDCol,
"image": NewImageCol,
"ports": NewPortsCol,
"IPs": NewIpsCol,
"created": NewCreatedCol,
"cpu": NewCPUCol,
"cpus": NewCpuScaledCol,
"mem": NewMemCol,
"net": NewNetCol,
"io": NewIOCol,
"pids": NewPIDCol,
"uptime": NewUptimeCol,
}
)
type NewCompactColFn func() CompactCol
func newRowWidgets() []CompactCol {
enabled := config.EnabledColumns()
cols := make([]CompactCol, len(enabled))
for n, name := range enabled {
wFn, ok := allCols[name]
if !ok {
panic("no such widget name: %s" + name)
}
cols[n] = wFn()
}
return cols
}
type CompactCol interface {
ui.GridBufferer
Reset()
Header() string // header text to display for column
FixedWidth() int // fixed width size. if == 0, width is automatically calculated
Highlight()
UnHighlight()
SetMeta(models.Meta)
SetMetrics(models.Metrics)
}

View File

@ -1,21 +1,68 @@
package compact
import (
"fmt"
"github.com/bcicen/ctop/cwidgets"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
type GaugeCol struct {
*ui.Gauge
type CPUCol struct {
*GaugeCol
scaleCpu bool
}
func NewGaugeCol() *GaugeCol {
g := ui.NewGauge()
func NewCPUCol() CompactCol {
return &CPUCol{NewGaugeCol("CPU"), false}
}
func NewCpuScaledCol() CompactCol {
return &CPUCol{NewGaugeCol("CPUS"), true}
}
func (w *CPUCol) SetMetrics(m models.Metrics) {
val := m.CPUUtil
w.BarColor = colorScale(val)
if !w.scaleCpu {
val = val * int(m.NCpus)
}
w.Label = fmt.Sprintf("%d%%", val)
if val > 100 {
val = 100
}
w.Percent = val
}
type MemCol struct {
*GaugeCol
}
func NewMemCol() CompactCol {
return &MemCol{NewGaugeCol("MEM")}
}
func (w *MemCol) SetMetrics(m models.Metrics) {
w.BarColor = ui.ThemeAttr("gauge.bar.bg")
w.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.MemUsage), cwidgets.ByteFormat64Short(m.MemLimit))
w.Percent = m.MemPercent
}
type GaugeCol struct {
*ui.Gauge
header string
fWidth int
}
func NewGaugeCol(header string) *GaugeCol {
g := &GaugeCol{ui.NewGauge(), header, 0}
g.Height = 1
g.Border = false
g.Percent = 0
g.PaddingBottom = 0
g.Label = "-"
return &GaugeCol{g}
g.Reset()
return g
}
func (w *GaugeCol) Reset() {
@ -23,12 +70,41 @@ func (w *GaugeCol) Reset() {
w.Percent = 0
}
func colorScale(n int) ui.Attribute {
if n > 70 {
return ui.ColorRed
func (w *GaugeCol) Buffer() ui.Buffer {
// if bar would not otherwise be visible, set a minimum
// percentage value and low-contrast color for structure
if w.Percent < 5 {
w.Percent = 5
w.BarColor = ui.ColorBlack
}
if n > 30 {
return ui.ColorYellow
}
return ui.ColorGreen
return w.Gauge.Buffer()
}
// GaugeCol implements CompactCol
func (w *GaugeCol) SetMeta(models.Meta) {}
func (w *GaugeCol) SetMetrics(models.Metrics) {}
func (w *GaugeCol) Header() string { return w.header }
func (w *GaugeCol) FixedWidth() int { return w.fWidth }
// GaugeCol implements CompactCol
func (w *GaugeCol) Highlight() {
w.Bg = ui.ThemeAttr("par.text.fg")
w.PercentColor = ui.ThemeAttr("par.text.hi")
}
// GaugeCol implements CompactCol
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.ok")
}
if n <= 90 {
return ui.ThemeAttr("status.warn")
}
return ui.ThemeAttr("status.danger")
}

View File

@ -4,11 +4,11 @@ import (
ui "github.com/gizak/termui"
)
var header *CompactHeader
type CompactGrid struct {
ui.GridBufferer
Rows []ui.GridBufferer
header *CompactHeader
cols []CompactCol // reference columns
Rows []RowBufferer
X, Y int
Width int
Height int
@ -16,37 +16,64 @@ type CompactGrid struct {
}
func NewCompactGrid() *CompactGrid {
header = NewCompactHeader() // init column header
return &CompactGrid{}
cg := &CompactGrid{header: NewCompactHeader()}
cg.rebuildHeader()
return cg
}
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
}
// update row ypos, width recursively
colWidths := cg.calcWidths()
for _, r := range cg.pageRows() {
r.SetY(y)
y += r.GetHeight()
r.SetWidth(cg.Width)
r.SetWidths(cg.Width, colWidths)
}
}
func (cg *CompactGrid) Clear() { cg.Rows = []ui.GridBufferer{} }
func (cg *CompactGrid) GetHeight() int { return len(cg.Rows) + header.Height }
func (cg *CompactGrid) Clear() {
cg.Rows = []RowBufferer{}
cg.rebuildHeader()
}
func (cg *CompactGrid) GetHeight() int { return len(cg.Rows) + cg.header.Height }
func (cg *CompactGrid) SetX(x int) { cg.X = x }
func (cg *CompactGrid) SetY(y int) { cg.Y = y }
func (cg *CompactGrid) SetWidth(w int) { cg.Width = w }
func (cg *CompactGrid) MaxRows() int { return ui.TermHeight() - header.Height - cg.Y }
func (cg *CompactGrid) MaxRows() int { return ui.TermHeight() - cg.header.Height - cg.Y }
func (cg *CompactGrid) pageRows() (rows []ui.GridBufferer) {
rows = append(rows, header)
// calculate and return per-column width
func (cg *CompactGrid) calcWidths() []int {
var autoCols int
width := cg.Width
colWidths := make([]int, len(cg.cols))
for n, w := range cg.cols {
colWidths[n] = w.FixedWidth()
width -= w.FixedWidth()
if w.FixedWidth() == 0 {
autoCols++
}
}
spacing := colSpacing * len(cg.cols)
autoWidth := (width - spacing) / autoCols
for n, val := range colWidths {
if val == 0 {
colWidths[n] = autoWidth
}
}
return colWidths
}
func (cg *CompactGrid) pageRows() (rows []RowBufferer) {
rows = append(rows, cg.header)
rows = append(rows, cg.Rows[cg.Offset:]...)
return rows
}
@ -59,8 +86,14 @@ func (cg *CompactGrid) Buffer() ui.Buffer {
return buf
}
func (cg *CompactGrid) AddRows(rows ...ui.GridBufferer) {
for _, r := range rows {
cg.Rows = append(cg.Rows, r)
func (cg *CompactGrid) AddRows(rows ...RowBufferer) {
cg.Rows = append(cg.Rows, rows...)
}
func (cg *CompactGrid) rebuildHeader() {
cg.cols = newRowWidgets()
cg.header.clearFieldPars()
for _, col := range cg.cols {
cg.header.addFieldPar(col.Header())
}
}

View File

@ -8,63 +8,59 @@ type CompactHeader struct {
X, Y int
Width int
Height int
cols []CompactCol
widths []int
pars []*ui.Par
}
func NewCompactHeader() *CompactHeader {
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX", "IO R/W", "PIDS"}
ch := &CompactHeader{}
ch.Height = 2
for _, f := range fields {
ch.addFieldPar(f)
return &CompactHeader{
X: rowPadding,
Height: 2,
}
return ch
}
func (ch *CompactHeader) GetHeight() int {
return ch.Height
func (row *CompactHeader) GetHeight() int {
return row.Height
}
func (ch *CompactHeader) SetWidth(w int) {
x := ch.X
autoWidth := calcWidth(w)
for n, col := range ch.pars {
// set column to static width
if colWidths[n] != 0 {
col.SetX(x)
col.SetWidth(colWidths[n])
x += colWidths[n]
continue
}
col.SetX(x)
col.SetWidth(autoWidth)
x += autoWidth + colSpacing
func (row *CompactHeader) SetWidths(totalWidth int, widths []int) {
x := row.X
for n, w := range row.pars {
w.SetX(x)
w.SetWidth(widths[n])
x += widths[n] + colSpacing
}
ch.Width = w
row.Width = totalWidth
}
func (ch *CompactHeader) SetX(x int) {
ch.X = x
func (row *CompactHeader) SetX(x int) {
row.X = x
}
func (ch *CompactHeader) SetY(y int) {
for _, p := range ch.pars {
func (row *CompactHeader) SetY(y int) {
for _, p := range row.pars {
p.SetY(y)
}
ch.Y = y
row.Y = y
}
func (ch *CompactHeader) Buffer() ui.Buffer {
func (row *CompactHeader) Buffer() ui.Buffer {
buf := ui.NewBuffer()
for _, p := range ch.pars {
for _, p := range row.pars {
buf.Merge(p.Buffer())
}
return buf
}
func (ch *CompactHeader) addFieldPar(s string) {
p := ui.NewPar(s)
p.Height = ch.Height
p.Border = false
ch.pars = append(ch.pars, p)
func (row *CompactHeader) clearFieldPars() {
row.pars = []*ui.Par{}
}
func (row *CompactHeader) addFieldPar(s string) {
p := ui.NewPar(s)
p.Height = row.Height
p.Border = false
row.pars = append(row.pars, p)
}

View File

@ -1,142 +0,0 @@
package compact
import (
"github.com/bcicen/ctop/logging"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
var log = logging.Init()
type Compact struct {
Status *Status
Name *TextCol
Cid *TextCol
Cpu *GaugeCol
Memory *GaugeCol
Net *TextCol
IO *TextCol
Pids *TextCol
X, Y int
Width int
Height int
}
func NewCompact(id string) *Compact {
// truncate container id
if len(id) > 12 {
id = id[:12]
}
row := &Compact{
Status: NewStatus(),
Name: NewTextCol("-"),
Cid: NewTextCol(id),
Cpu: NewGaugeCol(),
Memory: NewGaugeCol(),
Net: NewTextCol("-"),
IO: NewTextCol("-"),
Pids: NewTextCol("-"),
X: 1,
Height: 1,
}
return row
}
//func (row *Compact) ToggleExpand() {
//if row.Height == 1 {
//row.Height = 4
//} else {
//row.Height = 1
//}
//}
func (row *Compact) SetMeta(k, v string) {
switch k {
case "name":
row.Name.Set(v)
case "state":
row.Status.Set(v)
}
}
func (row *Compact) SetMetrics(m models.Metrics) {
row.SetCPU(m.CPUUtil)
row.SetNet(m.NetRx, m.NetTx)
row.SetMem(m.MemUsage, m.MemLimit, m.MemPercent)
row.SetIO(m.IOBytesRead, m.IOBytesWrite)
row.SetPids(m.Pids)
}
// Set gauges, counters to default unread values
func (row *Compact) Reset() {
row.Cpu.Reset()
row.Memory.Reset()
row.Net.Reset()
row.IO.Reset()
row.Pids.Reset()
}
func (row *Compact) GetHeight() int {
return row.Height
}
func (row *Compact) SetX(x int) {
row.X = x
}
func (row *Compact) SetY(y int) {
if y == row.Y {
return
}
for _, col := range row.all() {
col.SetY(y)
}
row.Y = y
}
func (row *Compact) SetWidth(width int) {
if width == row.Width {
return
}
x := row.X
autoWidth := calcWidth(width)
for n, col := range row.all() {
if colWidths[n] != 0 {
col.SetX(x)
col.SetWidth(colWidths[n])
x += colWidths[n]
continue
}
col.SetX(x)
col.SetWidth(autoWidth)
x += autoWidth + colSpacing
}
row.Width = width
}
func (row *Compact) Buffer() ui.Buffer {
buf := ui.NewBuffer()
buf.Merge(row.Status.Buffer())
buf.Merge(row.Name.Buffer())
buf.Merge(row.Cid.Buffer())
buf.Merge(row.Cpu.Buffer())
buf.Merge(row.Memory.Buffer())
buf.Merge(row.Net.Buffer())
buf.Merge(row.IO.Buffer())
buf.Merge(row.Pids.Buffer())
return buf
}
func (row *Compact) all() []ui.GridBufferer {
return []ui.GridBufferer{
row.Status,
row.Name,
row.Cid,
row.Cpu,
row.Memory,
row.Net,
row.IO,
row.Pids,
}
}

129
cwidgets/compact/row.go Normal file
View File

@ -0,0 +1,129 @@
package compact
import (
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/logging"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
const rowPadding = 1
var log = logging.Init()
type RowBufferer interface {
SetY(int)
SetWidths(int, []int)
GetHeight() int
Buffer() ui.Buffer
}
type CompactRow struct {
Bg *RowBg
Cols []CompactCol
X, Y int
Height int
widths []int // column widths
}
func NewCompactRow() *CompactRow {
row := &CompactRow{
Bg: NewRowBg(),
Cols: newRowWidgets(),
X: rowPadding,
Height: 1,
}
return row
}
func (row *CompactRow) SetMeta(m models.Meta) {
for _, w := range row.Cols {
w.SetMeta(m)
}
}
func (row *CompactRow) SetMetrics(m models.Metrics) {
for _, w := range row.Cols {
w.SetMetrics(m)
}
}
// Set gauges, counters, etc. to default unread values
func (row *CompactRow) Reset() {
for _, w := range row.Cols {
w.Reset()
}
}
func (row *CompactRow) GetHeight() int { return row.Height }
//func (row *CompactRow) SetX(x int) { row.X = x }
func (row *CompactRow) SetY(y int) {
if y == row.Y {
return
}
row.Bg.Y = y
for _, w := range row.Cols {
w.SetY(y)
}
row.Y = y
}
func (row *CompactRow) SetWidths(totalWidth int, widths []int) {
x := row.X
row.Bg.SetX(x)
row.Bg.SetWidth(totalWidth)
for n, w := range row.Cols {
w.SetX(x)
w.SetWidth(widths[n])
x += widths[n] + colSpacing
}
}
func (row *CompactRow) Buffer() ui.Buffer {
buf := ui.NewBuffer()
buf.Merge(row.Bg.Buffer())
for _, w := range row.Cols {
buf.Merge(w.Buffer())
}
return buf
}
func (row *CompactRow) Highlight() {
row.Cols[1].Highlight()
if config.GetSwitchVal("fullRowCursor") {
for _, w := range row.Cols {
w.Highlight()
}
}
}
func (row *CompactRow) UnHighlight() {
row.Cols[1].UnHighlight()
if config.GetSwitchVal("fullRowCursor") {
for _, w := range row.Cols {
w.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

@ -1,48 +0,0 @@
package compact
import (
"fmt"
"strconv"
"github.com/bcicen/ctop/cwidgets"
ui "github.com/gizak/termui"
)
func (row *Compact) SetNet(rx int64, tx int64) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(rx), cwidgets.ByteFormat(tx))
row.Net.Set(label)
}
func (row *Compact) SetIO(read int64, write int64) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat(read), cwidgets.ByteFormat(write))
row.IO.Set(label)
}
func (row *Compact) SetPids(val int) {
label := fmt.Sprintf("%s", strconv.Itoa(val))
row.Pids.Set(label)
}
func (row *Compact) SetCPU(val int) {
row.Cpu.BarColor = colorScale(val)
row.Cpu.Label = fmt.Sprintf("%s%%", strconv.Itoa(val))
if val < 5 {
val = 5
row.Cpu.BarColor = ui.ThemeAttr("gauge.bar.bg")
}
if val > 100 {
val = 100
}
row.Cpu.Percent = val
}
func (row *Compact) SetMem(val int64, limit int64, percent int) {
row.Memory.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(val), cwidgets.ByteFormat(limit))
if percent < 5 {
percent = 5
row.Memory.BarColor = ui.ColorBlack
} else {
row.Memory.BarColor = ui.ThemeAttr("gauge.bar.bg")
}
row.Memory.Percent = percent
}

View File

@ -1,44 +1,94 @@
package compact
import (
"fmt"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
const (
mark = string('\u25C9')
vBar = string('\u25AE')
statusWidth = 3
)
// Status indicator
type Status struct {
*ui.Par
*ui.Block
status []ui.Cell
health []ui.Cell
}
func NewStatus() *Status {
p := ui.NewPar(mark)
p.Border = false
p.Height = 1
p.Width = statusWidth
return &Status{p}
func NewStatus() CompactCol {
s := &Status{
Block: ui.NewBlock(),
status: []ui.Cell{{Ch: ' '}},
health: []ui.Cell{{Ch: ' '}},
}
s.Height = 1
s.Border = false
return s
}
func (s *Status) Set(val string) {
// defaults
text := mark
func (s *Status) Buffer() ui.Buffer {
buf := s.Block.Buffer()
buf.Set(s.InnerX(), s.InnerY(), s.health[0])
buf.Set(s.InnerX()+2, s.InnerY(), s.status[0])
return buf
}
func (s *Status) SetMeta(m models.Meta) {
s.setState(m.Get("state"))
s.setHealth(m.Get("health"))
}
// Status implements CompactCol
func (s *Status) Reset() {}
func (s *Status) SetMetrics(models.Metrics) {}
func (s *Status) Highlight() {}
func (s *Status) UnHighlight() {}
func (s *Status) Header() string { return "" }
func (s *Status) FixedWidth() int { return 3 }
func (s *Status) setState(val string) {
color := ui.ColorDefault
var mark string
switch val {
case "":
return
case "created":
mark = "◉"
case "running":
color = ui.ColorGreen
mark = "▶"
color = ui.ThemeAttr("status.ok")
case "exited":
color = ui.ColorRed
mark = "⏹"
color = ui.ThemeAttr("status.danger")
case "paused":
text = fmt.Sprintf("%s%s", vBar, vBar)
mark = "⏸"
default:
mark = " "
log.Warningf("unknown status string: \"%v\"", val)
}
s.Text = text
s.TextFgColor = color
s.status = ui.TextCells(mark, color, ui.ColorDefault)
}
func (s *Status) setHealth(val string) {
color := ui.ColorDefault
var mark string
switch val {
case "":
return
case "healthy":
mark = "☼"
color = ui.ThemeAttr("status.ok")
case "unhealthy":
mark = "⚠"
color = ui.ThemeAttr("status.danger")
case "starting":
mark = "◌"
color = ui.ThemeAttr("status.warn")
default:
mark = " "
log.Warningf("unknown health state string: \"%v\"", val)
}
s.health = ui.TextCells(mark, color, ui.ColorDefault)
}

View File

@ -1,35 +1,147 @@
package compact
import (
"fmt"
"github.com/bcicen/ctop/cwidgets"
"github.com/bcicen/ctop/models"
ui "github.com/gizak/termui"
)
type TextCol struct {
*ui.Par
// Column that shows container's meta property i.e. name, id, image tc.
type MetaCol struct {
*TextCol
metaName string
}
func NewTextCol(s string) *TextCol {
p := ui.NewPar(s)
func (w *MetaCol) SetMeta(m models.Meta) {
w.setText(m.Get(w.metaName))
}
func NewNameCol() CompactCol {
c := &MetaCol{NewTextCol("NAME"), "name"}
c.fWidth = 30
return c
}
func NewCIDCol() CompactCol {
c := &MetaCol{NewTextCol("CID"), "id"}
c.fWidth = 12
return c
}
func NewImageCol() CompactCol {
return &MetaCol{NewTextCol("IMAGE"), "image"}
}
func NewPortsCol() CompactCol {
return &MetaCol{NewTextCol("PORTS"), "ports"}
}
func NewIpsCol() CompactCol {
return &MetaCol{NewTextCol("IPs"), "IPs"}
}
func NewCreatedCol() CompactCol {
c := &MetaCol{NewTextCol("CREATED"), "created"}
c.fWidth = 19 // Year will be stripped e.g. "Thu Nov 26 07:44:03" without 2020 at end
return c
}
type NetCol struct {
*TextCol
}
func NewNetCol() CompactCol {
return &NetCol{NewTextCol("NET RX/TX")}
}
func (w *NetCol) SetMetrics(m models.Metrics) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.NetRx), cwidgets.ByteFormat64Short(m.NetTx))
w.setText(label)
}
type IOCol struct {
*TextCol
}
func NewIOCol() CompactCol {
return &IOCol{NewTextCol("IO R/W")}
}
func (w *IOCol) SetMetrics(m models.Metrics) {
label := fmt.Sprintf("%s / %s", cwidgets.ByteFormat64Short(m.IOBytesRead), cwidgets.ByteFormat64Short(m.IOBytesWrite))
w.setText(label)
}
type PIDCol struct {
*TextCol
}
func NewPIDCol() CompactCol {
w := &PIDCol{NewTextCol("PIDS")}
w.fWidth = 4
return w
}
func (w *PIDCol) SetMetrics(m models.Metrics) {
w.setText(fmt.Sprintf("%d", m.Pids))
}
type UptimeCol struct {
*TextCol
}
func NewUptimeCol() CompactCol {
return &UptimeCol{NewTextCol("UPTIME")}
}
func (w *UptimeCol) SetMeta(m models.Meta) {
w.Text = m.Get("uptime")
}
type TextCol struct {
*ui.Par
header string
fWidth int
}
func NewTextCol(header string) *TextCol {
p := ui.NewPar("-")
p.Border = false
p.Height = 1
p.Width = 20
return &TextCol{p}
return &TextCol{
Par: p,
header: header,
fWidth: 0,
}
}
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")
}
func (w *TextCol) Reset() {
w.Text = "-"
}
// TextCol implements CompactCol
func (w *TextCol) Reset() { w.setText("-") }
func (w *TextCol) SetMeta(models.Meta) {}
func (w *TextCol) SetMetrics(models.Metrics) {}
func (w *TextCol) Header() string { return w.header }
func (w *TextCol) FixedWidth() int { return w.fWidth }
func (w *TextCol) Set(s string) {
func (w *TextCol) setText(s string) {
if w.fWidth > 0 && len(s) > w.fWidth {
s = s[0:w.fWidth]
}
w.Text = s
}

View File

@ -4,36 +4,12 @@ package compact
import (
"fmt"
ui "github.com/gizak/termui"
)
const colSpacing = 1
// per-column width. 0 == auto width
var colWidths = []int{
3, // status
0, // name
0, // cid
0, // cpu
0, // memory
0, // net
0, // io
4, // pids
}
// Calculate per-column width, given total width
func calcWidth(width int) int {
spacing := colSpacing * len(colWidths)
var staticCols int
for _, w := range colWidths {
width -= w
if w == 0 {
staticCols += 1
}
}
return (width - spacing) / staticCols
}
func centerParText(p *ui.Par) {
var text string
var padding string

View File

@ -8,6 +8,14 @@ import (
var log = logging.Init()
type WidgetUpdater interface {
SetMeta(string, string)
SetMeta(models.Meta)
SetMetrics(models.Metrics)
}
type NullWidgetUpdater struct{}
// NullWidgetUpdater implements WidgetUpdater
func (wu NullWidgetUpdater) SetMeta(models.Meta) {}
// NullWidgetUpdater implements WidgetUpdater
func (wu NullWidgetUpdater) SetMetrics(models.Metrics) {}

View File

@ -1,4 +1,4 @@
package expanded
package single
import (
ui "github.com/gizak/termui"
@ -20,10 +20,10 @@ func NewCpu() *Cpu {
// hack to force the default minY scale to 0
tmpData := []float64{20}
cpu.Data = tmpData
cpu.Data["CPU"] = tmpData
_ = cpu.Buffer()
cpu.Data = cpu.hist.Data
cpu.Data["CPU"] = cpu.hist.Data
return cpu
}

42
cwidgets/single/env.go Normal file
View File

@ -0,0 +1,42 @@
package single
import (
"regexp"
"strings"
ui "github.com/gizak/termui"
)
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(allEnvs string) {
envs := strings.Split(allEnvs, ";")
w.Rows = [][]string{}
for _, env := range envs {
match := envPattern.FindStringSubmatch(env)
if len(match) == 3 {
key := match[1]
value := match[2]
w.data[key] = value
w.Rows = append(w.Rows, mkInfoRows(key, value)...)
}
}
w.Height = len(w.Rows) + 2
}

View File

@ -1,4 +1,4 @@
package expanded
package single
type IntHist struct {
Val int // most current data point

View File

@ -1,4 +1,4 @@
package expanded
package single
import (
"strings"
@ -6,21 +6,20 @@ import (
ui "github.com/gizak/termui"
)
var displayInfo = []string{"id", "name", "image", "ports", "state", "created"}
var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "uptime", "health"}
type Info struct {
*ui.Table
data map[string]string
}
func NewInfo(id string) *Info {
func NewInfo() *Info {
p := ui.NewTable()
p.Height = 4
p.Width = colWidth[0]
p.FgColor = ui.ThemeAttr("par.text.fg")
p.Separator = false
i := &Info{p, make(map[string]string)}
i.Set("id", id)
return i
}
@ -45,7 +44,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

@ -1,4 +1,4 @@
package expanded
package single
import (
"fmt"
@ -42,10 +42,10 @@ func (w *IO) Update(read int64, write int64) {
var rate string
w.readHist.Append(int(read))
rate = strings.ToLower(cwidgets.ByteFormatInt(w.readHist.Val))
rate = strings.ToLower(cwidgets.ByteFormatShort(w.readHist.Val))
w.Lines[0].Title = fmt.Sprintf("read [%s/s]", rate)
w.writeHist.Append(int(write))
rate = strings.ToLower(cwidgets.ByteFormatInt(w.writeHist.Val))
rate = strings.ToLower(cwidgets.ByteFormatShort(w.writeHist.Val))
w.Lines[1].Title = fmt.Sprintf("write [%s/s]", rate)
}

View File

@ -1,4 +1,4 @@
package expanded
package single
import (
"time"

View File

@ -1,4 +1,4 @@
package expanded
package single
import (
"github.com/bcicen/ctop/logging"
@ -12,31 +12,30 @@ var (
colWidth = [2]int{65, 0} // left,right column width
)
type Expanded struct {
type Single struct {
Info *Info
Net *Net
Cpu *Cpu
Mem *Mem
IO *IO
Env *Env
X, Y int
Width int
}
func NewExpanded(id string) *Expanded {
if len(id) > 12 {
id = id[:12]
}
return &Expanded{
Info: NewInfo(id),
func NewSingle() *Single {
return &Single{
Info: NewInfo(),
Net: NewNet(),
Cpu: NewCpu(),
Mem: NewMem(),
IO: NewIO(),
Env: NewEnv(),
Width: ui.TermWidth(),
}
}
func (e *Expanded) Up() {
func (e *Single) Up() {
if e.Y < 0 {
e.Y++
e.Align()
@ -44,7 +43,7 @@ func (e *Expanded) Up() {
}
}
func (e *Expanded) Down() {
func (e *Single) Down() {
if e.Y > (ui.TermHeight() - e.GetHeight()) {
e.Y--
e.Align()
@ -52,27 +51,36 @@ func (e *Expanded) Down() {
}
}
func (e *Expanded) SetWidth(w int) { e.Width = w }
func (e *Expanded) SetMeta(k, v string) { e.Info.Set(k, v) }
func (e *Single) SetWidth(w int) { e.Width = w }
func (e *Single) SetMeta(m models.Meta) {
for k, v := range m {
if k == "[ENV-VAR]" {
e.Env.Set(v)
} else {
e.Info.Set(k, v)
}
}
}
func (e *Expanded) SetMetrics(m models.Metrics) {
func (e *Single) SetMetrics(m models.Metrics) {
e.Cpu.Update(m.CPUUtil)
e.Net.Update(m.NetRx, m.NetTx)
e.Mem.Update(int(m.MemUsage), int(m.MemLimit))
e.IO.Update(m.IOBytesRead, m.IOBytesWrite)
}
// Return total column height
func (e *Expanded) GetHeight() (h int) {
// GetHeight returns total column height
func (e *Single) GetHeight() (h int) {
h += e.Info.Height
h += e.Net.Height
h += e.Cpu.Height
h += e.Mem.Height
h += e.IO.Height
h += e.Env.Height
return h
}
func (e *Expanded) Align() {
func (e *Single) Align() {
// reset offset if needed
if e.GetHeight() <= ui.TermHeight() {
e.Y = 0
@ -91,10 +99,7 @@ func (e *Expanded) Align() {
log.Debugf("align: width=%v left-col=%v right-col=%v", e.Width, colWidth[0], colWidth[1])
}
func calcWidth(w int) {
}
func (e *Expanded) Buffer() ui.Buffer {
func (e *Single) Buffer() ui.Buffer {
buf := ui.NewBuffer()
if e.Width < (colWidth[0] + colWidth[1]) {
ui.Clear()
@ -106,16 +111,18 @@ func (e *Expanded) 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
}
func (e *Expanded) all() []ui.GridBufferer {
func (e *Single) all() []ui.GridBufferer {
return []ui.GridBufferer{
e.Info,
e.Cpu,
e.Mem,
e.Net,
e.IO,
e.Env,
}
}

View File

@ -1,4 +1,4 @@
package expanded
package single
import (
"fmt"
@ -70,7 +70,7 @@ func newMemChart() *ui.MBarChart {
mbar.BarColor[1] = ui.ColorBlack
mbar.NumColor[1] = ui.ColorBlack
mbar.NumFmt = cwidgets.ByteFormatInt
mbar.NumFmt = cwidgets.ByteFormatShort
//mbar.ShowScale = true
return mbar
}
@ -78,6 +78,6 @@ func newMemChart() *ui.MBarChart {
func (w *Mem) Update(val int, limit int) {
w.valHist.Append(val)
w.limitHist.Append(limit - val)
w.InnerLabel.Text = fmt.Sprintf("%v / %v", cwidgets.ByteFormatInt(val), cwidgets.ByteFormatInt(limit))
w.InnerLabel.Text = fmt.Sprintf("%v / %v", cwidgets.ByteFormatShort(val), cwidgets.ByteFormatShort(limit))
//w.Data[0] = w.hist.data
}

View File

@ -1,4 +1,4 @@
package expanded
package single
import (
"fmt"
@ -42,10 +42,10 @@ func (w *Net) Update(rx int64, tx int64) {
var rate string
w.rxHist.Append(int(rx))
rate = strings.ToLower(cwidgets.ByteFormatInt(w.rxHist.Val))
rate = strings.ToLower(cwidgets.ByteFormat(w.rxHist.Val))
w.Lines[0].Title = fmt.Sprintf("RX [%s/s]", rate)
w.txHist.Append(int(tx))
rate = strings.ToLower(cwidgets.ByteFormatInt(w.txHist.Val))
rate = strings.ToLower(cwidgets.ByteFormat(w.txHist.Val))
w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", rate)
}

View File

@ -1,53 +1,74 @@
package cwidgets
import (
"fmt"
"strconv"
)
const (
kb = 1024
mb = kb * 1024
gb = mb * 1024
tb = gb * 1024
// byte ratio constants
_ = iota
kib float64 = 1 << (10 * iota)
mib
gib
tib
pib
)
// convenience method
func ByteFormatInt(n int) string {
return ByteFormat(int64(n))
var (
units = []float64{
1,
kib,
mib,
gib,
tib,
pib,
}
// short, full unit labels
labels = [][2]string{
[2]string{"B", "B"},
[2]string{"K", "KiB"},
[2]string{"M", "MiB"},
[2]string{"G", "GiB"},
[2]string{"T", "TiB"},
[2]string{"P", "PiB"},
}
)
// convenience methods
func ByteFormat(n int) string { return byteFormat(float64(n), false) }
func ByteFormatShort(n int) string { return byteFormat(float64(n), true) }
func ByteFormat64(n int64) string { return byteFormat(float64(n), false) }
func ByteFormat64Short(n int64) string { return byteFormat(float64(n), true) }
func byteFormat(n float64, short bool) string {
i := len(units) - 1
for i > 0 {
if n >= units[i] {
n /= units[i]
break
}
i--
}
if short {
return unpadFloat(n, 0) + labels[i][0]
}
return unpadFloat(n, 2) + labels[i][1]
}
func ByteFormat(n int64) string {
if n < kb {
return fmt.Sprintf("%sB", strconv.FormatInt(n, 10))
}
if n < mb {
n = n / kb
return fmt.Sprintf("%sK", strconv.FormatInt(n, 10))
}
if n < gb {
n = n / mb
return fmt.Sprintf("%sM", strconv.FormatInt(n, 10))
}
if n < tb {
nf := float64(n) / gb
return fmt.Sprintf("%sG", unpadFloat(nf))
}
nf := float64(n) / tb
return fmt.Sprintf("%sT", unpadFloat(nf))
func unpadFloat(f float64, maxp int) string {
return strconv.FormatFloat(f, 'f', getPrecision(f, maxp), 64)
}
func unpadFloat(f float64) string {
return strconv.FormatFloat(f, 'f', getPrecision(f), 64)
}
func getPrecision(f float64) int {
func getPrecision(f float64, maxp int) int {
frac := int((f - float64(int(f))) * 100)
if frac == 0 {
if frac == 0 || maxp == 0 {
return 0
}
if frac%10 == 0 {
if frac%10 == 0 || maxp < 2 {
return 1
}
return 2 // default precision
return maxp
}

View File

@ -12,6 +12,10 @@ import (
var mstats = &runtime.MemStats{}
func logEvent(e ui.Event) {
// skip timer events e.g. /timer/1s
if e.From == "timer" {
return
}
var s string
s += fmt.Sprintf("Type=%s", quote(e.Type))
s += fmt.Sprintf(" Path=%s", quote(e.Path))

129
glide.lock generated
View File

@ -1,129 +0,0 @@
hash: 0d550b01b3a1c4751a8f5c3fba0c43f62252055e231712729628e514bb494da8
updated: 2017-06-09T18:11:10.930196504-03:00
imports:
- name: github.com/Azure/go-ansiterm
version: fa152c58bc15761d0200cb75fe958b89a9d4888e
subpackages:
- winterm
- name: github.com/c9s/goprocinfo
version: b34328d6e0cd139894ea7347d2624ccf31fa3c58
subpackages:
- linux
- name: github.com/coreos/go-systemd
version: b4a58d95188dd092ae20072bac14cece0e67c388
subpackages:
- activation
- dbus
- util
- name: github.com/docker/docker
version: 90d35abf7b3535c1c319c872900fbd76374e521c
subpackages:
- 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
- name: github.com/docker/go-connections
version: a2afab9802043837035592f1c24827fb70766de9
subpackages:
- nat
- name: github.com/docker/go-units
version: 0dadbb0345b35ec7ef35e228dabb8de89a65bf52
- name: github.com/fsouza/go-dockerclient
version: 318513eb1ab27495afbc67f671ba1080513d8aa0
- name: github.com/gizak/termui
version: ea10e6ccee219e572ffad0ac1909f1a17f6db7d6
repo: https://github.com/bcicen/termui
vcs: git
- name: github.com/godbus/dbus
version: c7fdd8b5cd55e87b4e1f4e372cdb1db61dd6c66f
- name: github.com/golang/protobuf
version: f7137ae6b19afbfd61a94b746fda3b3fe0491874
subpackages:
- proto
- name: github.com/hashicorp/go-cleanhttp
version: 3573b8b52aa7b37b9358d966a898feb387f62437
- name: github.com/jgautheron/codename-generator
version: 16d037c7cc3c9b552fe4af9828b7338d752dbaf9
- name: github.com/maruel/panicparse
version: 25bcac0d793cf4109483505a0d66e066a3a90a80
subpackages:
- stack
- name: github.com/mattn/go-runewidth
version: 14207d285c6c197daabb5c9793d63e7af9ab2d50
- name: github.com/Microsoft/go-winio
version: fff283ad5116362ca252298cfc9b95828956d85d
- name: github.com/mitchellh/go-wordwrap
version: ad45545899c7b13c020ea92b2072220eefad42b8
- name: github.com/nsf/termbox-go
version: 91bae1bb5fa9ee504905ecbe7043fa30e92feaa3
- name: github.com/nu7hatch/gouuid
version: 179d4d0c4d8d407a32af483c2354df1d2c91e6c3
- name: github.com/Nvveen/Gotty
version: cd527374f1e5bff4938207604a14f2e38a9cf512
- name: github.com/op/go-logging
version: b2cb9fa56473e98db8caba80237377e83fe44db5
- name: github.com/opencontainers/runc
version: baf6536d6259209c3edfa2b22237af82942d3dfa
subpackages:
- 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
- name: github.com/seccomp/libseccomp-golang
version: 1b506fc7c24eec5a3693cdcbed40d9c226cfc6a1
- name: github.com/Sirupsen/logrus
version: 26709e2714106fb8ad40b773b711ebce25b78914
- name: github.com/syndtr/gocapability
version: 2c00daeb6c3b45114c80ac44119e7b8801fdd852
subpackages:
- capability
- name: github.com/vishvananda/netlink
version: 1e2e08e8a2dcdacaae3f14ac44c5cfa31361f270
subpackages:
- nl
- name: golang.org/x/net
version: a6577fac2d73be281a500b310739095313165611
subpackages:
- context
- context/ctxhttp
- name: golang.org/x/sys
version: 99f16d856c9836c42d24e7ab64ea72916925fa97
subpackages:
- unix
- windows
testImports: []

View File

@ -1,18 +0,0 @@
package: github.com/bcicen/ctop
import:
- package: github.com/c9s/goprocinfo/linux
- package: github.com/docker/docker
version: ^17.5.0-ce-rc3
- package: github.com/opencontainers/runc
version: 0.1.1
- package: github.com/fsouza/go-dockerclient
version: 318513eb1ab27495afbc67f671ba1080513d8aa0
- package: github.com/gizak/termui
version: barchart-numfmt
repo: https://github.com/bcicen/termui
vcs: git
- package: github.com/jgautheron/codename-generator
- package: github.com/nu7hatch/gouuid
- package: github.com/c9s/goprocinfo/linux
- package: github.com/op/go-logging
version: ^1.0.0

64
go.mod Normal file
View File

@ -0,0 +1,64 @@
module github.com/bcicen/ctop
require (
github.com/BurntSushi/toml v0.3.1
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd
github.com/fsouza/go-dockerclient v1.7.0
github.com/gizak/termui v2.3.1-0.20180817033724-8d4faad06196+incompatible
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b // indirect
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c
github.com/mattn/go-runewidth v0.0.2
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473
github.com/opencontainers/runc v1.1.0
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.4.0
)
require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/Microsoft/hcsshim v0.8.10 // indirect
github.com/checkpoint-restore/go-criu/v5 v5.3.0 // indirect
github.com/cilium/ebpf v0.7.0 // indirect
github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/containerd/containerd v1.4.1 // indirect
github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gogo/protobuf v1.3.1 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/maruel/panicparse v1.6.1 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/moby/sys/mount v0.2.0 // indirect
github.com/moby/sys/mountinfo v0.5.0 // indirect
github.com/moby/term v0.0.0-20201110203204-bea5bbe245bf // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/mrunalp/fileutils v0.5.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.1 // indirect
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 // indirect
github.com/opencontainers/selinux v1.10.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/vishvananda/netlink v1.1.0 // indirect
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect
go.opencensus.io v0.22.0 // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
go 1.18

256
go.sum Normal file
View File

@ -0,0 +1,256 @@
bazil.org/fuse v0.0.0-20160811212531-371fbbdaa898/go.mod h1:Xbm+BRKSBEpa4q4hTSxohYNQpsxXPbPry4JJWOB3LB8=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Microsoft/go-winio v0.4.15-0.20200908182639-5b44b70ab3ab/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/Microsoft/hcsshim v0.8.10 h1:k5wTrpnVU2/xv8ZuzGkbXVd3js5zJ8RnumPo5RxiIxU=
github.com/Microsoft/hcsshim v0.8.10/go.mod h1:g5uw8EV2mAlzqe94tfNBNdr89fnbD/n3HV0OhsddkmM=
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd h1:xqaBnULC8wEnQpRDXAsDgXkU/STqoluz1REOoegSfNU=
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE=
github.com/checkpoint-restore/go-criu/v5 v5.3.0 h1:wpFFOoomK3389ue2lAb0Boag6XPht5QYpipxmSNL4d8=
github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E=
github.com/cilium/ebpf v0.0.0-20200110133405-4032b1d8aae3/go.mod h1:MA5e5Lr8slmEg9bt0VpxxWqJlO4iwu3FBdHUzV7wQVg=
github.com/cilium/ebpf v0.7.0 h1:1k/q3ATgxSXRdrmPfH8d7YK0GfqVsEKZAX9dQZvs56k=
github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59 h1:qWj4qVYZ95vLWwqyNJCQg7rDsG5wPdze0UaPolH7DUk=
github.com/containerd/cgroups v0.0.0-20200531161412-0dbf7f05ba59/go.mod h1:pA0z1pT8KYB3TCXK/ocprsh7MAkoW8bZVzPdih9snmM=
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containerd/containerd v1.3.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/containerd v1.4.1 h1:pASeJT3R3YyVn+94qEPk0SnU1OQ20Jd/T+SPKy9xehY=
github.com/containerd/containerd v1.4.1/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a h1:jEIoR0aA5GogXZ8pP3DUzE+zrhaF6/1rYZy+7KkYEWM=
github.com/containerd/continuity v0.0.0-20200928162600-f2cc35102c2a/go.mod h1:W0qIOTD7mp2He++YVq+kgfXezRYqzP1uDuMVH1bITDY=
github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI=
github.com/containerd/go-runc v0.0.0-20180907222934-5a6d9f37cfa3/go.mod h1:IV7qH3hrUgRmyYrtgEeGWJfWbgcHL9CSRruz2Vqcph0=
github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o=
github.com/containerd/typeurl v0.0.0-20180627222232-a93fcdb778cd/go.mod h1:Cm3kwCdlkCfMSHURc+r6fwoGH6/F1hH3S4sg0rLFWPc=
github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk=
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible h1:lwpV3629md5omgAKjxPWX17shI7vMRpE3nyb9WHn8pA=
github.com/docker/docker v20.10.0-beta1.0.20201113105859-b6bfff2a628f+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY=
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/fsouza/go-dockerclient v1.7.0 h1:Ie1/8pAnBHNyCbSIDnYKBdXUEobk4AeJhWZz7k6rWfc=
github.com/fsouza/go-dockerclient v1.7.0/go.mod h1:Ny0LfP7OOsYu9nAi4339E4Ifor6nGBFO2M8lnd2nR+c=
github.com/gizak/termui v2.3.1-0.20180817033724-8d4faad06196+incompatible h1:pUbrySwhNIu18YXjMTCt/Z3kr8eYQ8hRDs4BeR/crmA=
github.com/gizak/termui v2.3.1-0.20180817033724-8d4faad06196+incompatible/go.mod h1:PkJoWUt/zacQKysNfQtcw1RW+eK2SxkieVBtl+4ovLA=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro=
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4=
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c h1:/hc+TxW4Q1v6aqNPHE5jiaNF2xEK0CzWTgo25RQhQ+U=
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c/go.mod h1:FJRkXmPrkHw0WDjB/LXMUhjWJ112Y6JUYnIVBOy8oH8=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/maruel/panicparse v1.6.1 h1:803MjBzGcUgE1vYgg3UMNq3G1oyYeKkMu3t6hBS97x0=
github.com/maruel/panicparse v1.6.1/go.mod h1:uoxI4w9gJL6XahaYPMq/z9uadrdr1SyHuQwV2q80Mm0=
github.com/maruel/panicparse/v2 v2.1.1/go.mod h1:AeTWdCE4lcq8OKsLb6cHSj1RWHVSnV9HBCk7sKLF4Jg=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC63o=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/moby/sys/mount v0.2.0 h1:WhCW5B355jtxndN5ovugJlMFJawbUODuW8fSnEH6SSM=
github.com/moby/sys/mount v0.2.0/go.mod h1:aAivFE2LB3W4bACsUXChRHQ0qKWsetY4Y9V7sxOougM=
github.com/moby/sys/mountinfo v0.4.0/go.mod h1:rEr8tzG/lsIZHBtN/JjGG+LMYx9eXgW2JI+6q0qou+A=
github.com/moby/sys/mountinfo v0.5.0 h1:2Ks8/r6lopsxWi9m58nlwjaeSzUX9iiL1vj5qB/9ObI=
github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU=
github.com/moby/term v0.0.0-20201110203204-bea5bbe245bf h1:Un6PNx5oMK6CCwO3QTUyPiK2mtZnPrpDl5UnZ64eCkw=
github.com/moby/term v0.0.0-20201110203204-bea5bbe245bf/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mrunalp/fileutils v0.5.0 h1:NKzVxiH7eSk+OQ4M+ZYW1K6h27RUV3MI6NUTsHhU6Z4=
github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ=
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840=
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473 h1:J1QZwDXgZ4dJD2s19iqR9+U00OWM2kDzbf1O/fmvCWg=
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI=
github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/runc v0.0.0-20190115041553-12f6a991201f/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U=
github.com/opencontainers/runc v1.1.0 h1:O9+X96OcDjkmmZyfaG996kV7yq8HsoU2h1XRRQcefG8=
github.com/opencontainers/runc v1.1.0/go.mod h1:Tj1hFw6eFWp/o33uxGf5yF2BX5yz2Z6iptFpuvbbKqc=
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/selinux v1.10.0 h1:rAiKF8hTcgLI3w0DHm6i0ylVVcOrlgR1kK99DRLDhyU=
github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI=
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23 h1:dofHuld+js7eKSemxqTVIo8yRlpRw+H1SdpzZxWruBc=
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/procfs v0.0.0-20180125133057-cb4147076ac7/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921 h1:58EBmR2dMNL2n/FnbQewK3D14nXr0V9CObDSvMJLq+Y=
github.com/seccomp/libseccomp-golang v0.9.2-0.20210429002308-3879420cc921/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200120151820-655fe14d7479/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200724161237-0e2f3a69832c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200922070232-aee5d888a860/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c h1:DHcbWVXeY+0Y8HHKR+rbLwnoh2F4tNCY7rTiHJ30RmA=
golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201113234701-d7a72108b828/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0=
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

143
grid.go
View File

@ -2,11 +2,48 @@ package main
import (
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/cwidgets/expanded"
"github.com/bcicen/ctop/cwidgets/single"
ui "github.com/gizak/termui"
)
func ShowConnError(err error) (exit bool) {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
setErr := func(err error) {
errView.Append(err.Error())
errView.Append("attempting to reconnect...")
ui.Render(errView)
}
HandleKeys("exit", func() {
exit = true
ui.StopLoop()
})
ui.Handle("/timer/1s", func(ui.Event) {
_, err := cursor.RefreshContainers()
if err == nil {
ui.StopLoop()
return
}
setErr(err)
})
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
errView.Resize()
ui.Clear()
ui.Render(errView)
log.Infof("RESIZE")
})
errView.Resize()
setErr(err)
ui.Loop()
return exit
}
func RedrawRows(clr bool) {
// reinit body rows
cGrid.Clear()
@ -18,6 +55,7 @@ func RedrawRows(clr bool) {
header.SetFilter(config.GetVal("filterStr"))
y += header.Height()
}
cGrid.SetY(y)
for _, c := range cursor.filtered {
@ -35,12 +73,17 @@ func RedrawRows(clr bool) {
ui.Render(cGrid)
}
func ExpandView(c *container.Container) {
func SingleView() MenuFn {
c := cursor.Selected()
if c == nil {
return nil
}
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
ex := expanded.NewExpanded(c.Id)
ex := single.NewSingle()
c.SetUpdater(ex)
ex.Align()
@ -59,25 +102,31 @@ func ExpandView(c *container.Container) {
ui.Loop()
c.SetUpdater(c.Widgets)
return nil
}
func RefreshDisplay() {
func RefreshDisplay() error {
// skip display refresh during scroll
if !cursor.isScrolling {
needsClear := cursor.RefreshContainers()
needsClear, err := cursor.RefreshContainers()
if err != nil {
return err
}
RedrawRows(needsClear)
}
return nil
}
func Display() bool {
var menu func()
var expand bool
var menu MenuFn
var connErr error
cGrid.SetWidth(ui.TermWidth())
ui.DefaultEvtStream.Hook(logEvent)
// initial draw
header.Align()
status.Align()
cursor.RefreshContainers()
RedrawRows(true)
@ -94,12 +143,38 @@ func Display() bool {
})
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
expand = true
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()
})
ui.Handle("/sys/kbd/e", func(ui.Event) {
menu = ExecShell
ui.StopLoop()
})
ui.Handle("/sys/kbd/w", func(ui.Event) {
menu = OpenInBrowser()
})
ui.Handle("/sys/kbd/o", func(ui.Event) {
menu = SingleView
ui.StopLoop()
})
ui.Handle("/sys/kbd/a", func(ui.Event) {
config.Toggle("allContainers")
RefreshDisplay()
connErr = RefreshDisplay()
if connErr != nil {
ui.StopLoop()
}
})
ui.Handle("/sys/kbd/D", func(ui.Event) {
dumpContainer(cursor.Selected())
@ -119,13 +194,33 @@ func Display() bool {
menu = SortMenu
ui.StopLoop()
})
ui.Handle("/sys/kbd/c", func(ui.Event) {
menu = ColumnsMenu
ui.StopLoop()
})
ui.Handle("/sys/kbd/S", func(ui.Event) {
path, err := config.Write()
if err == nil {
log.Statusf("wrote config to %s", path)
} else {
log.StatusErr(err)
}
ui.StopLoop()
})
ui.Handle("/timer/1s", func(e ui.Event) {
RefreshDisplay()
if log.StatusQueued() {
ui.StopLoop()
}
connErr = RefreshDisplay()
if connErr != nil {
ui.StopLoop()
}
})
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
header.Align()
status.Align()
cursor.ScrollPage()
cGrid.SetWidth(ui.TermWidth())
log.Infof("resize: width=%v max-rows=%v", cGrid.Width, cGrid.MaxRows())
@ -133,16 +228,28 @@ func Display() bool {
})
ui.Loop()
if menu != nil {
menu()
return false
if connErr != nil {
return ShowConnError(connErr)
}
if expand {
c := cursor.Selected()
if c != nil {
ExpandView(c)
if log.StatusQueued() {
for sm := range log.FlushStatus() {
if sm.IsError {
status.ShowErr(sm.Text)
} else {
status.Show(sm.Text)
}
}
return false
}
if menu != nil {
for menu != nil {
menu = menu()
}
return false
}
return true
}

84
install.sh Executable file
View File

@ -0,0 +1,84 @@
#!/usr/bin/env bash
# a simple install script for ctop
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
echo "$@" | while read line; do
case $line in
*browser_download_url*${match}*)
url=$(echo $line | sed -e 's/^.*"browser_download_url":[ ]*"//' -e 's/".*//;s/\ //g')
echo $url
break
;;
esac
done
}
case $KERNEL in
Linux) MATCH_BUILD="linux-amd64" ;;
Darwin) MATCH_BUILD="darwin-amd64" ;;
*)
echo "platform not supported by this install script"
exit 1
;;
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}
output "fetching latest release info"
resp=$(curl -s https://api.github.com/repos/bcicen/ctop/releases/latest)
output "fetching release checksums"
checksum_url=$(extract_url sha256sums.txt "$resp")
wget -q $checksum_url -O sha256sums.txt
# skip if latest already installed
cur_ctop=$(which ctop 2> /dev/null)
if [[ -n "$cur_ctop" ]]; then
cur_sum=$(sha256sum $cur_ctop | sed 's/ .*//')
(grep -q $cur_sum sha256sums.txt) && {
output "already up-to-date"
exit 0
}
fi
output "fetching latest ctop"
url=$(extract_url $MATCH_BUILD "$resp")
wget -q --show-progress $url
(sha256sum -c --quiet --ignore-missing sha256sums.txt) || exit 1
output "installing to /usr/local/bin"
chmod +x ctop-*
$sh_c "mv ctop-* /usr/local/bin/ctop"
output "done!"

View File

@ -1,6 +1,7 @@
package logging
import (
"fmt"
"os"
"time"
@ -20,11 +21,37 @@ var (
)
)
type statusMsg struct {
Text string
IsError bool
}
type CTopLogger struct {
*logging.Logger
backend *logging.MemoryBackend
logFile *os.File
sLog []statusMsg
}
func (c *CTopLogger) FlushStatus() chan statusMsg {
ch := make(chan statusMsg)
go func() {
for _, sm := range c.sLog {
ch <- sm
}
close(ch)
c.sLog = []statusMsg{}
}()
return ch
}
func (c *CTopLogger) StatusQueued() bool { return len(c.sLog) > 0 }
func (c *CTopLogger) Status(s string) { c.addStatus(statusMsg{s, false}) }
func (c *CTopLogger) StatusErr(err error) { c.addStatus(statusMsg{err.Error(), true}) }
func (c *CTopLogger) addStatus(sm statusMsg) { c.sLog = append(c.sLog, sm) }
func (c *CTopLogger) Statusf(s string, a ...interface{}) { c.Status(fmt.Sprintf(s, a...)) }
func Init() *CTopLogger {
if Log == nil {
logging.SetFormatter(format) // setup default formatter
@ -32,17 +59,37 @@ func Init() *CTopLogger {
Log = &CTopLogger{
logging.MustGetLogger("ctop"),
logging.NewMemoryBackend(size),
nil,
[]statusMsg{},
}
if debugMode() {
debugMode := debugMode()
if debugMode {
level = logging.DEBUG
StartServer()
}
backendLvl := logging.AddModuleLevel(Log.backend)
backendLvl.SetLevel(level, "")
logging.SetBackend(backendLvl)
logFilePath := debugModeFile()
if logFilePath == "" {
logging.SetBackend(backendLvl)
} else {
logFile, err := os.OpenFile(logFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
logging.SetBackend(backendLvl)
Log.Error("Unable to create log file: %s", err.Error())
} else {
backendFile := logging.NewLogBackend(logFile, "", 0)
backendFileLvl := logging.AddModuleLevel(backendFile)
backendFileLvl.SetLevel(level, "")
logging.SetBackend(backendLvl, backendFileLvl)
Log.logFile = logFile
}
}
if debugMode {
StartServer()
}
Log.Notice("logger initialized")
}
return Log
@ -75,8 +122,12 @@ func (log *CTopLogger) tail() chan string {
func (log *CTopLogger) Exit() {
exited = true
if log.logFile != nil {
_ = log.logFile.Close()
}
StopServer()
}
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
func debugModeTCP() bool { return os.Getenv("CTOP_DEBUG_TCP") == "1" }
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
func debugModeTCP() bool { return os.Getenv("CTOP_DEBUG_TCP") == "1" }
func debugModeFile() string { return os.Getenv("CTOP_DEBUG_FILE") }

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

46
main.go
View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"runtime"
"strings"
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/connector"
@ -21,10 +22,12 @@ var (
version = "dev-build"
goVersion = runtime.Version()
log *logging.CTopLogger
cursor *GridCursor
cGrid *compact.CompactGrid
header *widgets.CTopHeader
log *logging.CTopLogger
cursor *GridCursor
cGrid *compact.CompactGrid
header *widgets.CTopHeader
status *widgets.StatusLine
errView *widgets.ErrorView
versionStr = fmt.Sprintf("ctop version %v, build %v %v", version, build, goVersion)
)
@ -33,14 +36,16 @@ func main() {
defer panicExit()
// parse command line arguments
var versionFlag = flag.Bool("v", false, "output version information and exit")
var helpFlag = flag.Bool("h", false, "display this help dialog")
var filterFlag = flag.String("f", "", "filter containers")
var activeOnlyFlag = flag.Bool("a", false, "show active containers only")
var sortFieldFlag = flag.String("s", "", "select container sort field")
var reverseSortFlag = flag.Bool("r", false, "reverse container sort order")
var invertFlag = flag.Bool("i", false, "invert default colors")
var connectorFlag = flag.String("connector", "docker", "container connector to use")
var (
versionFlag = flag.Bool("v", false, "output version information and exit")
helpFlag = flag.Bool("h", false, "display this help dialog")
filterFlag = flag.String("f", "", "filter containers")
activeOnlyFlag = flag.Bool("a", false, "show active containers only")
sortFieldFlag = flag.String("s", "", "select container sort field")
reverseSortFlag = flag.Bool("r", false, "reverse container sort order")
invertFlag = flag.Bool("i", false, "invert default colors")
connectorFlag = flag.String("connector", "docker", "container connector to use")
)
flag.Parse()
if *versionFlag {
@ -56,8 +61,11 @@ func main() {
// init logger
log = logging.Init()
// init global config
// init global config and read config file if exists
config.Init()
if err := config.Read(); err != nil {
log.Warningf("reading config: %s", err)
}
// override default config values with command line flags
if *filterFlag != "" {
@ -85,16 +93,19 @@ func main() {
if err := ui.Init(); err != nil {
panic(err)
}
tm.SetInputMode(tm.InputAlt)
defer Shutdown()
// init grid, cursor, header
conn, err := connector.ByName(*connectorFlag)
cSuper, err := connector.ByName(*connectorFlag)
if err != nil {
panic(err)
}
cursor = &GridCursor{cSource: conn}
cursor = &GridCursor{cSuper: cSuper}
cGrid = compact.NewCompactGrid()
header = widgets.NewCTopHeader()
status = widgets.NewStatusLine()
errView = widgets.NewErrorView()
for {
exit := Display()
@ -123,12 +134,13 @@ func validSort(s string) {
func panicExit() {
if r := recover(); r != nil {
Shutdown()
panic(r)
fmt.Printf("error: %s\n", r)
os.Exit(1)
}
}
var helpMsg = `ctop - container metric viewer
var helpMsg = `ctop - interactive container viewer
usage: ctop [options]
@ -138,4 +150,6 @@ options:
func printHelp() {
fmt.Println(helpMsg)
flag.PrintDefaults()
fmt.Printf("\navailable connectors: ")
fmt.Println(strings.Join(connector.Enabled(), ", "))
}

422
menus.go
View File

@ -1,24 +1,40 @@
package main
import (
"fmt"
"strings"
"time"
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/container"
"github.com/bcicen/ctop/widgets"
"github.com/bcicen/ctop/widgets/menu"
ui "github.com/gizak/termui"
"github.com/pkg/browser"
)
// MenuFn executes a menu window, returning the next menu or nil
type MenuFn func() MenuFn
var helpDialog = []menu.Item{
menu.Item{"[a] - toggle display of all containers", ""},
menu.Item{"[f] - filter displayed containers", ""},
menu.Item{"[h] - open this help dialog", ""},
menu.Item{"[H] - toggle ctop header", ""},
menu.Item{"[s] - select container sort field", ""},
menu.Item{"[r] - reverse container sort order", ""},
menu.Item{"[q] - exit ctop", ""},
{"<enter> - open container menu", ""},
{"", ""},
{"[a] - toggle display of all containers", ""},
{"[f] - filter displayed containers", ""},
{"[h] - open this help dialog", ""},
{"[H] - toggle ctop header", ""},
{"[s] - select container sort field", ""},
{"[r] - reverse container sort order", ""},
{"[o] - open single view", ""},
{"[l] - view container logs ([t] to toggle timestamp when open)", ""},
{"[e] - exec shell", ""},
{"[w] - open browser (first port is http)", ""},
{"[c] - configure columns", ""},
{"[S] - save current configuration to file", ""},
{"[q] - exit ctop", ""},
}
func HelpMenu() {
func HelpMenu() MenuFn {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
@ -26,14 +42,18 @@ func HelpMenu() {
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()
})
ui.Loop()
return nil
}
func FilterMenu() {
func FilterMenu() MenuFn {
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
@ -63,9 +83,10 @@ func FilterMenu() {
ui.StopLoop()
})
ui.Loop()
return nil
}
func SortMenu() {
func SortMenu() MenuFn {
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
@ -87,10 +108,387 @@ func SortMenu() {
HandleKeys("exit", ui.StopLoop)
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
config.Update("sortField", m.SelectedItem().Val)
config.Update("sortField", m.SelectedValue())
ui.StopLoop()
})
ui.Render(m)
ui.Loop()
return nil
}
func ColumnsMenu() MenuFn {
const (
enabledStr = "[X]"
disabledStr = "[ ]"
padding = 2
)
ui.Clear()
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
m := menu.NewMenu()
m.Selectable = true
m.SortItems = false
m.BorderLabel = "Columns"
m.SubText = "Re-order: <Page Up> / <Page Down>"
rebuild := func() {
// get padding for right alignment of enabled status
var maxLen int
for _, col := range config.GlobalColumns {
if len(col.Label) > maxLen {
maxLen = len(col.Label)
}
}
maxLen += padding
// rebuild menu items
m.ClearItems()
for _, col := range config.GlobalColumns {
txt := col.Label + strings.Repeat(" ", maxLen-len(col.Label))
if col.Enabled {
txt += enabledStr
} else {
txt += disabledStr
}
m.AddItems(menu.Item{col.Name, txt})
}
}
upFn := func() {
config.ColumnLeft(m.SelectedValue())
m.Up()
rebuild()
}
downFn := func() {
config.ColumnRight(m.SelectedValue())
m.Down()
rebuild()
}
toggleFn := func() {
config.ColumnToggle(m.SelectedValue())
rebuild()
}
rebuild()
HandleKeys("up", m.Up)
HandleKeys("down", m.Down)
HandleKeys("enter", toggleFn)
HandleKeys("pgup", upFn)
HandleKeys("pgdown", downFn)
ui.Handle("/sys/kbd/x", func(ui.Event) { toggleFn() })
ui.Handle("/sys/kbd/<enter>", func(ui.Event) { toggleFn() })
HandleKeys("exit", func() {
cSource, err := cursor.cSuper.Get()
if err == nil {
for _, c := range cSource.All() {
c.RecreateWidgets()
}
}
ui.StopLoop()
})
ui.Render(m)
ui.Loop()
return nil
}
func ContainerMenu() MenuFn {
c := cursor.Selected()
if c == nil {
return nil
}
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
m := menu.NewMenu()
m.Selectable = true
m.BorderLabel = "Menu"
items := []menu.Item{
menu.Item{Val: "single", Label: "[o] single view"},
menu.Item{Val: "logs", Label: "[l] log view"},
}
if c.Meta["state"] == "running" {
items = append(items, menu.Item{Val: "stop", Label: "[s] stop"})
items = append(items, menu.Item{Val: "pause", Label: "[p] pause"})
items = append(items, menu.Item{Val: "restart", Label: "[r] restart"})
items = append(items, menu.Item{Val: "exec", Label: "[e] exec shell"})
if c.Meta["Web Port"] != "" {
items = append(items, menu.Item{Val: "browser", Label: "[w] open in browser"})
}
}
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
items = append(items, menu.Item{Val: "start", Label: "[s] start"})
items = append(items, menu.Item{Val: "remove", Label: "[R] remove"})
}
if c.Meta["state"] == "paused" {
items = append(items, menu.Item{Val: "unpause", Label: "[p] unpause"})
}
items = append(items, menu.Item{Val: "cancel", Label: "[c] cancel"})
m.AddItems(items...)
ui.Render(m)
HandleKeys("up", m.Up)
HandleKeys("down", m.Down)
var selected string
// shortcuts
ui.Handle("/sys/kbd/o", func(ui.Event) {
selected = "single"
ui.StopLoop()
})
ui.Handle("/sys/kbd/l", func(ui.Event) {
selected = "logs"
ui.StopLoop()
})
if c.Meta["state"] != "paused" {
ui.Handle("/sys/kbd/s", func(ui.Event) {
if c.Meta["state"] == "running" {
selected = "stop"
} else {
selected = "start"
}
ui.StopLoop()
})
}
if c.Meta["state"] != "exited" && c.Meta["state"] != "created" {
ui.Handle("/sys/kbd/p", func(ui.Event) {
if c.Meta["state"] == "paused" {
selected = "unpause"
} else {
selected = "pause"
}
ui.StopLoop()
})
}
if c.Meta["state"] == "running" {
ui.Handle("/sys/kbd/e", func(ui.Event) {
selected = "exec"
ui.StopLoop()
})
ui.Handle("/sys/kbd/r", func(ui.Event) {
selected = "restart"
ui.StopLoop()
})
if c.Meta["Web Port"] != "" {
ui.Handle("/sys/kbd/w", func(ui.Event) {
selected = "browser"
})
}
}
ui.Handle("/sys/kbd/R", func(ui.Event) {
selected = "remove"
ui.StopLoop()
})
ui.Handle("/sys/kbd/c", func(ui.Event) {
ui.StopLoop()
})
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
selected = m.SelectedValue()
ui.StopLoop()
})
ui.Handle("/sys/kbd/", func(ui.Event) {
ui.StopLoop()
})
ui.Loop()
var nextMenu MenuFn
switch selected {
case "single":
nextMenu = SingleView
case "logs":
nextMenu = LogMenu
case "exec":
nextMenu = ExecShell
case "browser":
nextMenu = OpenInBrowser
case "start":
nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start)
case "stop":
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)
}
return nextMenu
}
func LogMenu() MenuFn {
c := cursor.Selected()
if c == nil {
return nil
}
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
logs, quit := logReader(c)
m := widgets.NewTextView(logs)
m.BorderLabel = fmt.Sprintf("Logs [%s]", c.GetMeta("name"))
ui.Render(m)
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
m.Resize()
})
ui.Handle("/sys/kbd/t", func(ui.Event) {
m.Toggle()
})
ui.Handle("/sys/kbd/", func(ui.Event) {
quit <- true
ui.StopLoop()
})
ui.Loop()
return nil
}
func ExecShell() MenuFn {
c := cursor.Selected()
if c == nil {
return nil
}
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
// Detect and execute default shell in container.
// Execute Ash shell command: /bin/sh -c
// Reset colors: printf '\e[0m\e[?25h'
// Clear screen
// Run default shell for the user. It's configured in /etc/passwd and looks like root:x:0:0:root:/root:/bin/bash:
// 1. Get current user id: id -un
// 2. Find user's line in /etc/passwd by grep
// 3. Extract default user's shell by cutting seven's column separated by :
// 4. Execute the shell path with eval
if err := c.Exec([]string{"/bin/sh", "-c", "printf '\\e[0m\\e[?25h' && clear && eval `grep ^$(id -un): /etc/passwd | cut -d : -f 7-`"}); err != nil {
log.StatusErr(err)
}
return nil
}
func OpenInBrowser() MenuFn {
c := cursor.Selected()
if c == nil {
return nil
}
webPort := c.Meta.Get("Web Port")
if webPort == "" {
return nil
}
link := "http://" + webPort + "/"
browser.OpenURL(link)
return nil
}
// Create a confirmation dialog with a given description string and
// func to perform if confirmed
func Confirm(txt string, fn func()) MenuFn {
menu := func() MenuFn {
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
m := menu.NewMenu()
m.Selectable = true
m.BorderLabel = "Confirm"
m.SubText = txt
items := []menu.Item{
menu.Item{Val: "cancel", Label: "[c]ancel"},
menu.Item{Val: "yes", Label: "[y]es"},
}
var response bool
m.AddItems(items...)
ui.Render(m)
yes := func() {
response = true
ui.StopLoop()
}
no := func() {
response = false
ui.StopLoop()
}
HandleKeys("up", m.Up)
HandleKeys("down", m.Down)
HandleKeys("exit", no)
ui.Handle("/sys/kbd/c", func(ui.Event) { no() })
ui.Handle("/sys/kbd/y", func(ui.Event) { yes() })
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
switch m.SelectedValue() {
case "cancel":
no()
case "yes":
yes()
}
})
ui.Loop()
if response {
fn()
}
return nil
}
return menu
}
type toggleLog struct {
timestamp time.Time
message string
}
func (t *toggleLog) Toggle(on bool) string {
if on {
return fmt.Sprintf("%s %s", t.timestamp.Format("2006-01-02T15:04:05.999Z07:00"), t.message)
}
return t.message
}
func logReader(container *container.Container) (logs chan widgets.ToggleText, quit chan bool) {
logCollector := container.Logs()
stream := logCollector.Stream()
logs = make(chan widgets.ToggleText)
quit = make(chan bool)
go func() {
for {
select {
case log := <-stream:
logs <- &toggleLog{timestamp: log.Timestamp, message: log.Message}
case <-quit:
logCollector.Stop()
close(logs)
return
}
}
}()
return
}
func confirmTxt(a, n string) string { return fmt.Sprintf("%s container %s?", a, n) }

View File

@ -7,7 +7,31 @@ type Log struct {
Message string
}
type Meta map[string]string
// NewMeta returns an initialized Meta map.
// An optional series of key, values may be provided to populate the map prior to returning
func NewMeta(kvs ...string) Meta {
m := make(Meta)
var i int
for i < len(kvs)-1 {
m[kvs[i]] = kvs[i+1]
i += 2
}
return m
}
func (m Meta) Get(k string) string {
if s, ok := m[k]; ok {
return s
}
return ""
}
type Metrics struct {
NCpus uint8
CPUUtil int
NetTx int64
NetRx int64

60
widgets/error.go Normal file
View File

@ -0,0 +1,60 @@
package widgets
import (
"fmt"
"strings"
"time"
ui "github.com/gizak/termui"
)
type ErrorView struct {
*ui.Par
lines []string
}
func NewErrorView() *ErrorView {
const yPad = 1
const xPad = 2
p := ui.NewPar("")
p.X = xPad
p.Y = yPad
p.Border = true
p.Height = 10
p.Width = 20
p.PaddingTop = yPad
p.PaddingBottom = yPad
p.PaddingLeft = xPad
p.PaddingRight = xPad
p.BorderLabel = " ctop - error "
p.Bg = ui.ThemeAttr("bg")
p.TextFgColor = ui.ThemeAttr("status.warn")
p.TextBgColor = ui.ThemeAttr("menu.text.bg")
p.BorderFg = ui.ThemeAttr("status.warn")
p.BorderLabelFg = ui.ThemeAttr("status.warn")
return &ErrorView{p, make([]string, 0, 50)}
}
func (w *ErrorView) Append(s string) {
if len(w.lines)+2 >= cap(w.lines) {
w.lines = append(w.lines[:0], w.lines[2:]...)
}
ts := time.Now().Local().Format("15:04:05 MST")
w.lines = append(w.lines, fmt.Sprintf("[%s] %s", ts, s))
w.lines = append(w.lines, "")
}
func (w *ErrorView) Buffer() ui.Buffer {
offset := len(w.lines) - w.InnerHeight()
if offset < 0 {
offset = 0
}
w.Text = strings.Join(w.lines[offset:len(w.lines)], "\n")
return w.Par.Buffer()
}
func (w *ErrorView) Resize() {
w.Height = ui.TermHeight() - (w.PaddingTop + w.PaddingBottom)
w.SetWidth(ui.TermWidth() - (w.PaddingLeft + w.PaddingRight))
}

View File

@ -16,9 +16,9 @@ type CTopHeader struct {
func NewCTopHeader() *CTopHeader {
return &CTopHeader{
Time: headerPar(2, timeStr()),
Count: headerPar(27, "-"),
Filter: headerPar(47, ""),
Time: headerPar(2, ""),
Count: headerPar(24, "-"),
Filter: headerPar(40, ""),
bg: headerBg(),
}
}

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)

View File

@ -10,13 +10,15 @@ type Padding [2]int // x,y padding
type Menu struct {
ui.Block
SortItems bool // enable automatic sorting of menu items
SortItems bool // enable automatic sorting of menu items
Selectable bool // whether menu is navigable
SubText string // optional text to display before items
TextFgColor ui.Attribute
TextBgColor ui.Attribute
Selectable bool
cursorPos int
items Items
padding Padding
toolTip *ToolTip
}
func NewMenu() *Menu {
@ -41,7 +43,7 @@ func (m *Menu) AddItems(items ...Item) {
m.refresh()
}
// Remove menu item by value or label
// DelItem removes menu item by value or label
func (m *Menu) DelItem(s string) (success bool) {
for n, i := range m.items {
if i.Val == s || i.Label == s {
@ -54,6 +56,11 @@ func (m *Menu) DelItem(s string) (success bool) {
return success
}
// ClearItems removes all current menu items
func (m *Menu) ClearItems() {
m.items = m.items[:0]
}
// Move cursor to an position by Item value or label
func (m *Menu) SetCursor(s string) (success bool) {
for n, i := range m.items {
@ -65,26 +72,36 @@ func (m *Menu) SetCursor(s string) (success bool) {
return false
}
// Sort menu items(if enabled) and re-calculate window size
func (m *Menu) refresh() {
if m.SortItems {
sort.Sort(m.items)
}
m.calcSize()
ui.Render(m)
// SetToolTip sets an optional tooltip string to show at bottom of screen
func (m *Menu) SetToolTip(lines ...string) {
m.toolTip = NewToolTip(lines...)
}
func (m *Menu) SelectedItem() Item {
return m.items[m.cursorPos]
}
func (m *Menu) SelectedValue() string {
return m.items[m.cursorPos].Val
}
func (m *Menu) Buffer() ui.Buffer {
var cell ui.Cell
buf := m.Block.Buffer()
y := m.Y + m.padding[1]
if m.SubText != "" {
x := m.X + m.padding[0]
for i, ch := range m.SubText {
cell = ui.Cell{Ch: ch, Fg: m.TextFgColor, Bg: m.TextBgColor}
buf.Set(x+i, y, cell)
}
y += 2
}
for n, item := range m.items {
x := m.X + m.padding[0]
y := m.Y + m.padding[1]
for _, ch := range item.Text() {
// invert bg/fg colors on currently selected row
if m.Selectable && n == m.cursorPos {
@ -97,6 +114,10 @@ func (m *Menu) Buffer() ui.Buffer {
}
}
if m.toolTip != nil {
buf.Merge(m.toolTip.Buffer())
}
return buf
}
@ -114,18 +135,35 @@ func (m *Menu) Down() {
}
}
// Sort menu items(if enabled) and re-calculate window size
func (m *Menu) refresh() {
if m.SortItems {
sort.Sort(m.items)
}
m.calcSize()
ui.Render(m)
}
// Set width and height based on menu items
func (m *Menu) calcSize() {
m.Width = 7 // minimum width
items := m.items
var height int
for _, i := range m.items {
s := i.Text()
if len(s) > m.Width {
m.Width = len(s)
}
height++
}
if m.SubText != "" {
if len(m.SubText) > m.Width {
m.Width = len(m.SubText)
}
height += 2
}
m.Width += (m.padding[0] * 2)
m.Height = len(items) + (m.padding[1] * 2)
m.Height = height + (m.padding[1] * 2)
}

55
widgets/menu/tooltip.go Normal file
View File

@ -0,0 +1,55 @@
package menu
import (
ui "github.com/gizak/termui"
)
type ToolTip struct {
ui.Block
Lines []string
TextFgColor ui.Attribute
TextBgColor ui.Attribute
padding Padding
}
func NewToolTip(lines ...string) *ToolTip {
t := &ToolTip{
Block: *ui.NewBlock(),
Lines: lines,
TextFgColor: ui.ThemeAttr("menu.text.fg"),
TextBgColor: ui.ThemeAttr("menu.text.bg"),
padding: Padding{2, 1},
}
t.BorderFg = ui.ThemeAttr("menu.border.fg")
t.BorderLabelFg = ui.ThemeAttr("menu.label.fg")
t.X = 1
t.Align()
return t
}
func (t *ToolTip) Buffer() ui.Buffer {
var cell ui.Cell
buf := t.Block.Buffer()
y := t.Y + t.padding[1]
for n, line := range t.Lines {
x := t.X + t.padding[0]
for _, ch := range line {
cell = ui.Cell{Ch: ch, Fg: t.TextFgColor, Bg: t.TextBgColor}
buf.Set(x, y+n, cell)
x++
}
}
return buf
}
// Set width and height based on screen size
func (t *ToolTip) Align() {
t.Width = ui.TermWidth() - (t.padding[0] * 2)
t.Height = len(t.Lines) + (t.padding[1] * 2)
t.Y = ui.TermHeight() - t.Height
t.Block.Align()
}

87
widgets/status.go Normal file
View File

@ -0,0 +1,87 @@
package widgets
import (
ui "github.com/gizak/termui"
)
var (
statusHeight = 1
statusIter = 3
)
type StatusLine struct {
Message *ui.Par
bg *ui.Par
}
func NewStatusLine() *StatusLine {
p := ui.NewPar("")
p.X = 2
p.Border = false
p.Height = statusHeight
p.Bg = ui.ThemeAttr("header.bg")
p.TextFgColor = ui.ThemeAttr("header.fg")
p.TextBgColor = ui.ThemeAttr("header.bg")
return &StatusLine{
Message: p,
bg: statusBg(),
}
}
func (sl *StatusLine) Display() {
ui.DefaultEvtStream.ResetHandlers()
defer ui.DefaultEvtStream.ResetHandlers()
iter := statusIter
ui.Handle("/sys/kbd/", func(ui.Event) {
ui.StopLoop()
})
ui.Handle("/timer/1s", func(ui.Event) {
iter--
if iter <= 0 {
ui.StopLoop()
}
})
ui.Render(sl)
ui.Loop()
}
// change given message on the status line
func (sl *StatusLine) Show(s string) {
sl.Message.TextFgColor = ui.ThemeAttr("header.fg")
sl.Message.Text = s
sl.Display()
}
func (sl *StatusLine) ShowErr(s string) {
sl.Message.TextFgColor = ui.ThemeAttr("status.danger")
sl.Message.Text = s
sl.Display()
}
func (sl *StatusLine) Buffer() ui.Buffer {
buf := ui.NewBuffer()
buf.Merge(sl.bg.Buffer())
buf.Merge(sl.Message.Buffer())
return buf
}
func (sl *StatusLine) Align() {
sl.bg.SetWidth(ui.TermWidth() - 1)
sl.Message.SetWidth(ui.TermWidth() - 2)
sl.bg.Y = ui.TermHeight() - 1
sl.Message.Y = ui.TermHeight() - 1
}
func (sl *StatusLine) Height() int { return statusHeight }
func statusBg() *ui.Par {
bg := ui.NewPar("")
bg.X = 1
bg.Height = statusHeight
bg.Border = false
bg.Bg = ui.ThemeAttr("header.bg")
return bg
}

125
widgets/view.go Normal file
View File

@ -0,0 +1,125 @@
package widgets
import (
ui "github.com/gizak/termui"
"github.com/mattn/go-runewidth"
)
type ToggleText interface {
// returns text for toggle on/off
Toggle(on bool) string
}
type TextView struct {
ui.Block
inputStream <-chan ToggleText
render chan bool
toggleState bool
Text []ToggleText // all the text
TextOut []string // text to be displayed
TextFgColor ui.Attribute
TextBgColor ui.Attribute
padding Padding
}
func NewTextView(lines <-chan ToggleText) *TextView {
t := &TextView{
Block: *ui.NewBlock(),
inputStream: lines,
render: make(chan bool),
Text: []ToggleText{},
TextOut: []string{},
TextFgColor: ui.ThemeAttr("menu.text.fg"),
TextBgColor: ui.ThemeAttr("menu.text.bg"),
padding: Padding{4, 2},
}
t.BorderFg = ui.ThemeAttr("menu.border.fg")
t.BorderLabelFg = ui.ThemeAttr("menu.label.fg")
t.Height = ui.TermHeight()
t.Width = ui.TermWidth()
t.readInputLoop()
t.renderLoop()
return t
}
// Adjusts text inside this view according to the window size. No need to call ui.Render(...)
// after calling this method, it is called automatically
func (t *TextView) Resize() {
ui.Clear()
t.Height = ui.TermHeight()
t.Width = ui.TermWidth()
t.render <- true
}
// Toggles text inside this view. No need to call ui.Render(...) after calling this method,
// it is called automatically
func (t *TextView) Toggle() {
t.toggleState = !t.toggleState
t.render <- true
}
func (t *TextView) Buffer() ui.Buffer {
var cell ui.Cell
buf := t.Block.Buffer()
x := t.Block.X + t.padding[0]
y := t.Block.Y + t.padding[1]
for _, line := range t.TextOut {
for _, ch := range line {
cell = ui.Cell{Ch: ch, Fg: t.TextFgColor, Bg: t.TextBgColor}
buf.Set(x, y, cell)
x = x + runewidth.RuneWidth(ch)
}
x = t.Block.X + t.padding[0]
y++
}
return buf
}
func (t *TextView) renderLoop() {
go func() {
for range t.render {
maxWidth := t.Width - (t.padding[0] * 2)
height := t.Height - (t.padding[1] * 2)
t.TextOut = []string{}
for i := len(t.Text) - 1; i >= 0; i-- {
lines := splitLine(t.Text[i].Toggle(t.toggleState), maxWidth)
t.TextOut = append(lines, t.TextOut...)
if len(t.TextOut) > height {
t.TextOut = t.TextOut[:height]
break
}
}
ui.Render(t)
}
}()
}
func (t *TextView) readInputLoop() {
go func() {
for line := range t.inputStream {
t.Text = append(t.Text, line)
t.render <- true
}
close(t.render)
}()
}
func splitLine(line string, lineSize int) []string {
if line == "" {
return []string{}
}
var lines []string
for {
if len(line) <= lineSize {
lines = append(lines, line)
return lines
}
lines = append(lines, line[:lineSize])
line = line[lineSize:]
}
}

35
widgets/view_test.go Normal file
View File

@ -0,0 +1,35 @@
package widgets
import "testing"
func TestSplitEmptyLine(t *testing.T) {
result := splitLine("", 5)
if len(result) != 0 {
t.Errorf("expected: 0 lines, got: %d", len(result))
}
}
func TestSplitLineShorterThanLimit(t *testing.T) {
result := splitLine("hello", 7)
if len(result) != 1 {
t.Errorf("expected: 0 lines, got: %d", len(result))
}
}
func TestSplitLineLongerThanLimit(t *testing.T) {
result := splitLine("hello", 3)
if len(result) != 2 {
t.Errorf("expected: 0 lines, got: %d", len(result))
}
}
func TestSplitLineSameAsLimit(t *testing.T) {
result := splitLine("hello", 5)
if len(result) != 1 {
t.Errorf("expected: 0 lines, got: %d", len(result))
}
}