mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 15:16:41 +08:00
Compare commits
212 Commits
v0.7.2
...
222a7d77b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
222a7d77b2 | ||
|
|
9bc26c8296 | ||
|
|
5271cf6d90 | ||
|
|
a8e1fb7246 | ||
|
|
d60b215611 | ||
|
|
79242c7de5 | ||
|
|
6dcb62f172 | ||
|
|
163060b3fa | ||
|
|
acbf17a4fd | ||
|
|
021b1710a3 | ||
|
|
2d43cd146f | ||
|
|
11a1cb10f4 | ||
|
|
f83e73d1ea | ||
|
|
1f91033beb | ||
|
|
da09b95d29 | ||
|
|
350cb09338 | ||
|
|
d8542c894c | ||
|
|
be23d85eda | ||
|
|
2047e3fa52 | ||
|
|
4b653e71f6 | ||
|
|
c145cf404a | ||
|
|
52f52a1163 | ||
|
|
94f1f3f558 | ||
|
|
3d5a1c0682 | ||
|
|
1c3577ad4e | ||
|
|
b48a5cf2f9 | ||
|
|
9f8f38f9d7 | ||
|
|
2b898fb216 | ||
|
|
99be3b979e | ||
|
|
29f9abf35c | ||
|
|
82e731e577 | ||
|
|
a603c1b58c | ||
|
|
8f0c9f5048 | ||
|
|
15708224a7 | ||
|
|
442e70b8df | ||
|
|
c58a609349 | ||
|
|
78b038e687 | ||
|
|
2d937aca08 | ||
|
|
77c9001ed1 | ||
|
|
d98ce102b1 | ||
|
|
cfa43f809e | ||
|
|
0094cba5ea | ||
|
|
537bb2adfa | ||
|
|
8dce3ece2b | ||
|
|
dd92e85d45 | ||
|
|
491cd85b4d | ||
|
|
9545dfba31 | ||
|
|
cdcb8b6d99 | ||
|
|
b562c923b3 | ||
|
|
f2c28c5fb0 | ||
|
|
ac76b2eac1 | ||
|
|
b32f90fa4a | ||
|
|
bec78c90b5 | ||
|
|
043f4bd3f3 | ||
|
|
c2401cb33a | ||
|
|
fa254c652c | ||
|
|
a59c7aab3c | ||
|
|
4e44c9d5f7 | ||
|
|
948e7cc9d0 | ||
|
|
4850f817f3 | ||
|
|
10c49018a6 | ||
|
|
6c662d91fb | ||
|
|
b4a63f8c60 | ||
|
|
4973bc83ff | ||
|
|
87d135909f | ||
|
|
7632420ecc | ||
|
|
4fbc998a41 | ||
|
|
117c3bc7b5 | ||
|
|
b1171f6c3e | ||
|
|
9a41252764 | ||
|
|
f377dcaee2 | ||
|
|
65e9c6dff6 | ||
|
|
df0d8b7892 | ||
|
|
2792e72d18 | ||
|
|
68d6da5c61 | ||
|
|
53a6b36bf5 | ||
|
|
5ec02f760e | ||
|
|
83a422933a | ||
|
|
7679d4a7fd | ||
|
|
e34afceb5f | ||
|
|
ddfff03c05 | ||
|
|
29d90cfdd9 | ||
|
|
ba126e6e7c | ||
|
|
009201ed0c | ||
|
|
2c07cab59c | ||
|
|
fd06992236 | ||
|
|
e64edbdc36 | ||
|
|
4c280cee56 | ||
|
|
b65e970a83 | ||
|
|
957cabba2d | ||
|
|
5aacdc3772 | ||
|
|
99d9aeec98 | ||
|
|
44600fca45 | ||
|
|
9aaba5dfca | ||
|
|
0bd8efe800 | ||
|
|
3a29c94833 | ||
|
|
a22d99fefb | ||
|
|
c971d26d42 | ||
|
|
de380ff810 | ||
|
|
e7e2478468 | ||
|
|
42c80c2395 | ||
|
|
d22bbc3420 | ||
|
|
bdfb98265d | ||
|
|
af1908fb27 | ||
|
|
73a976c6fe | ||
|
|
2bcfc365f7 | ||
|
|
ecc7bf4081 | ||
|
|
68e4c32c1b | ||
|
|
a63f05b430 | ||
|
|
426dd2c985 | ||
|
|
0fb627a529 | ||
|
|
c8f74a47a1 | ||
|
|
c984b270db | ||
|
|
41c04fefa2 | ||
|
|
5b2d180f60 | ||
|
|
2fdbb91f87 | ||
|
|
c0703db094 | ||
|
|
53ec5c911a | ||
|
|
c5038e2edd | ||
|
|
e1a52a314d | ||
|
|
bbecbc66b9 | ||
|
|
192d3eaa7a | ||
|
|
d34de844e0 | ||
|
|
a8e235beca | ||
|
|
ed194e8c04 | ||
|
|
09566a4043 | ||
|
|
f11a705b8b | ||
|
|
6fe6e7c316 | ||
|
|
9aa104fbc6 | ||
|
|
7c6b5c54dc | ||
|
|
ffb96f4e90 | ||
|
|
fc9bd9e5ca | ||
|
|
c7a8bfa26f | ||
|
|
6b79e5a370 | ||
|
|
54fc5ac5c6 | ||
|
|
eb8237cbb1 | ||
|
|
60875b179c | ||
|
|
15c5c31726 | ||
|
|
ea5968edce | ||
|
|
c0db41ebcb | ||
|
|
dc14c79edf | ||
|
|
0ca5235ae5 | ||
|
|
8427b0c81d | ||
|
|
9bcf2c2c7a | ||
|
|
03a0da3230 | ||
|
|
4d7d69d4cf | ||
|
|
fae9deb1d9 | ||
|
|
8027b990f8 | ||
|
|
4a0e80ffdf | ||
|
|
c446fb0e11 | ||
|
|
4741b276e4 | ||
|
|
d60b16aad1 | ||
|
|
f704898212 | ||
|
|
1523cc80ca | ||
|
|
b16561dccb | ||
|
|
bf3b89a010 | ||
|
|
5585a22962 | ||
|
|
ca5d40b7cc | ||
|
|
50d1c29d57 | ||
|
|
22a5607012 | ||
|
|
6e60fc905e | ||
|
|
118b89240d | ||
|
|
ee25f80a9c | ||
|
|
416eb5c363 | ||
|
|
746da760fb | ||
|
|
cc6f706c4b | ||
|
|
1ca40bb7e1 | ||
|
|
918ccdbe39 | ||
|
|
8fcd14e097 | ||
|
|
9dd12103fc | ||
|
|
c38942c7ed | ||
|
|
d34b9c2bf6 | ||
|
|
a60861437f | ||
|
|
4b391e900c | ||
|
|
4460162380 | ||
|
|
d56cc9475a | ||
|
|
4584cf34f5 | ||
|
|
1ce07448ce | ||
|
|
c8e896e371 | ||
|
|
db2c832bd7 | ||
|
|
7fdcd7bbf1 | ||
|
|
923edb967e | ||
|
|
1271ce96e8 | ||
|
|
d8c7dd4c5c | ||
|
|
b7d81485f9 | ||
|
|
8946c4b03b | ||
|
|
331f50f03e | ||
|
|
4c4f041b40 | ||
|
|
c8ac331652 | ||
|
|
0a5a4c9062 | ||
|
|
98fcfe8b6f | ||
|
|
42f095cd85 | ||
|
|
73986d2732 | ||
|
|
c1d4615cc0 | ||
|
|
d187e8c623 | ||
|
|
b8c38d09ef | ||
|
|
d7384db373 | ||
|
|
1b441db189 | ||
|
|
0479d42e31 | ||
|
|
b401e7b17e | ||
|
|
9592de82a0 | ||
|
|
29fa8cf3e7 | ||
|
|
c49939f965 | ||
|
|
2f7bc2a172 | ||
|
|
7b4d4db049 | ||
|
|
101ddad692 | ||
|
|
ca35ef2aab | ||
|
|
d59c91a461 | ||
|
|
a26fc9169c | ||
|
|
967a87a65f | ||
|
|
e68f7ba96a | ||
|
|
f27de1c29e |
@@ -3,13 +3,13 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
working_directory: ~/build
|
working_directory: ~/build
|
||||||
docker:
|
docker:
|
||||||
- image: circleci/golang:latest
|
- image: cimg/go:1.18
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- setup_remote_docker:
|
- setup_remote_docker:
|
||||||
version: 17.05.0-ce
|
version: 20.10.11
|
||||||
- run: make image
|
- run: make image
|
||||||
- deploy:
|
- deploy:
|
||||||
command: |
|
command: |
|
||||||
if [[ "$CIRCLE_BRANCH" == "master" ]]; then
|
if [[ "$CIRCLE_BRANCH" == "master" ]]; then
|
||||||
docker tag ctop quay.io/vektorlab/ctop:latest
|
docker tag ctop quay.io/vektorlab/ctop:latest
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
ctop
|
ctop
|
||||||
.idea
|
.idea
|
||||||
/vendor/
|
/vendor/
|
||||||
|
*.log
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
FROM quay.io/vektorcloud/go:1.11
|
FROM quay.io/vektorcloud/go:1.18
|
||||||
|
|
||||||
RUN apk add --no-cache make
|
RUN apk add --no-cache make
|
||||||
|
|
||||||
|
|||||||
28
Makefile
28
Makefile
@@ -1,8 +1,7 @@
|
|||||||
NAME=ctop
|
NAME=ctop
|
||||||
VERSION=$(shell cat VERSION)
|
VERSION=$(shell cat VERSION)
|
||||||
BUILD=$(shell git rev-parse --short HEAD)
|
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)"
|
||||||
LD_FLAGS="-w -X main.version=$(VERSION) -X main.build=$(BUILD) -extldflags=$(EXT_LD_FLAGS)"
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf _build/ release/
|
rm -rf _build/ release/
|
||||||
@@ -11,27 +10,28 @@ build:
|
|||||||
go mod download
|
go mod download
|
||||||
CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o ctop
|
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:
|
build-all:
|
||||||
mkdir -p _build
|
mkdir -p _build
|
||||||
GOOS=darwin GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-darwin-amd64
|
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 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=amd64 CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-amd64
|
||||||
GOOS=linux GOARCH=arm go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm
|
GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm
|
||||||
GOOS=linux GOARCH=arm64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm64
|
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-linux-arm64
|
||||||
GOOS=windows GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o _build/ctop-$(VERSION)-windows-amd64
|
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
|
cd _build; sha256sum * > sha256sums.txt
|
||||||
|
|
||||||
|
run-dev:
|
||||||
|
rm -f ctop.sock ctop
|
||||||
|
go build -ldflags $(LD_FLAGS) -o ctop
|
||||||
|
CTOP_DEBUG=1 ./ctop
|
||||||
|
|
||||||
image:
|
image:
|
||||||
docker build -t ctop -f Dockerfile .
|
docker build -t ctop -f Dockerfile .
|
||||||
|
|
||||||
release:
|
release:
|
||||||
mkdir release
|
mkdir release
|
||||||
go get github.com/progrium/gh-release/...
|
|
||||||
cp _build/* release
|
cp _build/* release
|
||||||
cd release; sha256sum --quiet --check sha256sums.txt
|
cd release; sha256sum --quiet --check sha256sums.txt && \
|
||||||
gh-release create bcicen/$(NAME) $(VERSION) \
|
gh release create v$(VERSION) -d -t v$(VERSION) *
|
||||||
$(shell git rev-parse --abbrev-ref HEAD) $(VERSION)
|
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
|
|||||||
84
README.md
84
README.md
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
![release][release] ![homebrew][homebrew]
|
![release][release] ![homebrew][homebrew] ![macports][macports]
|
||||||
|
|
||||||
Top-like interface for container metrics
|
Top-like interface for container metrics
|
||||||
|
|
||||||
`ctop` provides a concise and condensed overview of real-time metrics for multiple containers:
|
`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>
|
<p align="center"><img src="_docs/img/grid.gif" alt="ctop"/></p>
|
||||||
|
|
||||||
as well as an [single container view][single_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.
|
`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,24 @@ as well as an [single container view][single_view] for inspecting a specific con
|
|||||||
|
|
||||||
Fetch the [latest release](https://github.com/bcicen/ctop/releases) for your platform:
|
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
|
||||||
|
echo "deb http://packages.azlux.fr/debian/ buster main" | sudo tee /etc/apt/sources.list.d/azlux.list
|
||||||
|
wget -qO - https://azlux.fr/repo.gpg.key | sudo apt-key add -
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install docker-ctop
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Arch
|
||||||
|
|
||||||
|
`ctop` is available for Arch in the [AUR](https://aur.archlinux.org/packages/ctop-bin/)
|
||||||
|
|
||||||
|
#### Linux (Generic)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo wget https://github.com/bcicen/ctop/releases/download/v0.7.2/ctop-0.7.2-linux-amd64 -O /usr/local/bin/ctop
|
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
|
sudo chmod +x /usr/local/bin/ctop
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -31,7 +45,11 @@ brew install ctop
|
|||||||
```
|
```
|
||||||
or
|
or
|
||||||
```bash
|
```bash
|
||||||
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.7.2/ctop-0.7.2-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
|
sudo chmod +x /usr/local/bin/ctop
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -40,12 +58,10 @@ sudo chmod +x /usr/local/bin/ctop
|
|||||||
```bash
|
```bash
|
||||||
docker run --rm -ti \
|
docker run --rm -ti \
|
||||||
--name=ctop \
|
--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
|
quay.io/vektorlab/ctop:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
`ctop` is also available for Arch in the [AUR](https://aur.archlinux.org/packages/ctop-bin/)
|
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Build steps can be found [here][build].
|
Build steps can be found [here][build].
|
||||||
@@ -56,39 +72,47 @@ Build steps can be found [here][build].
|
|||||||
|
|
||||||
### Config file
|
### Config file
|
||||||
|
|
||||||
While running, use `S` to save the current filters, sort field, and other options to a default config path. These settings will be loaded and applied the next time `ctop` is started.
|
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
|
### Options
|
||||||
|
|
||||||
Option | Description
|
Option | Description
|
||||||
--- | ---
|
--- | ---
|
||||||
-a | show active containers only
|
`-a` | show active containers only
|
||||||
-f \<string\> | set an initial filter string
|
`-f <string>` | set an initial filter string
|
||||||
-h | display help dialog
|
`-h` | display help dialog
|
||||||
-i | invert default colors
|
`-i` | invert default colors
|
||||||
-r | reverse container sort order
|
`-r` | reverse container sort order
|
||||||
-s | select initial container sort field
|
`-s` | select initial container sort field
|
||||||
-scale-cpu | show cpu as % of system total
|
`-v` | output version information and exit
|
||||||
-v | output version information and exit
|
|
||||||
|
|
||||||
### Keybindings
|
### Keybindings
|
||||||
|
|
||||||
Key | Action
|
| Key | Action |
|
||||||
--- | ---
|
| :----------------------: | ---------------------------------------------------------- |
|
||||||
\<enter\> | Open container menu
|
| <kbd><ENTER></kbd> | Open container menu |
|
||||||
a | Toggle display of all (running and non-running) containers
|
| <kbd>a</kbd> | Toggle display of all (running and non-running) containers |
|
||||||
f | Filter displayed containers (`esc` to clear when open)
|
| <kbd>f</kbd> | Filter displayed containers (`esc` to clear when open) |
|
||||||
H | Toggle ctop header
|
| <kbd>H</kbd> | Toggle ctop header |
|
||||||
h | Open help dialog
|
| <kbd>h</kbd> | Open help dialog |
|
||||||
s | Select container sort field
|
| <kbd>s</kbd> | Select container sort field |
|
||||||
r | Reverse container sort order
|
| <kbd>r</kbd> | Reverse container sort order |
|
||||||
o | Open single view
|
| <kbd>o</kbd> | Open single view |
|
||||||
l | View container logs (`t` to toggle timestamp when open)
|
| <kbd>l</kbd> | View container logs (`t` to toggle timestamp when open) |
|
||||||
S | Save current configuration to file
|
| <kbd>e</kbd> | Exec Shell |
|
||||||
q | Quit ctop
|
| <kbd>c</kbd> | Configure columns |
|
||||||
|
| <kbd>S</kbd> | Save current configuration to file |
|
||||||
|
| <kbd>q</kbd> | Quit ctop |
|
||||||
|
|
||||||
[build]: _docs/build.md
|
[build]: _docs/build.md
|
||||||
[connectors]: _docs/connectors.md
|
[connectors]: _docs/connectors.md
|
||||||
[single_view]: _docs/single.md
|
[single_view]: _docs/single.md
|
||||||
[release]: https://img.shields.io/github/release/bcicen/ctop.svg "ctop"
|
[release]: https://img.shields.io/github/release/bcicen/ctop.svg "ctop"
|
||||||
[homebrew]: https://img.shields.io/homebrew/v/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"
|
||||||
|
|
||||||
|
## Alternatives
|
||||||
|
|
||||||
|
See [Awesome Docker list](https://github.com/veggiemonk/awesome-docker/blob/master/README.md#terminal) for similar tools to work with Docker.
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
# Build
|
# Build
|
||||||
|
|
||||||
To build `ctop` from source, ensure you have [dep](https://github.com/golang/dep) installed and run:
|
To build `ctop` from source, simply clone the repo and run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/bcicen/ctop && \
|
|
||||||
cd $GOPATH/src/github.com/bcicen/ctop && \
|
|
||||||
make build
|
make build
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -16,5 +14,8 @@ make image
|
|||||||
Now you can run your local image:
|
Now you can run your local image:
|
||||||
|
|
||||||
```bash
|
```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
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# connectors
|
# Connectors
|
||||||
|
|
||||||
`ctop` comes with the below native connectors, enabled via the `--connector` option.
|
`ctop` comes with the below native connectors, enabled via the `--connector` option.
|
||||||
|
|
||||||
|
|||||||
@@ -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`)
|
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:
|
||||||
|
|
||||||
|

|
||||||
|
|||||||
BIN
_docs/img/goland_debug.png
Normal file
BIN
_docs/img/goland_debug.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 143 KiB |
BIN
_docs/img/status.png
Normal file
BIN
_docs/img/status.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
30
_docs/status.md
Normal file
30
_docs/status.md
Normal 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>
|
||||||
175
config/columns.go
Normal file
175
config/columns.go
Normal 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
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -19,19 +20,28 @@ type File struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func exportConfig() File {
|
func exportConfig() File {
|
||||||
|
// update columns param from working config
|
||||||
|
Update("columns", ColumnsString())
|
||||||
|
|
||||||
|
lock.RLock()
|
||||||
|
defer lock.RUnlock()
|
||||||
|
|
||||||
c := File{
|
c := File{
|
||||||
Options: make(map[string]string),
|
Options: make(map[string]string),
|
||||||
Toggles: make(map[string]bool),
|
Toggles: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range GlobalParams {
|
for _, p := range GlobalParams {
|
||||||
c.Options[p.Key] = p.Val
|
c.Options[p.Key] = p.Val
|
||||||
}
|
}
|
||||||
for _, sw := range GlobalSwitches {
|
for _, sw := range GlobalSwitches {
|
||||||
c.Toggles[sw.Key] = sw.Val
|
c.Toggles[sw.Key] = sw.Val
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
func Read() error {
|
func Read() error {
|
||||||
var config File
|
var config File
|
||||||
|
|
||||||
@@ -43,13 +53,26 @@ func Read() error {
|
|||||||
if _, err := toml.DecodeFile(path, &config); err != nil {
|
if _, err := toml.DecodeFile(path, &config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range config.Options {
|
for k, v := range config.Options {
|
||||||
Update(k, v)
|
Update(k, v)
|
||||||
}
|
}
|
||||||
for k, v := range config.Toggles {
|
for k, v := range config.Toggles {
|
||||||
UpdateSwitch(k, v)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +82,7 @@ func Write() (path string, err error) {
|
|||||||
return path, err
|
return path, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgdir := basedir(path)
|
cfgdir := filepath.Dir(path)
|
||||||
// create config dir if not exist
|
// create config dir if not exist
|
||||||
if _, err := os.Stat(cfgdir); err != nil {
|
if _, err := os.Stat(cfgdir); err != nil {
|
||||||
err = os.MkdirAll(cfgdir, 0755)
|
err = os.MkdirAll(cfgdir, 0755)
|
||||||
@@ -68,6 +91,13 @@ func Write() (path string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return path, fmt.Errorf("failed to open config for writing: %s", err)
|
return path, fmt.Errorf("failed to open config for writing: %s", err)
|
||||||
@@ -112,8 +142,3 @@ func xdgSupport() bool {
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func basedir(path string) string {
|
|
||||||
parts := strings.Split(path, "/")
|
|
||||||
return strings.Join((parts[0 : len(parts)-1]), "/")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
)
|
)
|
||||||
@@ -10,17 +11,24 @@ import (
|
|||||||
var (
|
var (
|
||||||
GlobalParams []*Param
|
GlobalParams []*Param
|
||||||
GlobalSwitches []*Switch
|
GlobalSwitches []*Switch
|
||||||
|
GlobalColumns []*Column
|
||||||
|
lock sync.RWMutex
|
||||||
log = logging.Init()
|
log = logging.Init()
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
for _, p := range params {
|
for _, p := range defaultParams {
|
||||||
GlobalParams = append(GlobalParams, p)
|
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)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
var params = []*Param{
|
var defaultParams = []*Param{
|
||||||
&Param{
|
&Param{
|
||||||
Key: "filterStr",
|
Key: "filterStr",
|
||||||
Val: "",
|
Val: "",
|
||||||
@@ -12,6 +12,11 @@ var params = []*Param{
|
|||||||
Val: "state",
|
Val: "state",
|
||||||
Label: "Container Sort Field",
|
Label: "Container Sort Field",
|
||||||
},
|
},
|
||||||
|
&Param{
|
||||||
|
Key: "columns",
|
||||||
|
Val: "status,name,id,cpu,mem,net,io,pids,uptime",
|
||||||
|
Label: "Enabled Columns",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Param struct {
|
type Param struct {
|
||||||
@@ -22,6 +27,9 @@ type Param struct {
|
|||||||
|
|
||||||
// Get Param by key
|
// Get Param by key
|
||||||
func Get(k string) *Param {
|
func Get(k string) *Param {
|
||||||
|
lock.RLock()
|
||||||
|
defer lock.RUnlock()
|
||||||
|
|
||||||
for _, p := range GlobalParams {
|
for _, p := range GlobalParams {
|
||||||
if p.Key == k {
|
if p.Key == k {
|
||||||
return p
|
return p
|
||||||
@@ -30,7 +38,7 @@ func Get(k string) *Param {
|
|||||||
return &Param{} // default
|
return &Param{} // default
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Param value by key
|
// GetVal gets Param value by key
|
||||||
func GetVal(k string) string {
|
func GetVal(k string) string {
|
||||||
return Get(k).Val
|
return Get(k).Val
|
||||||
}
|
}
|
||||||
@@ -38,7 +46,10 @@ func GetVal(k string) string {
|
|||||||
// Set param value
|
// Set param value
|
||||||
func Update(k, v string) {
|
func Update(k, v string) {
|
||||||
p := Get(k)
|
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
|
p.Val = v
|
||||||
// log.Errorf("ignoring update for non-existant parameter: %s", k)
|
// log.Errorf("ignoring update for non-existant parameter: %s", k)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
var switches = []*Switch{
|
var defaultSwitches = []*Switch{
|
||||||
&Switch{
|
&Switch{
|
||||||
Key: "sortReversed",
|
Key: "sortReversed",
|
||||||
Val: false,
|
Val: false,
|
||||||
@@ -22,11 +22,6 @@ var switches = []*Switch{
|
|||||||
Val: true,
|
Val: true,
|
||||||
Label: "Enable status header",
|
Label: "Enable status header",
|
||||||
},
|
},
|
||||||
&Switch{
|
|
||||||
Key: "scaleCpu",
|
|
||||||
Val: false,
|
|
||||||
Label: "Show CPU as %% of system total",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Switch struct {
|
type Switch struct {
|
||||||
@@ -35,8 +30,11 @@ type Switch struct {
|
|||||||
Label string
|
Label string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Switch by key
|
// GetSwitch returns Switch by key
|
||||||
func GetSwitch(k string) *Switch {
|
func GetSwitch(k string) *Switch {
|
||||||
|
lock.RLock()
|
||||||
|
defer lock.RUnlock()
|
||||||
|
|
||||||
for _, sw := range GlobalSwitches {
|
for _, sw := range GlobalSwitches {
|
||||||
if sw.Key == k {
|
if sw.Key == k {
|
||||||
return sw
|
return sw
|
||||||
@@ -45,15 +43,19 @@ func GetSwitch(k string) *Switch {
|
|||||||
return &Switch{} // default
|
return &Switch{} // default
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return Switch value by key
|
// GetSwitchVal returns Switch value by key
|
||||||
func GetSwitchVal(k string) bool {
|
func GetSwitchVal(k string) bool {
|
||||||
return GetSwitch(k).Val
|
return GetSwitch(k).Val
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateSwitch(k string, val bool) {
|
func UpdateSwitch(k string, val bool) {
|
||||||
sw := GetSwitch(k)
|
sw := GetSwitch(k)
|
||||||
|
|
||||||
|
lock.Lock()
|
||||||
|
defer lock.Unlock()
|
||||||
|
|
||||||
if sw.Val != val {
|
if sw.Val != val {
|
||||||
log.Noticef("config change: %s: %t -> %t", k, sw.Val, val)
|
log.Noticef("config change [%s]: %t -> %t", k, sw.Val, val)
|
||||||
sw.Val = val
|
sw.Val = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -61,8 +63,11 @@ func UpdateSwitch(k string, val bool) {
|
|||||||
// Toggle a boolean switch
|
// Toggle a boolean switch
|
||||||
func Toggle(k string) {
|
func Toggle(k string) {
|
||||||
sw := GetSwitch(k)
|
sw := GetSwitch(k)
|
||||||
newVal := !sw.Val
|
|
||||||
log.Noticef("config change: %s: %t -> %t", k, sw.Val, newVal)
|
lock.Lock()
|
||||||
sw.Val = newVal
|
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)
|
//log.Errorf("ignoring toggle for non-existant switch: %s", k)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/bcicen/ctop/config"
|
|
||||||
"github.com/bcicen/ctop/models"
|
"github.com/bcicen/ctop/models"
|
||||||
api "github.com/fsouza/go-dockerclient"
|
api "github.com/fsouza/go-dockerclient"
|
||||||
)
|
)
|
||||||
@@ -16,15 +15,13 @@ type Docker struct {
|
|||||||
done chan bool
|
done chan bool
|
||||||
lastCpu float64
|
lastCpu float64
|
||||||
lastSysCpu float64
|
lastSysCpu float64
|
||||||
scaleCpu bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDocker(client *api.Client, id string) *Docker {
|
func NewDocker(client *api.Client, id string) *Docker {
|
||||||
return &Docker{
|
return &Docker{
|
||||||
Metrics: models.Metrics{},
|
Metrics: models.Metrics{},
|
||||||
id: id,
|
id: id,
|
||||||
client: client,
|
client: client,
|
||||||
scaleCpu: config.GetSwitchVal("scaleCpu"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,22 +71,23 @@ func (c *Docker) Logs() LogCollector {
|
|||||||
|
|
||||||
// Stop collector
|
// Stop collector
|
||||||
func (c *Docker) Stop() {
|
func (c *Docker) Stop() {
|
||||||
|
c.running = false
|
||||||
c.done <- true
|
c.done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Docker) ReadCPU(stats *api.Stats) {
|
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)
|
total := float64(stats.CPUStats.CPUUsage.TotalUsage)
|
||||||
system := float64(stats.CPUStats.SystemCPUUsage)
|
system := float64(stats.CPUStats.SystemCPUUsage)
|
||||||
|
|
||||||
cpudiff := total - c.lastCpu
|
cpudiff := total - c.lastCpu
|
||||||
syscpudiff := system - c.lastSysCpu
|
syscpudiff := system - c.lastSysCpu
|
||||||
|
|
||||||
if c.scaleCpu {
|
c.NCpus = ncpus
|
||||||
c.CPUUtil = round((cpudiff / syscpudiff * 100))
|
c.CPUUtil = percent(cpudiff, syscpudiff)
|
||||||
} else {
|
|
||||||
c.CPUUtil = round((cpudiff / syscpudiff * 100) * ncpus)
|
|
||||||
}
|
|
||||||
c.lastCpu = total
|
c.lastCpu = total
|
||||||
c.lastSysCpu = system
|
c.lastSysCpu = system
|
||||||
c.Pids = int(stats.PidsStats.Current)
|
c.Pids = int(stats.PidsStats.Current)
|
||||||
@@ -114,10 +112,10 @@ func (c *Docker) ReadIO(stats *api.Stats) {
|
|||||||
var read, write int64
|
var read, write int64
|
||||||
for _, blk := range stats.BlkioStats.IOServiceBytesRecursive {
|
for _, blk := range stats.BlkioStats.IOServiceBytesRecursive {
|
||||||
if blk.Op == "Read" {
|
if blk.Op == "Read" {
|
||||||
read = int64(blk.Value)
|
read += int64(blk.Value)
|
||||||
}
|
}
|
||||||
if blk.Op == "Write" {
|
if blk.Op == "Write" {
|
||||||
write = int64(blk.Value)
|
write += int64(blk.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.IOBytesRead, c.IOBytesWrite = read, write
|
c.IOBytesRead, c.IOBytesWrite = read, write
|
||||||
|
|||||||
@@ -34,21 +34,28 @@ func (l *DockerLogs) Stream() chan models.Log {
|
|||||||
Context: ctx,
|
Context: ctx,
|
||||||
Container: l.id,
|
Container: l.id,
|
||||||
OutputStream: w,
|
OutputStream: w,
|
||||||
ErrorStream: w,
|
//ErrorStream: w,
|
||||||
Stdout: true,
|
Stdout: true,
|
||||||
Stderr: true,
|
Stderr: true,
|
||||||
Tail: "10",
|
Tail: "20",
|
||||||
Follow: true,
|
Follow: true,
|
||||||
Timestamps: true,
|
Timestamps: true,
|
||||||
|
RawTerminal: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// read io pipe into channel
|
// read io pipe into channel
|
||||||
go func() {
|
go func() {
|
||||||
scanner := bufio.NewScanner(r)
|
scanner := bufio.NewScanner(r)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
parts := strings.Split(scanner.Text(), " ")
|
parts := strings.SplitN(scanner.Text(), " ", 2)
|
||||||
ts := l.parseTime(parts[0])
|
if len(parts) == 0 {
|
||||||
logCh <- models.Log{Timestamp: ts, Message: strings.Join(parts[1:], " ")}
|
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]}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -73,10 +80,26 @@ func (l *DockerLogs) Stream() chan models.Log {
|
|||||||
func (l *DockerLogs) Stop() { l.done <- true }
|
func (l *DockerLogs) Stop() { l.done <- true }
|
||||||
|
|
||||||
func (l *DockerLogs) parseTime(s string) time.Time {
|
func (l *DockerLogs) parseTime(s string) time.Time {
|
||||||
ts, err := time.Parse("2006-01-02T15:04:05.000000000Z", s)
|
ts, err := time.Parse(time.RFC3339Nano, s)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
log.Errorf("failed to parse container log: %s", err)
|
return ts
|
||||||
ts = time.Now()
|
|
||||||
}
|
}
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !release
|
||||||
// +build !release
|
// +build !release
|
||||||
|
|
||||||
package collector
|
package collector
|
||||||
@@ -38,6 +39,7 @@ func (c *Mock) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Mock) Stop() {
|
func (c *Mock) Stop() {
|
||||||
|
c.running = false
|
||||||
c.done = true
|
c.done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
|
//go:build linux
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
linuxproc "github.com/c9s/goprocinfo/linux"
|
linuxproc "github.com/c9s/goprocinfo/linux"
|
||||||
"github.com/opencontainers/runc/libcontainer/system"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var sysMemTotal = getSysMemTotal()
|
var sysMemTotal = getSysMemTotal()
|
||||||
var clockTicksPerSecond = uint64(system.GetClockTicks())
|
|
||||||
|
|
||||||
const nanoSecondsPerSecond = 1e9
|
const (
|
||||||
|
clockTicksPerSecond uint64 = 100
|
||||||
|
nanoSecondsPerSecond = 1e9
|
||||||
|
)
|
||||||
|
|
||||||
func getSysMemTotal() int64 {
|
func getSysMemTotal() int64 {
|
||||||
stat, err := linuxproc.ReadMemInfo("/proc/meminfo")
|
stat, err := linuxproc.ReadMemInfo("/proc/meminfo")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build linux
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package collector
|
package collector
|
||||||
@@ -5,10 +6,11 @@ package collector
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/config"
|
|
||||||
"github.com/bcicen/ctop/models"
|
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
|
"github.com/opencontainers/runc/types"
|
||||||
|
|
||||||
|
"github.com/bcicen/ctop/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Runc collector
|
// Runc collector
|
||||||
@@ -22,7 +24,6 @@ type Runc struct {
|
|||||||
interval int // collection interval, in seconds
|
interval int // collection interval, in seconds
|
||||||
lastCpu float64
|
lastCpu float64
|
||||||
lastSysCpu float64
|
lastSysCpu float64
|
||||||
scaleCpu bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRunc(libc libcontainer.Container) *Runc {
|
func NewRunc(libc libcontainer.Container) *Runc {
|
||||||
@@ -31,7 +32,6 @@ func NewRunc(libc libcontainer.Container) *Runc {
|
|||||||
id: libc.ID(),
|
id: libc.ID(),
|
||||||
libc: libc,
|
libc: libc,
|
||||||
interval: 1,
|
interval: 1,
|
||||||
scaleCpu: config.GetSwitchVal("scaleCpu"),
|
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,7 @@ func (c *Runc) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Runc) Stop() {
|
func (c *Runc) Stop() {
|
||||||
|
c.running = false
|
||||||
c.done = true
|
c.done = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,18 +87,15 @@ func (c *Runc) run() {
|
|||||||
|
|
||||||
func (c *Runc) ReadCPU(stats *cgroups.Stats) {
|
func (c *Runc) ReadCPU(stats *cgroups.Stats) {
|
||||||
u := stats.CpuStats.CpuUsage
|
u := stats.CpuStats.CpuUsage
|
||||||
ncpus := float64(len(u.PercpuUsage))
|
ncpus := uint8(len(u.PercpuUsage))
|
||||||
total := float64(u.TotalUsage)
|
total := float64(u.TotalUsage)
|
||||||
system := float64(getSysCPUUsage())
|
system := float64(getSysCPUUsage())
|
||||||
|
|
||||||
cpudiff := total - c.lastCpu
|
cpudiff := total - c.lastCpu
|
||||||
syscpudiff := system - c.lastSysCpu
|
syscpudiff := system - c.lastSysCpu
|
||||||
|
|
||||||
if c.scaleCpu {
|
c.NCpus = ncpus
|
||||||
c.CPUUtil = round((cpudiff / syscpudiff * 100))
|
c.CPUUtil = percent(cpudiff, syscpudiff)
|
||||||
} else {
|
|
||||||
c.CPUUtil = round((cpudiff / syscpudiff * 100) * ncpus)
|
|
||||||
}
|
|
||||||
c.lastCpu = total
|
c.lastCpu = total
|
||||||
c.lastSysCpu = system
|
c.lastSysCpu = system
|
||||||
c.Pids = int(stats.PidsStats.Current)
|
c.Pids = int(stats.PidsStats.Current)
|
||||||
@@ -112,7 +110,7 @@ func (c *Runc) ReadMem(stats *cgroups.Stats) {
|
|||||||
c.MemPercent = percent(float64(c.MemUsage), float64(c.MemLimit))
|
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
|
var rx, tx int64
|
||||||
for _, network := range interfaces {
|
for _, network := range interfaces {
|
||||||
rx += int64(network.RxBytes)
|
rx += int64(network.RxBytes)
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/op/go-logging"
|
||||||
|
"github.com/hako/durafmt"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/connector/collector"
|
"github.com/bcicen/ctop/connector/collector"
|
||||||
"github.com/bcicen/ctop/connector/manager"
|
"github.com/bcicen/ctop/connector/manager"
|
||||||
@@ -13,53 +17,111 @@ import (
|
|||||||
|
|
||||||
func init() { enabled["docker"] = NewDocker }
|
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 {
|
type Docker struct {
|
||||||
client *api.Client
|
client *api.Client
|
||||||
containers map[string]*container.Container
|
containers map[string]*container.Container
|
||||||
needsRefresh chan string // container IDs requiring refresh
|
needsRefresh chan string // container IDs requiring refresh
|
||||||
|
statuses chan StatusUpdate
|
||||||
|
closed chan struct{}
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDocker() Connector {
|
func NewDocker() (Connector, error) {
|
||||||
// init docker client
|
// init docker client
|
||||||
client, err := api.NewClientFromEnv()
|
client, err := api.NewClientFromEnv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
cm := &Docker{
|
cm := &Docker{
|
||||||
client: client,
|
client: client,
|
||||||
containers: make(map[string]*container.Container),
|
containers: make(map[string]*container.Container),
|
||||||
needsRefresh: make(chan string, 60),
|
needsRefresh: make(chan string, 60),
|
||||||
|
statuses: make(chan StatusUpdate, 60),
|
||||||
|
closed: make(chan struct{}),
|
||||||
lock: sync.RWMutex{},
|
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.Loop()
|
||||||
|
go cm.LoopStatuses()
|
||||||
cm.refreshAll()
|
cm.refreshAll()
|
||||||
go cm.watchEvents()
|
go cm.watchEvents()
|
||||||
return cm
|
return cm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Docker implements Connector
|
||||||
|
func (cm *Docker) Wait() struct{} { return <-cm.closed }
|
||||||
|
|
||||||
// Docker events watcher
|
// Docker events watcher
|
||||||
func (cm *Docker) watchEvents() {
|
func (cm *Docker) watchEvents() {
|
||||||
log.Info("docker event listener starting")
|
log.Info("docker event listener starting")
|
||||||
events := make(chan *api.APIEvents)
|
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 {
|
for e := range events {
|
||||||
if e.Type != "container" {
|
actionName := e.Action
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
actionName := strings.Split(e.Action, ":")[0]
|
|
||||||
|
|
||||||
switch actionName {
|
switch actionName {
|
||||||
case "start", "die", "pause", "unpause", "health_status":
|
// most frequent event is a health checks
|
||||||
log.Debugf("handling docker event: action=%s id=%s", e.Action, e.ID)
|
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
|
cm.needsRefresh <- e.ID
|
||||||
case "destroy":
|
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)
|
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 {
|
func portsFormat(ports map[api.Port][]api.PortBinding) string {
|
||||||
@@ -80,6 +142,23 @@ func portsFormat(ports map[api.Port][]api.PortBinding) string {
|
|||||||
return strings.Join(append(exposed, published...), "\n")
|
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 {
|
func ipsFormat(networks map[string]api.ContainerNetwork) string {
|
||||||
var ips []string
|
var ips []string
|
||||||
|
|
||||||
@@ -92,9 +171,12 @@ func ipsFormat(networks map[string]api.ContainerNetwork) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cm *Docker) refresh(c *container.Container) {
|
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
|
// remove container if no longer exists
|
||||||
if insp == nil {
|
if !found {
|
||||||
cm.delByID(c.Id)
|
cm.delByID(c.Id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -102,22 +184,37 @@ func (cm *Docker) refresh(c *container.Container) {
|
|||||||
c.SetMeta("image", insp.Config.Image)
|
c.SetMeta("image", insp.Config.Image)
|
||||||
c.SetMeta("IPs", ipsFormat(insp.NetworkSettings.Networks))
|
c.SetMeta("IPs", ipsFormat(insp.NetworkSettings.Networks))
|
||||||
c.SetMeta("ports", portsFormat(insp.NetworkSettings.Ports))
|
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)
|
||||||
c.SetMeta("health", insp.State.Health.Status)
|
if webPort != "" {
|
||||||
for _, env := range insp.Config.Env {
|
c.SetMeta("Web Port", webPort)
|
||||||
c.SetMeta("[ENV-VAR]", env)
|
|
||||||
}
|
}
|
||||||
|
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)
|
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)
|
c, err := cm.client.InspectContainer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*api.NoSuchContainer); !ok {
|
if _, notFound := err.(*api.NoSuchContainer); notFound {
|
||||||
log.Errorf(err.Error())
|
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
|
// Mark all container IDs for refresh
|
||||||
@@ -125,7 +222,8 @@ func (cm *Docker) refreshAll() {
|
|||||||
opts := api.ListContainersOptions{All: true}
|
opts := api.ListContainersOptions{All: true}
|
||||||
allContainers, err := cm.client.ListContainers(opts)
|
allContainers, err := cm.client.ListContainers(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Errorf("%s (%T)", err.Error(), err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, i := range allContainers {
|
for _, i := range allContainers {
|
||||||
@@ -137,13 +235,36 @@ func (cm *Docker) refreshAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cm *Docker) Loop() {
|
func (cm *Docker) Loop() {
|
||||||
for id := range cm.needsRefresh {
|
for {
|
||||||
c := cm.MustGet(id)
|
select {
|
||||||
cm.refresh(c)
|
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 {
|
func (cm *Docker) MustGet(id string) *container.Container {
|
||||||
c, ok := cm.Get(id)
|
c, ok := cm.Get(id)
|
||||||
// append container struct for new containers
|
// append container struct for new containers
|
||||||
@@ -161,7 +282,7 @@ func (cm *Docker) MustGet(id string) *container.Container {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a single container, by ID
|
// Docker implements Connector
|
||||||
func (cm *Docker) Get(id string) (*container.Container, bool) {
|
func (cm *Docker) Get(id string) (*container.Container, bool) {
|
||||||
cm.lock.Lock()
|
cm.lock.Lock()
|
||||||
c, ok := cm.containers[id]
|
c, ok := cm.containers[id]
|
||||||
@@ -177,7 +298,7 @@ func (cm *Docker) delByID(id string) {
|
|||||||
log.Infof("removed dead container: %s", id)
|
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) {
|
func (cm *Docker) All() (containers container.Containers) {
|
||||||
cm.lock.Lock()
|
cm.lock.Lock()
|
||||||
for _, c := range cm.containers {
|
for _, c := range cm.containers {
|
||||||
@@ -192,5 +313,5 @@ func (cm *Docker) All() (containers container.Containers) {
|
|||||||
|
|
||||||
// use primary container name
|
// use primary container name
|
||||||
func shortName(name string) string {
|
func shortName(name string) string {
|
||||||
return strings.Replace(name, "/", "", 1)
|
return strings.TrimPrefix(name, "/")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package connector
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/container"
|
"github.com/bcicen/ctop/container"
|
||||||
"github.com/bcicen/ctop/logging"
|
"github.com/bcicen/ctop/logging"
|
||||||
@@ -10,10 +12,80 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
log = logging.Init()
|
log = logging.Init()
|
||||||
enabled = make(map[string]func() Connector)
|
enabled = make(map[string]ConnectorFn)
|
||||||
)
|
)
|
||||||
|
|
||||||
// return names for all enabled connectors on the current platform
|
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) {
|
func Enabled() (a []string) {
|
||||||
for k, _ := range enabled {
|
for k, _ := range enabled {
|
||||||
a = append(a, k)
|
a = append(a, k)
|
||||||
@@ -22,14 +94,11 @@ func Enabled() (a []string) {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
func ByName(s string) (Connector, error) {
|
// 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 {
|
if cfn, ok := enabled[s]; ok {
|
||||||
return cfn(), nil
|
return NewConnectorSuper(cfn), nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
|
return nil, fmt.Errorf("invalid connector type \"%s\"", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Connector interface {
|
|
||||||
All() container.Containers
|
|
||||||
Get(string) (*container.Container, bool)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,6 +3,9 @@ package manager
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
api "github.com/fsouza/go-dockerclient"
|
api "github.com/fsouza/go-dockerclient"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
@@ -17,6 +20,88 @@ func NewDocker(client *api.Client, id string) *Docker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
func (dc *Docker) Start() error {
|
||||||
c, err := dc.client.InspectContainer(dc.id)
|
c, err := dc.client.InspectContainer(dc.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package manager
|
package manager
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var ActionNotImplErr = errors.New("action not implemented")
|
||||||
|
|
||||||
type Manager interface {
|
type Manager interface {
|
||||||
Start() error
|
Start() error
|
||||||
Stop() error
|
Stop() error
|
||||||
@@ -7,4 +11,5 @@ type Manager interface {
|
|||||||
Pause() error
|
Pause() error
|
||||||
Unpause() error
|
Unpause() error
|
||||||
Restart() error
|
Restart() error
|
||||||
|
Exec(cmd []string) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,25 +7,29 @@ func NewMock() *Mock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mock) Start() error {
|
func (m *Mock) Start() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mock) Stop() error {
|
func (m *Mock) Stop() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mock) Remove() error {
|
func (m *Mock) Remove() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mock) Pause() error {
|
func (m *Mock) Pause() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mock) Unpause() error {
|
func (m *Mock) Unpause() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mock) Restart() error {
|
func (m *Mock) Restart() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Mock) Exec(cmd []string) error {
|
||||||
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,25 +7,29 @@ func NewRunc() *Runc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Runc) Start() error {
|
func (rc *Runc) Start() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Runc) Stop() error {
|
func (rc *Runc) Stop() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Runc) Remove() error {
|
func (rc *Runc) Remove() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Runc) Pause() error {
|
func (rc *Runc) Pause() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Runc) Unpause() error {
|
func (rc *Runc) Unpause() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *Runc) Restart() error {
|
func (rc *Runc) Restart() error {
|
||||||
return nil
|
return ActionNotImplErr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *Runc) Exec(cmd []string) error {
|
||||||
|
return ActionNotImplErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//go:build !release
|
||||||
// +build !release
|
// +build !release
|
||||||
|
|
||||||
package connector
|
package connector
|
||||||
@@ -20,11 +21,11 @@ type Mock struct {
|
|||||||
containers container.Containers
|
containers container.Containers
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMock() Connector {
|
func NewMock() (Connector, error) {
|
||||||
cs := &Mock{}
|
cs := &Mock{}
|
||||||
go cs.Init()
|
go cs.Init()
|
||||||
go cs.Loop()
|
go cs.Loop()
|
||||||
return cs
|
return cs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Mock containers
|
// Create Mock containers
|
||||||
@@ -32,21 +33,46 @@ func (cs *Mock) Init() {
|
|||||||
rand.Seed(int64(time.Now().Nanosecond()))
|
rand.Seed(int64(time.Now().Nanosecond()))
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
cs.makeContainer(3)
|
cs.makeContainer(3, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < 16; i++ {
|
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)
|
collector := collector.NewMock(aggression)
|
||||||
manager := manager.NewMock()
|
manager := manager.NewMock()
|
||||||
c := container.New(makeID(), collector, manager)
|
c := container.New(makeID(), collector, manager)
|
||||||
c.SetMeta("name", makeName())
|
c.SetMeta("name", makeName())
|
||||||
c.SetState(makeState())
|
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)
|
cs.containers = append(cs.containers, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +99,7 @@ func (cs *Mock) Get(id string) (*container.Container, bool) {
|
|||||||
return nil, false
|
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 {
|
func (cs *Mock) All() container.Containers {
|
||||||
cs.containers.Sort()
|
cs.containers.Sort()
|
||||||
cs.containers.Filter()
|
cs.containers.Filter()
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
//go:build linux
|
||||||
// +build linux
|
// +build linux
|
||||||
|
|
||||||
package connector
|
package connector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -14,7 +15,6 @@ import (
|
|||||||
"github.com/bcicen/ctop/connector/manager"
|
"github.com/bcicen/ctop/connector/manager"
|
||||||
"github.com/bcicen/ctop/container"
|
"github.com/bcicen/ctop/container"
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { enabled["runc"] = NewRunc }
|
func init() { enabled["runc"] = NewRunc }
|
||||||
@@ -54,35 +54,44 @@ type Runc struct {
|
|||||||
factory libcontainer.Factory
|
factory libcontainer.Factory
|
||||||
containers map[string]*container.Container
|
containers map[string]*container.Container
|
||||||
libContainers map[string]libcontainer.Container
|
libContainers map[string]libcontainer.Container
|
||||||
|
closed chan struct{}
|
||||||
needsRefresh chan string // container IDs requiring refresh
|
needsRefresh chan string // container IDs requiring refresh
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRunc() Connector {
|
func NewRunc() (Connector, error) {
|
||||||
opts, err := NewRuncOpts()
|
opts, err := NewRuncOpts()
|
||||||
runcFailOnErr(err)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
factory, err := getFactory(opts)
|
factory, err := libcontainer.New(opts.root)
|
||||||
runcFailOnErr(err)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
cm := &Runc{
|
cm := &Runc{
|
||||||
opts: opts,
|
opts: opts,
|
||||||
factory: factory,
|
factory: factory,
|
||||||
containers: make(map[string]*container.Container),
|
containers: make(map[string]*container.Container),
|
||||||
libContainers: make(map[string]libcontainer.Container),
|
libContainers: make(map[string]libcontainer.Container),
|
||||||
needsRefresh: make(chan string, 60),
|
closed: make(chan struct{}),
|
||||||
lock: sync.RWMutex{},
|
lock: sync.RWMutex{},
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
cm.refreshAll()
|
select {
|
||||||
time.Sleep(5 * time.Second)
|
case <-cm.closed:
|
||||||
|
return
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
cm.refreshAll()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go cm.Loop()
|
go cm.Loop()
|
||||||
|
|
||||||
return cm
|
return cm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *Runc) GetLibc(id string) libcontainer.Container {
|
func (cm *Runc) GetLibc(id string) libcontainer.Container {
|
||||||
@@ -95,7 +104,7 @@ func (cm *Runc) GetLibc(id string) libcontainer.Container {
|
|||||||
libc, err := cm.factory.Load(id)
|
libc, err := cm.factory.Load(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// remove container if no longer exists
|
// 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)
|
cm.delByID(id)
|
||||||
} else {
|
} else {
|
||||||
log.Warningf("failed to read container: %s\n", err)
|
log.Warningf("failed to read container: %s\n", err)
|
||||||
@@ -141,7 +150,11 @@ func (cm *Runc) refresh(id string) {
|
|||||||
// Read runc root, creating any new containers
|
// Read runc root, creating any new containers
|
||||||
func (cm *Runc) refreshAll() {
|
func (cm *Runc) refreshAll() {
|
||||||
list, err := ioutil.ReadDir(cm.opts.root)
|
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 {
|
for _, i := range list {
|
||||||
if i.IsDir() {
|
if i.IsDir() {
|
||||||
@@ -156,7 +169,7 @@ func (cm *Runc) refreshAll() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// queue all existing containers for refresh
|
// queue all existing containers for refresh
|
||||||
for id, _ := range cm.containers {
|
for id := range cm.containers {
|
||||||
cm.needsRefresh <- id
|
cm.needsRefresh <- id
|
||||||
}
|
}
|
||||||
log.Debugf("queued %d containers for refresh", len(cm.containers))
|
log.Debugf("queued %d containers for refresh", len(cm.containers))
|
||||||
@@ -168,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 {
|
func (cm *Runc) MustGet(id string) *container.Container {
|
||||||
c, ok := cm.Get(id)
|
c, ok := cm.Get(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -199,14 +212,6 @@ func (cm *Runc) MustGet(id string) *container.Container {
|
|||||||
return c
|
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
|
// Remove containers by ID
|
||||||
func (cm *Runc) delByID(id string) {
|
func (cm *Runc) delByID(id string) {
|
||||||
cm.lock.Lock()
|
cm.lock.Lock()
|
||||||
@@ -216,7 +221,18 @@ func (cm *Runc) delByID(id string) {
|
|||||||
log.Infof("removed dead container: %s", id)
|
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) {
|
func (cm *Runc) All() (containers container.Containers) {
|
||||||
cm.lock.Lock()
|
cm.lock.Lock()
|
||||||
for _, c := range cm.containers {
|
for _, c := range cm.containers {
|
||||||
@@ -227,21 +243,3 @@ func (cm *Runc) All() (containers container.Containers) {
|
|||||||
cm.lock.Unlock()
|
cm.lock.Unlock()
|
||||||
return containers
|
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))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ const (
|
|||||||
type Container struct {
|
type Container struct {
|
||||||
models.Metrics
|
models.Metrics
|
||||||
Id string
|
Id string
|
||||||
Meta map[string]string
|
Meta models.Meta
|
||||||
Widgets *compact.Compact
|
Widgets *compact.CompactRow
|
||||||
Display bool // display this container in compact view
|
Display bool // display this container in compact view
|
||||||
updater cwidgets.WidgetUpdater
|
updater cwidgets.WidgetUpdater
|
||||||
collector collector.Collector
|
collector collector.Collector
|
||||||
@@ -30,11 +30,15 @@ type Container struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(id string, collector collector.Collector, manager manager.Manager) *Container {
|
func New(id string, collector collector.Collector, manager manager.Manager) *Container {
|
||||||
widgets := compact.NewCompact(id)
|
widgets := compact.NewCompactRow()
|
||||||
|
shortID := id
|
||||||
|
if len(shortID) > 12 {
|
||||||
|
shortID = shortID[0:12]
|
||||||
|
}
|
||||||
return &Container{
|
return &Container{
|
||||||
Metrics: models.NewMetrics(),
|
Metrics: models.NewMetrics(),
|
||||||
Id: id,
|
Id: id,
|
||||||
Meta: make(map[string]string),
|
Meta: models.NewMeta("id", shortID),
|
||||||
Widgets: widgets,
|
Widgets: widgets,
|
||||||
updater: widgets,
|
updater: widgets,
|
||||||
collector: collector,
|
collector: collector,
|
||||||
@@ -42,23 +46,24 @@ func New(id string, collector collector.Collector, manager manager.Manager) *Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Container) RecreateWidgets() {
|
||||||
|
c.SetUpdater(cwidgets.NullWidgetUpdater{})
|
||||||
|
c.Widgets = compact.NewCompactRow()
|
||||||
|
c.SetUpdater(c.Widgets)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Container) SetUpdater(u cwidgets.WidgetUpdater) {
|
func (c *Container) SetUpdater(u cwidgets.WidgetUpdater) {
|
||||||
c.updater = u
|
c.updater = u
|
||||||
for k, v := range c.Meta {
|
c.updater.SetMeta(c.Meta)
|
||||||
c.updater.SetMeta(k, v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) SetMeta(k, v string) {
|
func (c *Container) SetMeta(k, v string) {
|
||||||
c.Meta[k] = v
|
c.Meta[k] = v
|
||||||
c.updater.SetMeta(k, v)
|
c.updater.SetMeta(c.Meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) GetMeta(k string) string {
|
func (c *Container) GetMeta(k string) string {
|
||||||
if v, ok := c.Meta[k]; ok {
|
return c.Meta.Get(k)
|
||||||
return v
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) SetState(s string) {
|
func (c *Container) SetState(s string) {
|
||||||
@@ -74,7 +79,7 @@ func (c *Container) SetState(s string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return container log collector
|
// Logs returns container log collector
|
||||||
func (c *Container) Logs() collector.LogCollector {
|
func (c *Container) Logs() collector.LogCollector {
|
||||||
return c.collector.Logs()
|
return c.collector.Logs()
|
||||||
}
|
}
|
||||||
@@ -153,3 +158,7 @@ func (c *Container) Restart() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Container) Exec(cmd []string) error {
|
||||||
|
return c.manager.Exec(cmd)
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,6 +79,15 @@ var Sorters = map[string]sortMethod{
|
|||||||
}
|
}
|
||||||
return stateMap[c1state] > stateMap[c2state]
|
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) {
|
func SortFields() (fields []string) {
|
||||||
|
|||||||
39
cursor.go
39
cursor.go
@@ -11,7 +11,7 @@ import (
|
|||||||
type GridCursor struct {
|
type GridCursor struct {
|
||||||
selectedID string // id of currently selected container
|
selectedID string // id of currently selected container
|
||||||
filtered container.Containers
|
filtered container.Containers
|
||||||
cSource connector.Connector
|
cSuper *connector.ConnectorSuper
|
||||||
isScrolling bool // toggled when actively scrolling
|
isScrolling bool // toggled when actively scrolling
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,14 +25,20 @@ func (gc *GridCursor) Selected() *container.Container {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh containers from source
|
// Refresh containers from source, returning whether the quantity of
|
||||||
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
// containers has changed and any error
|
||||||
|
func (gc *GridCursor) RefreshContainers() (bool, error) {
|
||||||
oldLen := gc.Len()
|
oldLen := gc.Len()
|
||||||
|
|
||||||
// Containers filtered by display bool
|
|
||||||
gc.filtered = container.Containers{}
|
gc.filtered = container.Containers{}
|
||||||
|
|
||||||
|
cSource, err := gc.cSuper.Get()
|
||||||
|
if err != nil {
|
||||||
|
return true, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter Containers by display bool
|
||||||
var cursorVisible bool
|
var cursorVisible bool
|
||||||
for _, c := range gc.cSource.All() {
|
for _, c := range cSource.All() {
|
||||||
if c.Display {
|
if c.Display {
|
||||||
if c.Id == gc.selectedID {
|
if c.Id == gc.selectedID {
|
||||||
cursorVisible = true
|
cursorVisible = true
|
||||||
@@ -41,22 +47,21 @@ func (gc *GridCursor) RefreshContainers() (lenChanged bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldLen != gc.Len() {
|
if !cursorVisible || gc.selectedID == "" {
|
||||||
lenChanged = true
|
gc.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cursorVisible {
|
return oldLen != gc.Len(), nil
|
||||||
gc.Reset()
|
|
||||||
}
|
|
||||||
if gc.selectedID == "" {
|
|
||||||
gc.Reset()
|
|
||||||
}
|
|
||||||
return lenChanged
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set an initial cursor position, if possible
|
// Set an initial cursor position, if possible
|
||||||
func (gc *GridCursor) Reset() {
|
func (gc *GridCursor) Reset() {
|
||||||
for _, c := range gc.cSource.All() {
|
cSource, err := gc.cSuper.Get()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cSource.All() {
|
||||||
c.Widgets.UnHighlight()
|
c.Widgets.UnHighlight()
|
||||||
}
|
}
|
||||||
if gc.Len() > 0 {
|
if gc.Len() > 0 {
|
||||||
@@ -65,7 +70,7 @@ func (gc *GridCursor) Reset() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return current cursor index
|
// Idx returns current cursor index
|
||||||
func (gc *GridCursor) Idx() int {
|
func (gc *GridCursor) Idx() int {
|
||||||
for n, c := range gc.filtered {
|
for n, c := range gc.filtered {
|
||||||
if c.Id == gc.selectedID {
|
if c.Id == gc.selectedID {
|
||||||
|
|||||||
55
cwidgets/compact/column.go
Normal file
55
cwidgets/compact/column.go
Normal 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)
|
||||||
|
}
|
||||||
@@ -1,21 +1,68 @@
|
|||||||
package compact
|
package compact
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/bcicen/ctop/cwidgets"
|
||||||
|
"github.com/bcicen/ctop/models"
|
||||||
|
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GaugeCol struct {
|
type CPUCol struct {
|
||||||
*ui.Gauge
|
*GaugeCol
|
||||||
|
scaleCpu bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGaugeCol() *GaugeCol {
|
func NewCPUCol() CompactCol {
|
||||||
g := ui.NewGauge()
|
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.Height = 1
|
||||||
g.Border = false
|
g.Border = false
|
||||||
g.Percent = 0
|
|
||||||
g.PaddingBottom = 0
|
g.PaddingBottom = 0
|
||||||
g.Label = "-"
|
g.Reset()
|
||||||
return &GaugeCol{g}
|
return g
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *GaugeCol) Reset() {
|
func (w *GaugeCol) Reset() {
|
||||||
@@ -23,22 +70,41 @@ func (w *GaugeCol) Reset() {
|
|||||||
w.Percent = 0
|
w.Percent = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
func (w *GaugeCol) Highlight() {
|
||||||
w.Bg = ui.ThemeAttr("par.text.fg")
|
w.Bg = ui.ThemeAttr("par.text.fg")
|
||||||
w.PercentColor = ui.ThemeAttr("par.text.hi")
|
w.PercentColor = ui.ThemeAttr("par.text.hi")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GaugeCol implements CompactCol
|
||||||
func (w *GaugeCol) UnHighlight() {
|
func (w *GaugeCol) UnHighlight() {
|
||||||
w.Bg = ui.ThemeAttr("par.text.bg")
|
w.Bg = ui.ThemeAttr("par.text.bg")
|
||||||
w.PercentColor = ui.ThemeAttr("par.text.bg")
|
w.PercentColor = ui.ThemeAttr("par.text.bg")
|
||||||
}
|
}
|
||||||
|
|
||||||
func colorScale(n int) ui.Attribute {
|
func colorScale(n int) ui.Attribute {
|
||||||
if n > 70 {
|
if n <= 70 {
|
||||||
return ui.ThemeAttr("status.danger")
|
return ui.ThemeAttr("status.ok")
|
||||||
}
|
}
|
||||||
if n > 30 {
|
if n <= 90 {
|
||||||
return ui.ThemeAttr("status.warn")
|
return ui.ThemeAttr("status.warn")
|
||||||
}
|
}
|
||||||
return ui.ThemeAttr("status.ok")
|
return ui.ThemeAttr("status.danger")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import (
|
|||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var header *CompactHeader
|
|
||||||
|
|
||||||
type CompactGrid struct {
|
type CompactGrid struct {
|
||||||
ui.GridBufferer
|
ui.GridBufferer
|
||||||
Rows []ui.GridBufferer
|
header *CompactHeader
|
||||||
|
cols []CompactCol // reference columns
|
||||||
|
Rows []RowBufferer
|
||||||
X, Y int
|
X, Y int
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
@@ -16,8 +16,9 @@ type CompactGrid struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewCompactGrid() *CompactGrid {
|
func NewCompactGrid() *CompactGrid {
|
||||||
header = NewCompactHeader() // init column header
|
cg := &CompactGrid{header: NewCompactHeader()}
|
||||||
return &CompactGrid{}
|
cg.rebuildHeader()
|
||||||
|
return cg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cg *CompactGrid) Align() {
|
func (cg *CompactGrid) Align() {
|
||||||
@@ -28,22 +29,51 @@ func (cg *CompactGrid) Align() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update row ypos, width recursively
|
// update row ypos, width recursively
|
||||||
|
colWidths := cg.calcWidths()
|
||||||
for _, r := range cg.pageRows() {
|
for _, r := range cg.pageRows() {
|
||||||
r.SetY(y)
|
r.SetY(y)
|
||||||
y += r.GetHeight()
|
y += r.GetHeight()
|
||||||
r.SetWidth(cg.Width)
|
r.SetWidths(cg.Width, colWidths)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cg *CompactGrid) Clear() { cg.Rows = []ui.GridBufferer{} }
|
func (cg *CompactGrid) Clear() {
|
||||||
func (cg *CompactGrid) GetHeight() int { return len(cg.Rows) + header.Height }
|
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) SetX(x int) { cg.X = x }
|
||||||
func (cg *CompactGrid) SetY(y int) { cg.Y = y }
|
func (cg *CompactGrid) SetY(y int) { cg.Y = y }
|
||||||
func (cg *CompactGrid) SetWidth(w int) { cg.Width = w }
|
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) {
|
// calculate and return per-column width
|
||||||
rows = append(rows, header)
|
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:]...)
|
rows = append(rows, cg.Rows[cg.Offset:]...)
|
||||||
return rows
|
return rows
|
||||||
}
|
}
|
||||||
@@ -56,6 +86,14 @@ func (cg *CompactGrid) Buffer() ui.Buffer {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cg *CompactGrid) AddRows(rows ...ui.GridBufferer) {
|
func (cg *CompactGrid) AddRows(rows ...RowBufferer) {
|
||||||
cg.Rows = append(cg.Rows, rows...)
|
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())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,63 +8,59 @@ type CompactHeader struct {
|
|||||||
X, Y int
|
X, Y int
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
|
cols []CompactCol
|
||||||
|
widths []int
|
||||||
pars []*ui.Par
|
pars []*ui.Par
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCompactHeader() *CompactHeader {
|
func NewCompactHeader() *CompactHeader {
|
||||||
fields := []string{"", "NAME", "CID", "CPU", "MEM", "NET RX/TX", "IO R/W", "PIDS"}
|
return &CompactHeader{
|
||||||
ch := &CompactHeader{}
|
X: rowPadding,
|
||||||
ch.Height = 2
|
Height: 2,
|
||||||
for _, f := range fields {
|
|
||||||
ch.addFieldPar(f)
|
|
||||||
}
|
}
|
||||||
return ch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *CompactHeader) GetHeight() int {
|
func (row *CompactHeader) GetHeight() int {
|
||||||
return ch.Height
|
return row.Height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *CompactHeader) SetWidth(w int) {
|
func (row *CompactHeader) SetWidths(totalWidth int, widths []int) {
|
||||||
x := ch.X
|
x := row.X
|
||||||
autoWidth := calcWidth(w)
|
|
||||||
for n, col := range ch.pars {
|
for n, w := range row.pars {
|
||||||
// set column to static width
|
w.SetX(x)
|
||||||
if colWidths[n] != 0 {
|
w.SetWidth(widths[n])
|
||||||
col.SetX(x)
|
x += widths[n] + colSpacing
|
||||||
col.SetWidth(colWidths[n])
|
|
||||||
x += colWidths[n]
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
col.SetX(x)
|
|
||||||
col.SetWidth(autoWidth)
|
|
||||||
x += autoWidth + colSpacing
|
|
||||||
}
|
}
|
||||||
ch.Width = w
|
row.Width = totalWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *CompactHeader) SetX(x int) {
|
func (row *CompactHeader) SetX(x int) {
|
||||||
ch.X = x
|
row.X = x
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *CompactHeader) SetY(y int) {
|
func (row *CompactHeader) SetY(y int) {
|
||||||
for _, p := range ch.pars {
|
for _, p := range row.pars {
|
||||||
p.SetY(y)
|
p.SetY(y)
|
||||||
}
|
}
|
||||||
ch.Y = y
|
row.Y = y
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *CompactHeader) Buffer() ui.Buffer {
|
func (row *CompactHeader) Buffer() ui.Buffer {
|
||||||
buf := ui.NewBuffer()
|
buf := ui.NewBuffer()
|
||||||
for _, p := range ch.pars {
|
for _, p := range row.pars {
|
||||||
buf.Merge(p.Buffer())
|
buf.Merge(p.Buffer())
|
||||||
}
|
}
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ch *CompactHeader) addFieldPar(s string) {
|
func (row *CompactHeader) clearFieldPars() {
|
||||||
p := ui.NewPar(s)
|
row.pars = []*ui.Par{}
|
||||||
p.Height = ch.Height
|
}
|
||||||
p.Border = false
|
|
||||||
ch.pars = append(ch.pars, p)
|
func (row *CompactHeader) addFieldPar(s string) {
|
||||||
|
p := ui.NewPar(s)
|
||||||
|
p.Height = row.Height
|
||||||
|
p.Border = false
|
||||||
|
row.pars = append(row.pars, p)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,195 +0,0 @@
|
|||||||
package compact
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/bcicen/ctop/config"
|
|
||||||
"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
|
|
||||||
Mem *GaugeCol
|
|
||||||
Net *TextCol
|
|
||||||
IO *TextCol
|
|
||||||
Pids *TextCol
|
|
||||||
Bg *RowBg
|
|
||||||
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(),
|
|
||||||
Mem: NewGaugeCol(),
|
|
||||||
Net: NewTextCol("-"),
|
|
||||||
IO: NewTextCol("-"),
|
|
||||||
Pids: NewTextCol("-"),
|
|
||||||
Bg: NewRowBg(),
|
|
||||||
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)
|
|
||||||
case "health":
|
|
||||||
row.Status.SetHealth(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.Mem.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
|
|
||||||
}
|
|
||||||
|
|
||||||
row.Bg.Y = y
|
|
||||||
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
|
|
||||||
|
|
||||||
row.Bg.SetX(x + colWidths[0] + 1)
|
|
||||||
row.Bg.SetWidth(width)
|
|
||||||
|
|
||||||
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.Bg.Buffer())
|
|
||||||
buf.Merge(row.Status.Buffer())
|
|
||||||
buf.Merge(row.Name.Buffer())
|
|
||||||
buf.Merge(row.Cid.Buffer())
|
|
||||||
buf.Merge(row.Cpu.Buffer())
|
|
||||||
buf.Merge(row.Mem.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.Mem,
|
|
||||||
row.Net,
|
|
||||||
row.IO,
|
|
||||||
row.Pids,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (row *Compact) Highlight() {
|
|
||||||
row.Name.Highlight()
|
|
||||||
if config.GetSwitchVal("fullRowCursor") {
|
|
||||||
row.Bg.Highlight()
|
|
||||||
row.Cid.Highlight()
|
|
||||||
row.Cpu.Highlight()
|
|
||||||
row.Mem.Highlight()
|
|
||||||
row.Net.Highlight()
|
|
||||||
row.IO.Highlight()
|
|
||||||
row.Pids.Highlight()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (row *Compact) UnHighlight() {
|
|
||||||
row.Name.UnHighlight()
|
|
||||||
if config.GetSwitchVal("fullRowCursor") {
|
|
||||||
row.Bg.UnHighlight()
|
|
||||||
row.Cid.UnHighlight()
|
|
||||||
row.Cpu.UnHighlight()
|
|
||||||
row.Mem.UnHighlight()
|
|
||||||
row.Net.UnHighlight()
|
|
||||||
row.IO.UnHighlight()
|
|
||||||
row.Pids.UnHighlight()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type RowBg struct {
|
|
||||||
*ui.Par
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRowBg() *RowBg {
|
|
||||||
bg := ui.NewPar("")
|
|
||||||
bg.Height = 1
|
|
||||||
bg.Border = false
|
|
||||||
bg.Bg = ui.ThemeAttr("par.text.bg")
|
|
||||||
return &RowBg{bg}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *RowBg) Highlight() { w.Bg = ui.ThemeAttr("par.text.fg") }
|
|
||||||
func (w *RowBg) UnHighlight() { w.Bg = ui.ThemeAttr("par.text.bg") }
|
|
||||||
129
cwidgets/compact/row.go
Normal file
129
cwidgets/compact/row.go
Normal 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") }
|
||||||
@@ -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 := 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.Mem.Label = fmt.Sprintf("%s / %s", cwidgets.ByteFormat(val), cwidgets.ByteFormat(limit))
|
|
||||||
if percent < 5 {
|
|
||||||
percent = 5
|
|
||||||
row.Mem.BarColor = ui.ColorBlack
|
|
||||||
} else {
|
|
||||||
row.Mem.BarColor = ui.ThemeAttr("gauge.bar.bg")
|
|
||||||
}
|
|
||||||
row.Mem.Percent = percent
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,9 @@
|
|||||||
package compact
|
package compact
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ui "github.com/gizak/termui"
|
"github.com/bcicen/ctop/models"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
ui "github.com/gizak/termui"
|
||||||
mark = string('\u25C9')
|
|
||||||
healthMark = string('\u207A')
|
|
||||||
vBar = string('\u25AE') + string('\u25AE')
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Status indicator
|
// Status indicator
|
||||||
@@ -17,67 +13,82 @@ type Status struct {
|
|||||||
health []ui.Cell
|
health []ui.Cell
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStatus() *Status {
|
func NewStatus() CompactCol {
|
||||||
s := &Status{Block: ui.NewBlock()}
|
s := &Status{
|
||||||
|
Block: ui.NewBlock(),
|
||||||
|
status: []ui.Cell{{Ch: ' '}},
|
||||||
|
health: []ui.Cell{{Ch: ' '}},
|
||||||
|
}
|
||||||
s.Height = 1
|
s.Height = 1
|
||||||
s.Border = false
|
s.Border = false
|
||||||
s.Set("")
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Status) Buffer() ui.Buffer {
|
func (s *Status) Buffer() ui.Buffer {
|
||||||
buf := s.Block.Buffer()
|
buf := s.Block.Buffer()
|
||||||
x := 0
|
buf.Set(s.InnerX(), s.InnerY(), s.health[0])
|
||||||
for _, c := range s.status {
|
buf.Set(s.InnerX()+2, s.InnerY(), s.status[0])
|
||||||
buf.Set(s.InnerX()+x, s.InnerY(), c)
|
|
||||||
x += c.Width()
|
|
||||||
}
|
|
||||||
for _, c := range s.health {
|
|
||||||
buf.Set(s.InnerX()+x, s.InnerY(), c)
|
|
||||||
x += c.Width()
|
|
||||||
}
|
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Status) Set(val string) {
|
func (s *Status) SetMeta(m models.Meta) {
|
||||||
// defaults
|
s.setState(m.Get("state"))
|
||||||
text := mark
|
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
|
color := ui.ColorDefault
|
||||||
|
var mark string
|
||||||
|
|
||||||
switch val {
|
switch val {
|
||||||
|
case "":
|
||||||
|
return
|
||||||
|
case "created":
|
||||||
|
mark = "◉"
|
||||||
case "running":
|
case "running":
|
||||||
|
mark = "⏵"
|
||||||
color = ui.ThemeAttr("status.ok")
|
color = ui.ThemeAttr("status.ok")
|
||||||
case "exited":
|
case "exited":
|
||||||
|
mark = "⏹"
|
||||||
color = ui.ThemeAttr("status.danger")
|
color = ui.ThemeAttr("status.danger")
|
||||||
case "paused":
|
case "paused":
|
||||||
text = vBar
|
mark = "⏸"
|
||||||
|
default:
|
||||||
|
mark = " "
|
||||||
|
log.Warningf("unknown status string: \"%v\"", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cells []ui.Cell
|
s.status = ui.TextCells(mark, color, ui.ColorDefault)
|
||||||
for _, ch := range text {
|
|
||||||
cells = append(cells, ui.Cell{Ch: ch, Fg: color})
|
|
||||||
}
|
|
||||||
s.status = cells
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Status) SetHealth(val string) {
|
func (s *Status) setHealth(val string) {
|
||||||
if val == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
color := ui.ColorDefault
|
color := ui.ColorDefault
|
||||||
|
var mark string
|
||||||
|
|
||||||
switch val {
|
switch val {
|
||||||
|
case "":
|
||||||
|
return
|
||||||
case "healthy":
|
case "healthy":
|
||||||
|
mark = "☼"
|
||||||
color = ui.ThemeAttr("status.ok")
|
color = ui.ThemeAttr("status.ok")
|
||||||
case "unhealthy":
|
case "unhealthy":
|
||||||
|
mark = "⚠"
|
||||||
color = ui.ThemeAttr("status.danger")
|
color = ui.ThemeAttr("status.danger")
|
||||||
case "starting":
|
case "starting":
|
||||||
|
mark = "◌"
|
||||||
color = ui.ThemeAttr("status.warn")
|
color = ui.ThemeAttr("status.warn")
|
||||||
|
default:
|
||||||
|
mark = " "
|
||||||
|
log.Warningf("unknown health state string: \"%v\"", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cells []ui.Cell
|
s.health = ui.TextCells(mark, color, ui.ColorDefault)
|
||||||
for _, ch := range healthMark {
|
|
||||||
cells = append(cells, ui.Cell{Ch: ch, Fg: color})
|
|
||||||
}
|
|
||||||
s.health = cells
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,123 @@
|
|||||||
package compact
|
package compact
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/bcicen/ctop/cwidgets"
|
||||||
|
"github.com/bcicen/ctop/models"
|
||||||
|
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TextCol struct {
|
// Column that shows container's meta property i.e. name, id, image tc.
|
||||||
*ui.Par
|
type MetaCol struct {
|
||||||
|
*TextCol
|
||||||
|
metaName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTextCol(s string) *TextCol {
|
func (w *MetaCol) SetMeta(m models.Meta) {
|
||||||
p := ui.NewPar(s)
|
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.Border = false
|
||||||
p.Height = 1
|
p.Height = 1
|
||||||
p.Width = 20
|
p.Width = 20
|
||||||
return &TextCol{p}
|
|
||||||
|
return &TextCol{
|
||||||
|
Par: p,
|
||||||
|
header: header,
|
||||||
|
fWidth: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TextCol) Highlight() {
|
func (w *TextCol) Highlight() {
|
||||||
@@ -28,10 +132,16 @@ func (w *TextCol) UnHighlight() {
|
|||||||
w.TextBgColor = ui.ThemeAttr("par.text.bg")
|
w.TextBgColor = ui.ThemeAttr("par.text.bg")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TextCol) Reset() {
|
// TextCol implements CompactCol
|
||||||
w.Text = "-"
|
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
|
w.Text = s
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,31 +10,6 @@ import (
|
|||||||
|
|
||||||
const colSpacing = 1
|
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++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (width - spacing) / staticCols
|
|
||||||
}
|
|
||||||
|
|
||||||
func centerParText(p *ui.Par) {
|
func centerParText(p *ui.Par) {
|
||||||
var text string
|
var text string
|
||||||
var padding string
|
var padding string
|
||||||
|
|||||||
@@ -8,6 +8,14 @@ import (
|
|||||||
var log = logging.Init()
|
var log = logging.Init()
|
||||||
|
|
||||||
type WidgetUpdater interface {
|
type WidgetUpdater interface {
|
||||||
SetMeta(string, string)
|
SetMeta(models.Meta)
|
||||||
SetMetrics(models.Metrics)
|
SetMetrics(models.Metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NullWidgetUpdater struct{}
|
||||||
|
|
||||||
|
// NullWidgetUpdater implements WidgetUpdater
|
||||||
|
func (wu NullWidgetUpdater) SetMeta(models.Meta) {}
|
||||||
|
|
||||||
|
// NullWidgetUpdater implements WidgetUpdater
|
||||||
|
func (wu NullWidgetUpdater) SetMetrics(models.Metrics) {}
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ func NewCpu() *Cpu {
|
|||||||
|
|
||||||
// hack to force the default minY scale to 0
|
// hack to force the default minY scale to 0
|
||||||
tmpData := []float64{20}
|
tmpData := []float64{20}
|
||||||
cpu.Data = tmpData
|
cpu.Data["CPU"] = tmpData
|
||||||
_ = cpu.Buffer()
|
_ = cpu.Buffer()
|
||||||
|
|
||||||
cpu.Data = cpu.hist.Data
|
cpu.Data["CPU"] = cpu.hist.Data
|
||||||
return cpu
|
return cpu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package single
|
package single
|
||||||
|
|
||||||
import (
|
import (
|
||||||
ui "github.com/gizak/termui"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var envPattern = regexp.MustCompile(`(?P<KEY>[^=]+)=(?P<VALUJE>.*)`)
|
var envPattern = regexp.MustCompile(`(?P<KEY>[^=]+)=(?P<VALUJE>.*)`)
|
||||||
@@ -23,14 +25,18 @@ func NewEnv() *Env {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Env) Set(k, v string) {
|
func (w *Env) Set(allEnvs string) {
|
||||||
match := envPattern.FindStringSubmatch(v)
|
envs := strings.Split(allEnvs, ";")
|
||||||
key := match[1]
|
|
||||||
value := match[2]
|
|
||||||
w.data[key] = value
|
|
||||||
|
|
||||||
w.Rows = [][]string{}
|
w.Rows = [][]string{}
|
||||||
w.Rows = append(w.Rows, mkInfoRows(key, value)...)
|
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
|
w.Height = len(w.Rows) + 2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,20 @@ import (
|
|||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "health"}
|
var displayInfo = []string{"id", "name", "image", "ports", "IPs", "state", "created", "uptime", "health"}
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
*ui.Table
|
*ui.Table
|
||||||
data map[string]string
|
data map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInfo(id string) *Info {
|
func NewInfo() *Info {
|
||||||
p := ui.NewTable()
|
p := ui.NewTable()
|
||||||
p.Height = 4
|
p.Height = 4
|
||||||
p.Width = colWidth[0]
|
p.Width = colWidth[0]
|
||||||
p.FgColor = ui.ThemeAttr("par.text.fg")
|
p.FgColor = ui.ThemeAttr("par.text.fg")
|
||||||
p.Separator = false
|
p.Separator = false
|
||||||
i := &Info{p, make(map[string]string)}
|
i := &Info{p, make(map[string]string)}
|
||||||
i.Set("id", id)
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ func (w *IO) Update(read int64, write int64) {
|
|||||||
var rate string
|
var rate string
|
||||||
|
|
||||||
w.readHist.Append(int(read))
|
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.Lines[0].Title = fmt.Sprintf("read [%s/s]", rate)
|
||||||
|
|
||||||
w.writeHist.Append(int(write))
|
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)
|
w.Lines[1].Title = fmt.Sprintf("write [%s/s]", rate)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,12 +23,9 @@ type Single struct {
|
|||||||
Width int
|
Width int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSingle(id string) *Single {
|
func NewSingle() *Single {
|
||||||
if len(id) > 12 {
|
|
||||||
id = id[:12]
|
|
||||||
}
|
|
||||||
return &Single{
|
return &Single{
|
||||||
Info: NewInfo(id),
|
Info: NewInfo(),
|
||||||
Net: NewNet(),
|
Net: NewNet(),
|
||||||
Cpu: NewCpu(),
|
Cpu: NewCpu(),
|
||||||
Mem: NewMem(),
|
Mem: NewMem(),
|
||||||
@@ -55,11 +52,13 @@ func (e *Single) Down() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Single) SetWidth(w int) { e.Width = w }
|
func (e *Single) SetWidth(w int) { e.Width = w }
|
||||||
func (e *Single) SetMeta(k, v string) {
|
func (e *Single) SetMeta(m models.Meta) {
|
||||||
if k == "[ENV-VAR]" {
|
for k, v := range m {
|
||||||
e.Env.Set(k, v)
|
if k == "[ENV-VAR]" {
|
||||||
} else {
|
e.Env.Set(v)
|
||||||
e.Info.Set(k, v)
|
} else {
|
||||||
|
e.Info.Set(k, v)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +69,7 @@ func (e *Single) SetMetrics(m models.Metrics) {
|
|||||||
e.IO.Update(m.IOBytesRead, m.IOBytesWrite)
|
e.IO.Update(m.IOBytesRead, m.IOBytesWrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return total column height
|
// GetHeight returns total column height
|
||||||
func (e *Single) GetHeight() (h int) {
|
func (e *Single) GetHeight() (h int) {
|
||||||
h += e.Info.Height
|
h += e.Info.Height
|
||||||
h += e.Net.Height
|
h += e.Net.Height
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func newMemChart() *ui.MBarChart {
|
|||||||
mbar.BarColor[1] = ui.ColorBlack
|
mbar.BarColor[1] = ui.ColorBlack
|
||||||
mbar.NumColor[1] = ui.ColorBlack
|
mbar.NumColor[1] = ui.ColorBlack
|
||||||
|
|
||||||
mbar.NumFmt = cwidgets.ByteFormatInt
|
mbar.NumFmt = cwidgets.ByteFormatShort
|
||||||
//mbar.ShowScale = true
|
//mbar.ShowScale = true
|
||||||
return mbar
|
return mbar
|
||||||
}
|
}
|
||||||
@@ -78,6 +78,6 @@ func newMemChart() *ui.MBarChart {
|
|||||||
func (w *Mem) Update(val int, limit int) {
|
func (w *Mem) Update(val int, limit int) {
|
||||||
w.valHist.Append(val)
|
w.valHist.Append(val)
|
||||||
w.limitHist.Append(limit - 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
|
//w.Data[0] = w.hist.data
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ func (w *Net) Update(rx int64, tx int64) {
|
|||||||
var rate string
|
var rate string
|
||||||
|
|
||||||
w.rxHist.Append(int(rx))
|
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.Lines[0].Title = fmt.Sprintf("RX [%s/s]", rate)
|
||||||
|
|
||||||
w.txHist.Append(int(tx))
|
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)
|
w.Lines[1].Title = fmt.Sprintf("TX [%s/s]", rate)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,53 +1,74 @@
|
|||||||
package cwidgets
|
package cwidgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
kb = 1024
|
// byte ratio constants
|
||||||
mb = kb * 1024
|
_ = iota
|
||||||
gb = mb * 1024
|
kib float64 = 1 << (10 * iota)
|
||||||
tb = gb * 1024
|
mib
|
||||||
|
gib
|
||||||
|
tib
|
||||||
|
pib
|
||||||
)
|
)
|
||||||
|
|
||||||
// convenience method
|
var (
|
||||||
func ByteFormatInt(n int) string {
|
units = []float64{
|
||||||
return ByteFormat(int64(n))
|
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 {
|
func unpadFloat(f float64, maxp int) string {
|
||||||
if n < kb {
|
return strconv.FormatFloat(f, 'f', getPrecision(f, maxp), 64)
|
||||||
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) string {
|
func getPrecision(f float64, maxp int) int {
|
||||||
return strconv.FormatFloat(f, 'f', getPrecision(f), 64)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPrecision(f float64) int {
|
|
||||||
frac := int((f - float64(int(f))) * 100)
|
frac := int((f - float64(int(f))) * 100)
|
||||||
if frac == 0 {
|
if frac == 0 || maxp == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
if frac%10 == 0 {
|
if frac%10 == 0 || maxp < 2 {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return 2 // default precision
|
return maxp
|
||||||
}
|
}
|
||||||
|
|||||||
4
debug.go
4
debug.go
@@ -12,6 +12,10 @@ import (
|
|||||||
var mstats = &runtime.MemStats{}
|
var mstats = &runtime.MemStats{}
|
||||||
|
|
||||||
func logEvent(e ui.Event) {
|
func logEvent(e ui.Event) {
|
||||||
|
// skip timer events e.g. /timer/1s
|
||||||
|
if e.From == "timer" {
|
||||||
|
return
|
||||||
|
}
|
||||||
var s string
|
var s string
|
||||||
s += fmt.Sprintf("Type=%s", quote(e.Type))
|
s += fmt.Sprintf("Type=%s", quote(e.Type))
|
||||||
s += fmt.Sprintf(" Path=%s", quote(e.Path))
|
s += fmt.Sprintf(" Path=%s", quote(e.Path))
|
||||||
|
|||||||
87
go.mod
87
go.mod
@@ -1,41 +1,64 @@
|
|||||||
module github.com/bcicen/ctop
|
module github.com/bcicen/ctop
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Azure/go-ansiterm v0.0.0-20160622173216-fa152c58bc15 // indirect
|
github.com/BurntSushi/toml v0.3.1
|
||||||
github.com/BurntSushi/toml v0.3.0
|
|
||||||
github.com/Microsoft/go-winio v0.3.8 // indirect
|
|
||||||
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
|
|
||||||
github.com/Sirupsen/logrus v0.0.0-20150423025312-26709e271410 // indirect
|
|
||||||
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd
|
github.com/c9s/goprocinfo v0.0.0-20170609001544-b34328d6e0cd
|
||||||
github.com/coreos/go-systemd v0.0.0-20151104194251-b4a58d95188d // indirect
|
github.com/fsouza/go-dockerclient v1.7.0
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/gizak/termui v2.3.1-0.20180817033724-8d4faad06196+incompatible
|
||||||
github.com/docker/docker v0.0.0-20170502054910-90d35abf7b35 // indirect
|
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b // indirect
|
||||||
github.com/docker/go-connections v0.0.0-20170301234100-a2afab980204 // indirect
|
|
||||||
github.com/docker/go-units v0.3.2 // indirect
|
|
||||||
github.com/fsouza/go-dockerclient v0.0.0-20170307141636-318513eb1ab2
|
|
||||||
github.com/gizak/termui v2.3.0+incompatible
|
|
||||||
github.com/godbus/dbus v0.0.0-20151105175453-c7fdd8b5cd55 // indirect
|
|
||||||
github.com/golang/protobuf v0.0.0-20170712042213-0a4f71a498b7 // indirect
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.0.0-20170211013415-3573b8b52aa7 // indirect
|
|
||||||
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c
|
github.com/jgautheron/codename-generator v0.0.0-20150829203204-16d037c7cc3c
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/mattn/go-runewidth v0.0.2
|
||||||
github.com/maruel/panicparse v0.0.0-20170227222818-25bcac0d793c // indirect
|
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d
|
||||||
github.com/maruel/ut v1.0.0 // indirect
|
|
||||||
github.com/mattn/go-runewidth v0.0.0-20170201023540-14207d285c6c // indirect
|
|
||||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
|
||||||
github.com/nsf/termbox-go v0.0.0-20180303152453-e2050e41c884
|
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
||||||
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473
|
github.com/op/go-logging v0.0.0-20160211212156-b2cb9fa56473
|
||||||
github.com/opencontainers/runc v0.1.1
|
github.com/opencontainers/runc v1.1.0
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pkg/browser v0.0.0-20201207095918-0426ae3fba23
|
||||||
github.com/seccomp/libseccomp-golang v0.0.0-20150813023252-1b506fc7c24e // indirect
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/stretchr/testify v1.2.2 // indirect
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/syndtr/gocapability v0.0.0-20150716010906-2c00daeb6c3b // indirect
|
|
||||||
github.com/vishvananda/netlink v0.0.0-20150820014904-1e2e08e8a2dc // indirect
|
|
||||||
github.com/vishvananda/netns v0.0.0-20180720170159-13995c7128cc // indirect
|
|
||||||
golang.org/x/net v0.0.0-20170308210134-a6577fac2d73 // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
|
|
||||||
golang.org/x/sys v0.0.0-20170308153327-99f16d856c98 // indirect
|
|
||||||
)
|
)
|
||||||
|
|
||||||
replace github.com/gizak/termui => github.com/bcicen/termui v0.0.0-20180326052246-4eb80249d3f5
|
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
256
go.sum
Normal 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=
|
||||||
75
grid.go
75
grid.go
@@ -6,6 +6,44 @@ import (
|
|||||||
ui "github.com/gizak/termui"
|
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) {
|
func RedrawRows(clr bool) {
|
||||||
// reinit body rows
|
// reinit body rows
|
||||||
cGrid.Clear()
|
cGrid.Clear()
|
||||||
@@ -33,7 +71,6 @@ func RedrawRows(clr bool) {
|
|||||||
}
|
}
|
||||||
cGrid.Align()
|
cGrid.Align()
|
||||||
ui.Render(cGrid)
|
ui.Render(cGrid)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SingleView() MenuFn {
|
func SingleView() MenuFn {
|
||||||
@@ -46,7 +83,7 @@ func SingleView() MenuFn {
|
|||||||
ui.DefaultEvtStream.ResetHandlers()
|
ui.DefaultEvtStream.ResetHandlers()
|
||||||
defer ui.DefaultEvtStream.ResetHandlers()
|
defer ui.DefaultEvtStream.ResetHandlers()
|
||||||
|
|
||||||
ex := single.NewSingle(c.Id)
|
ex := single.NewSingle()
|
||||||
c.SetUpdater(ex)
|
c.SetUpdater(ex)
|
||||||
|
|
||||||
ex.Align()
|
ex.Align()
|
||||||
@@ -68,16 +105,21 @@ func SingleView() MenuFn {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RefreshDisplay() {
|
func RefreshDisplay() error {
|
||||||
// skip display refresh during scroll
|
// skip display refresh during scroll
|
||||||
if !cursor.isScrolling {
|
if !cursor.isScrolling {
|
||||||
needsClear := cursor.RefreshContainers()
|
needsClear, err := cursor.RefreshContainers()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
RedrawRows(needsClear)
|
RedrawRows(needsClear)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Display() bool {
|
func Display() bool {
|
||||||
var menu MenuFn
|
var menu MenuFn
|
||||||
|
var connErr error
|
||||||
|
|
||||||
cGrid.SetWidth(ui.TermWidth())
|
cGrid.SetWidth(ui.TermWidth())
|
||||||
ui.DefaultEvtStream.Hook(logEvent)
|
ui.DefaultEvtStream.Hook(logEvent)
|
||||||
@@ -116,13 +158,23 @@ func Display() bool {
|
|||||||
menu = LogMenu
|
menu = LogMenu
|
||||||
ui.StopLoop()
|
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) {
|
ui.Handle("/sys/kbd/o", func(ui.Event) {
|
||||||
menu = SingleView
|
menu = SingleView
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/a", func(ui.Event) {
|
ui.Handle("/sys/kbd/a", func(ui.Event) {
|
||||||
config.Toggle("allContainers")
|
config.Toggle("allContainers")
|
||||||
RefreshDisplay()
|
connErr = RefreshDisplay()
|
||||||
|
if connErr != nil {
|
||||||
|
ui.StopLoop()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/D", func(ui.Event) {
|
ui.Handle("/sys/kbd/D", func(ui.Event) {
|
||||||
dumpContainer(cursor.Selected())
|
dumpContainer(cursor.Selected())
|
||||||
@@ -142,6 +194,10 @@ func Display() bool {
|
|||||||
menu = SortMenu
|
menu = SortMenu
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
|
ui.Handle("/sys/kbd/c", func(ui.Event) {
|
||||||
|
menu = ColumnsMenu
|
||||||
|
ui.StopLoop()
|
||||||
|
})
|
||||||
ui.Handle("/sys/kbd/S", func(ui.Event) {
|
ui.Handle("/sys/kbd/S", func(ui.Event) {
|
||||||
path, err := config.Write()
|
path, err := config.Write()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@@ -156,7 +212,10 @@ func Display() bool {
|
|||||||
if log.StatusQueued() {
|
if log.StatusQueued() {
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
}
|
}
|
||||||
RefreshDisplay()
|
connErr = RefreshDisplay()
|
||||||
|
if connErr != nil {
|
||||||
|
ui.StopLoop()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
ui.Handle("/sys/wnd/resize", func(e ui.Event) {
|
||||||
@@ -170,6 +229,10 @@ func Display() bool {
|
|||||||
|
|
||||||
ui.Loop()
|
ui.Loop()
|
||||||
|
|
||||||
|
if connErr != nil {
|
||||||
|
return ShowConnError(connErr)
|
||||||
|
}
|
||||||
|
|
||||||
if log.StatusQueued() {
|
if log.StatusQueued() {
|
||||||
for sm := range log.FlushStatus() {
|
for sm := range log.FlushStatus() {
|
||||||
if sm.IsError {
|
if sm.IsError {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ type statusMsg struct {
|
|||||||
type CTopLogger struct {
|
type CTopLogger struct {
|
||||||
*logging.Logger
|
*logging.Logger
|
||||||
backend *logging.MemoryBackend
|
backend *logging.MemoryBackend
|
||||||
|
logFile *os.File
|
||||||
sLog []statusMsg
|
sLog []statusMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,18 +59,37 @@ func Init() *CTopLogger {
|
|||||||
Log = &CTopLogger{
|
Log = &CTopLogger{
|
||||||
logging.MustGetLogger("ctop"),
|
logging.MustGetLogger("ctop"),
|
||||||
logging.NewMemoryBackend(size),
|
logging.NewMemoryBackend(size),
|
||||||
|
nil,
|
||||||
[]statusMsg{},
|
[]statusMsg{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if debugMode() {
|
debugMode := debugMode()
|
||||||
|
if debugMode {
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
StartServer()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
backendLvl := logging.AddModuleLevel(Log.backend)
|
backendLvl := logging.AddModuleLevel(Log.backend)
|
||||||
backendLvl.SetLevel(level, "")
|
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")
|
Log.Notice("logger initialized")
|
||||||
}
|
}
|
||||||
return Log
|
return Log
|
||||||
@@ -102,8 +122,12 @@ func (log *CTopLogger) tail() chan string {
|
|||||||
|
|
||||||
func (log *CTopLogger) Exit() {
|
func (log *CTopLogger) Exit() {
|
||||||
exited = true
|
exited = true
|
||||||
|
if log.logFile != nil {
|
||||||
|
_ = log.logFile.Close()
|
||||||
|
}
|
||||||
StopServer()
|
StopServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
|
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
|
||||||
func debugModeTCP() bool { return os.Getenv("CTOP_DEBUG_TCP") == "1" }
|
func debugModeTCP() bool { return os.Getenv("CTOP_DEBUG_TCP") == "1" }
|
||||||
|
func debugModeFile() string { return os.Getenv("CTOP_DEBUG_FILE") }
|
||||||
|
|||||||
26
main.go
26
main.go
@@ -22,11 +22,12 @@ var (
|
|||||||
version = "dev-build"
|
version = "dev-build"
|
||||||
goVersion = runtime.Version()
|
goVersion = runtime.Version()
|
||||||
|
|
||||||
log *logging.CTopLogger
|
log *logging.CTopLogger
|
||||||
cursor *GridCursor
|
cursor *GridCursor
|
||||||
cGrid *compact.CompactGrid
|
cGrid *compact.CompactGrid
|
||||||
header *widgets.CTopHeader
|
header *widgets.CTopHeader
|
||||||
status *widgets.StatusLine
|
status *widgets.StatusLine
|
||||||
|
errView *widgets.ErrorView
|
||||||
|
|
||||||
versionStr = fmt.Sprintf("ctop version %v, build %v %v", version, build, goVersion)
|
versionStr = fmt.Sprintf("ctop version %v, build %v %v", version, build, goVersion)
|
||||||
)
|
)
|
||||||
@@ -43,7 +44,6 @@ func main() {
|
|||||||
sortFieldFlag = flag.String("s", "", "select container sort field")
|
sortFieldFlag = flag.String("s", "", "select container sort field")
|
||||||
reverseSortFlag = flag.Bool("r", false, "reverse container sort order")
|
reverseSortFlag = flag.Bool("r", false, "reverse container sort order")
|
||||||
invertFlag = flag.Bool("i", false, "invert default colors")
|
invertFlag = flag.Bool("i", false, "invert default colors")
|
||||||
scaleCpu = flag.Bool("scale-cpu", false, "show cpu as % of system total")
|
|
||||||
connectorFlag = flag.String("connector", "docker", "container connector to use")
|
connectorFlag = flag.String("connector", "docker", "container connector to use")
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@@ -63,7 +63,9 @@ func main() {
|
|||||||
|
|
||||||
// init global config and read config file if exists
|
// init global config and read config file if exists
|
||||||
config.Init()
|
config.Init()
|
||||||
config.Read()
|
if err := config.Read(); err != nil {
|
||||||
|
log.Warningf("reading config: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// override default config values with command line flags
|
// override default config values with command line flags
|
||||||
if *filterFlag != "" {
|
if *filterFlag != "" {
|
||||||
@@ -83,10 +85,6 @@ func main() {
|
|||||||
config.Toggle("sortReversed")
|
config.Toggle("sortReversed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if *scaleCpu {
|
|
||||||
config.Toggle("scaleCpu")
|
|
||||||
}
|
|
||||||
|
|
||||||
// init ui
|
// init ui
|
||||||
if *invertFlag {
|
if *invertFlag {
|
||||||
InvertColorMap()
|
InvertColorMap()
|
||||||
@@ -99,14 +97,15 @@ func main() {
|
|||||||
|
|
||||||
defer Shutdown()
|
defer Shutdown()
|
||||||
// init grid, cursor, header
|
// init grid, cursor, header
|
||||||
conn, err := connector.ByName(*connectorFlag)
|
cSuper, err := connector.ByName(*connectorFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
cursor = &GridCursor{cSource: conn}
|
cursor = &GridCursor{cSuper: cSuper}
|
||||||
cGrid = compact.NewCompactGrid()
|
cGrid = compact.NewCompactGrid()
|
||||||
header = widgets.NewCTopHeader()
|
header = widgets.NewCTopHeader()
|
||||||
status = widgets.NewStatusLine()
|
status = widgets.NewStatusLine()
|
||||||
|
errView = widgets.NewErrorView()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
exit := Display()
|
exit := Display()
|
||||||
@@ -135,6 +134,7 @@ func validSort(s string) {
|
|||||||
func panicExit() {
|
func panicExit() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
Shutdown()
|
Shutdown()
|
||||||
|
panic(r)
|
||||||
fmt.Printf("error: %s\n", r)
|
fmt.Printf("error: %s\n", r)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
254
menus.go
254
menus.go
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bcicen/ctop/config"
|
"github.com/bcicen/ctop/config"
|
||||||
@@ -9,6 +10,7 @@ import (
|
|||||||
"github.com/bcicen/ctop/widgets"
|
"github.com/bcicen/ctop/widgets"
|
||||||
"github.com/bcicen/ctop/widgets/menu"
|
"github.com/bcicen/ctop/widgets/menu"
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
|
"github.com/pkg/browser"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MenuFn executes a menu window, returning the next menu or nil
|
// MenuFn executes a menu window, returning the next menu or nil
|
||||||
@@ -25,6 +27,9 @@ var helpDialog = []menu.Item{
|
|||||||
{"[r] - reverse container sort order", ""},
|
{"[r] - reverse container sort order", ""},
|
||||||
{"[o] - open single view", ""},
|
{"[o] - open single view", ""},
|
||||||
{"[l] - view container logs ([t] to toggle timestamp when open)", ""},
|
{"[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", ""},
|
{"[S] - save current configuration to file", ""},
|
||||||
{"[q] - exit ctop", ""},
|
{"[q] - exit ctop", ""},
|
||||||
}
|
}
|
||||||
@@ -103,7 +108,90 @@ func SortMenu() MenuFn {
|
|||||||
HandleKeys("exit", ui.StopLoop)
|
HandleKeys("exit", ui.StopLoop)
|
||||||
|
|
||||||
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
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.StopLoop()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -126,55 +214,121 @@ func ContainerMenu() MenuFn {
|
|||||||
m.BorderLabel = "Menu"
|
m.BorderLabel = "Menu"
|
||||||
|
|
||||||
items := []menu.Item{
|
items := []menu.Item{
|
||||||
menu.Item{Val: "single", Label: "single view"},
|
menu.Item{Val: "single", Label: "[o] single view"},
|
||||||
menu.Item{Val: "logs", Label: "log view"},
|
menu.Item{Val: "logs", Label: "[l] log view"},
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Meta["state"] == "running" {
|
if c.Meta["state"] == "running" {
|
||||||
items = append(items, menu.Item{Val: "stop", Label: "stop"})
|
items = append(items, menu.Item{Val: "stop", Label: "[s] stop"})
|
||||||
items = append(items, menu.Item{Val: "pause", Label: "pause"})
|
items = append(items, menu.Item{Val: "pause", Label: "[p] pause"})
|
||||||
items = append(items, menu.Item{Val: "restart", Label: "restart"})
|
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" {
|
if c.Meta["state"] == "exited" || c.Meta["state"] == "created" {
|
||||||
items = append(items, menu.Item{Val: "start", Label: "start"})
|
items = append(items, menu.Item{Val: "start", Label: "[s] start"})
|
||||||
items = append(items, menu.Item{Val: "remove", Label: "remove"})
|
items = append(items, menu.Item{Val: "remove", Label: "[R] remove"})
|
||||||
}
|
}
|
||||||
if c.Meta["state"] == "paused" {
|
if c.Meta["state"] == "paused" {
|
||||||
items = append(items, menu.Item{Val: "unpause", Label: "unpause"})
|
items = append(items, menu.Item{Val: "unpause", Label: "[p] unpause"})
|
||||||
}
|
}
|
||||||
items = append(items, menu.Item{Val: "cancel", Label: "cancel"})
|
items = append(items, menu.Item{Val: "cancel", Label: "[c] cancel"})
|
||||||
|
|
||||||
m.AddItems(items...)
|
m.AddItems(items...)
|
||||||
ui.Render(m)
|
ui.Render(m)
|
||||||
|
|
||||||
var nextMenu MenuFn
|
|
||||||
HandleKeys("up", m.Up)
|
HandleKeys("up", m.Up)
|
||||||
HandleKeys("down", m.Down)
|
HandleKeys("down", m.Down)
|
||||||
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
|
||||||
switch m.SelectedItem().Val {
|
var selected string
|
||||||
case "single":
|
|
||||||
nextMenu = SingleView
|
// shortcuts
|
||||||
case "logs":
|
ui.Handle("/sys/kbd/o", func(ui.Event) {
|
||||||
nextMenu = LogMenu
|
selected = "single"
|
||||||
case "start":
|
ui.StopLoop()
|
||||||
nextMenu = Confirm(confirmTxt("start", c.GetMeta("name")), c.Start)
|
})
|
||||||
case "stop":
|
ui.Handle("/sys/kbd/l", func(ui.Event) {
|
||||||
nextMenu = Confirm(confirmTxt("stop", c.GetMeta("name")), c.Stop)
|
selected = "logs"
|
||||||
case "remove":
|
ui.StopLoop()
|
||||||
nextMenu = Confirm(confirmTxt("remove", c.GetMeta("name")), c.Remove)
|
})
|
||||||
case "pause":
|
if c.Meta["state"] != "paused" {
|
||||||
nextMenu = Confirm(confirmTxt("pause", c.GetMeta("name")), c.Pause)
|
ui.Handle("/sys/kbd/s", func(ui.Event) {
|
||||||
case "unpause":
|
if c.Meta["state"] == "running" {
|
||||||
nextMenu = Confirm(confirmTxt("unpause", c.GetMeta("name")), c.Unpause)
|
selected = "stop"
|
||||||
case "restart":
|
} else {
|
||||||
nextMenu = Confirm(confirmTxt("restart", c.GetMeta("name")), c.Restart)
|
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.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Handle("/sys/kbd/", func(ui.Event) {
|
ui.Handle("/sys/kbd/", func(ui.Event) {
|
||||||
ui.StopLoop()
|
ui.StopLoop()
|
||||||
})
|
})
|
||||||
ui.Loop()
|
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
|
return nextMenu
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,6 +361,46 @@ func LogMenu() MenuFn {
|
|||||||
return nil
|
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
|
// Create a confirmation dialog with a given description string and
|
||||||
// func to perform if confirmed
|
// func to perform if confirmed
|
||||||
func Confirm(txt string, fn func()) MenuFn {
|
func Confirm(txt string, fn func()) MenuFn {
|
||||||
@@ -246,7 +440,7 @@ func Confirm(txt string, fn func()) MenuFn {
|
|||||||
ui.Handle("/sys/kbd/y", func(ui.Event) { yes() })
|
ui.Handle("/sys/kbd/y", func(ui.Event) { yes() })
|
||||||
|
|
||||||
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
ui.Handle("/sys/kbd/<enter>", func(ui.Event) {
|
||||||
switch m.SelectedItem().Val {
|
switch m.SelectedValue() {
|
||||||
case "cancel":
|
case "cancel":
|
||||||
no()
|
no()
|
||||||
case "yes":
|
case "yes":
|
||||||
|
|||||||
@@ -7,7 +7,31 @@ type Log struct {
|
|||||||
Message string
|
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 {
|
type Metrics struct {
|
||||||
|
NCpus uint8
|
||||||
CPUUtil int
|
CPUUtil int
|
||||||
NetTx int64
|
NetTx int64
|
||||||
NetRx int64
|
NetRx int64
|
||||||
|
|||||||
60
widgets/error.go
Normal file
60
widgets/error.go
Normal 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))
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ type CTopHeader struct {
|
|||||||
|
|
||||||
func NewCTopHeader() *CTopHeader {
|
func NewCTopHeader() *CTopHeader {
|
||||||
return &CTopHeader{
|
return &CTopHeader{
|
||||||
Time: headerPar(2, timeStr()),
|
Time: headerPar(2, ""),
|
||||||
Count: headerPar(24, "-"),
|
Count: headerPar(24, "-"),
|
||||||
Filter: headerPar(40, ""),
|
Filter: headerPar(40, ""),
|
||||||
bg: headerBg(),
|
bg: headerBg(),
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ type Padding [2]int // x,y padding
|
|||||||
type Menu struct {
|
type Menu struct {
|
||||||
ui.Block
|
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
|
SubText string // optional text to display before items
|
||||||
TextFgColor ui.Attribute
|
TextFgColor ui.Attribute
|
||||||
TextBgColor ui.Attribute
|
TextBgColor ui.Attribute
|
||||||
Selectable bool
|
|
||||||
cursorPos int
|
cursorPos int
|
||||||
items Items
|
items Items
|
||||||
padding Padding
|
padding Padding
|
||||||
|
toolTip *ToolTip
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMenu() *Menu {
|
func NewMenu() *Menu {
|
||||||
@@ -42,7 +43,7 @@ func (m *Menu) AddItems(items ...Item) {
|
|||||||
m.refresh()
|
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) {
|
func (m *Menu) DelItem(s string) (success bool) {
|
||||||
for n, i := range m.items {
|
for n, i := range m.items {
|
||||||
if i.Val == s || i.Label == s {
|
if i.Val == s || i.Label == s {
|
||||||
@@ -55,6 +56,11 @@ func (m *Menu) DelItem(s string) (success bool) {
|
|||||||
return success
|
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
|
// Move cursor to an position by Item value or label
|
||||||
func (m *Menu) SetCursor(s string) (success bool) {
|
func (m *Menu) SetCursor(s string) (success bool) {
|
||||||
for n, i := range m.items {
|
for n, i := range m.items {
|
||||||
@@ -66,19 +72,19 @@ func (m *Menu) SetCursor(s string) (success bool) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort menu items(if enabled) and re-calculate window size
|
// SetToolTip sets an optional tooltip string to show at bottom of screen
|
||||||
func (m *Menu) refresh() {
|
func (m *Menu) SetToolTip(lines ...string) {
|
||||||
if m.SortItems {
|
m.toolTip = NewToolTip(lines...)
|
||||||
sort.Sort(m.items)
|
|
||||||
}
|
|
||||||
m.calcSize()
|
|
||||||
ui.Render(m)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Menu) SelectedItem() Item {
|
func (m *Menu) SelectedItem() Item {
|
||||||
return m.items[m.cursorPos]
|
return m.items[m.cursorPos]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Menu) SelectedValue() string {
|
||||||
|
return m.items[m.cursorPos].Val
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Menu) Buffer() ui.Buffer {
|
func (m *Menu) Buffer() ui.Buffer {
|
||||||
var cell ui.Cell
|
var cell ui.Cell
|
||||||
buf := m.Block.Buffer()
|
buf := m.Block.Buffer()
|
||||||
@@ -108,6 +114,10 @@ func (m *Menu) Buffer() ui.Buffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.toolTip != nil {
|
||||||
|
buf.Merge(m.toolTip.Buffer())
|
||||||
|
}
|
||||||
|
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +135,15 @@ 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
|
// Set width and height based on menu items
|
||||||
func (m *Menu) calcSize() {
|
func (m *Menu) calcSize() {
|
||||||
m.Width = 7 // minimum width
|
m.Width = 7 // minimum width
|
||||||
|
|||||||
55
widgets/menu/tooltip.go
Normal file
55
widgets/menu/tooltip.go
Normal 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()
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package widgets
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
ui "github.com/gizak/termui"
|
ui "github.com/gizak/termui"
|
||||||
|
"github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ToggleText interface {
|
type ToggleText interface {
|
||||||
@@ -70,7 +71,7 @@ func (t *TextView) Buffer() ui.Buffer {
|
|||||||
for _, ch := range line {
|
for _, ch := range line {
|
||||||
cell = ui.Cell{Ch: ch, Fg: t.TextFgColor, Bg: t.TextBgColor}
|
cell = ui.Cell{Ch: ch, Fg: t.TextFgColor, Bg: t.TextBgColor}
|
||||||
buf.Set(x, y, cell)
|
buf.Set(x, y, cell)
|
||||||
x++
|
x = x + runewidth.RuneWidth(ch)
|
||||||
}
|
}
|
||||||
x = t.Block.X + t.padding[0]
|
x = t.Block.X + t.padding[0]
|
||||||
y++
|
y++
|
||||||
|
|||||||
Reference in New Issue
Block a user