mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 23:26:45 +08:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5db90f31dc | ||
|
|
82677d52ef | ||
|
|
2b2338805b | ||
|
|
60213f1551 | ||
|
|
8aa932b29f | ||
|
|
35cc8d095d | ||
|
|
30530bc2a1 | ||
|
|
2c282923c0 | ||
|
|
d0d39749de | ||
|
|
26b88a9790 | ||
|
|
a135a67c06 | ||
|
|
19b212f45d | ||
|
|
34987df010 | ||
|
|
e2bc4d0a08 | ||
|
|
4ac1348fbb | ||
|
|
66d78a7d74 | ||
|
|
e62a8881a2 | ||
|
|
a5b2e7b074 |
11
Dockerfile
11
Dockerfile
@@ -1,10 +1,3 @@
|
||||
FROM quay.io/vektorcloud/glibc:latest
|
||||
|
||||
ARG CTOP_VERSION=0.5
|
||||
ENV CTOP_URL https://github.com/bcicen/ctop/releases/download/v${CTOP_VERSION}/ctop-${CTOP_VERSION}-linux-amd64
|
||||
|
||||
RUN echo $CTOP_URL && \
|
||||
wget -q $CTOP_URL -O /ctop && \
|
||||
chmod +x /ctop
|
||||
|
||||
FROM scratch
|
||||
COPY ./ctop /ctop
|
||||
ENTRYPOINT ["/ctop"]
|
||||
|
||||
12
Dockerfile_build
Normal file
12
Dockerfile_build
Normal file
@@ -0,0 +1,12 @@
|
||||
FROM quay.io/vektorcloud/go:1.8
|
||||
|
||||
RUN apk add --no-cache make
|
||||
|
||||
COPY glide.* /go/src/github.com/bcicen/ctop/
|
||||
WORKDIR /go/src/github.com/bcicen/ctop/
|
||||
RUN glide install
|
||||
|
||||
COPY . /go/src/github.com/bcicen/ctop
|
||||
RUN make build && \
|
||||
mkdir -p /go/bin && \
|
||||
mv -v ctop /go/bin/
|
||||
34
Makefile
Normal file
34
Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
NAME=ctop
|
||||
VERSION=$(shell cat VERSION)
|
||||
BUILD=$(shell git rev-parse --short HEAD)
|
||||
LD_FLAGS="-w -X main.version=$(VERSION) -X main.build=$(BUILD)"
|
||||
|
||||
clean:
|
||||
rm -rf build/ release/
|
||||
|
||||
build:
|
||||
glide install
|
||||
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)"
|
||||
|
||||
build-all:
|
||||
mkdir -p build
|
||||
GOOS=darwin GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o build/ctop-$(VERSION)-darwin-amd64
|
||||
GOOS=linux GOARCH=amd64 go build -tags release -ldflags $(LD_FLAGS) -o build/ctop-$(VERSION)-linux-amd64
|
||||
GOOS=linux GOARCH=arm go build -tags release -ldflags $(LD_FLAGS) -o build/ctop-$(VERSION)-linux-arm
|
||||
|
||||
image:
|
||||
docker build -t ctop_build -f Dockerfile_build .
|
||||
docker run -ti --rm -v $(shell pwd):/target ctop_build cp -v /go/bin/ctop /target/
|
||||
docker build -t ctop -f Dockerfile .
|
||||
|
||||
release:
|
||||
mkdir release
|
||||
go get github.com/progrium/gh-release/...
|
||||
cp build/* release
|
||||
gh-release create bcicen/$(NAME) $(VERSION) \
|
||||
$(shell git rev-parse --abbrev-ref HEAD) $(VERSION)
|
||||
|
||||
.PHONY: build
|
||||
23
README.md
23
README.md
@@ -1,4 +1,5 @@
|
||||
<p align="center"><img width="200px" src="/_docs/img/logo.png" alt="ctop"/></p>
|
||||
|
||||
#
|
||||
|
||||
Top-like interface for container metrics
|
||||
@@ -17,16 +18,18 @@ Fetch the [latest release](https://github.com/bcicen/ctop/releases) for your pla
|
||||
#### Linux
|
||||
|
||||
```bash
|
||||
wget https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-linux-amd64 -O ctop
|
||||
sudo mv ctop /usr/local/bin/
|
||||
sudo wget https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-linux-amd64 -O /usr/local/bin/ctop
|
||||
sudo chmod +x /usr/local/bin/ctop
|
||||
```
|
||||
|
||||
#### OS X
|
||||
|
||||
```bash
|
||||
curl -Lo ctop https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-darwin-amd64
|
||||
sudo mv ctop /usr/local/bin/
|
||||
brew install ctop
|
||||
```
|
||||
or
|
||||
```bash
|
||||
sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-darwin-amd64
|
||||
sudo chmod +x /usr/local/bin/ctop
|
||||
```
|
||||
|
||||
@@ -35,18 +38,11 @@ or run via Docker:
|
||||
docker run -ti --name ctop --rm -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest
|
||||
```
|
||||
|
||||
`ctop` is also available for Arch in the [AUR](https://aur.archlinux.org/packages/ctop/)
|
||||
`ctop` is also available for Arch in the [AUR](https://aur.archlinux.org/packages/ctop-bin/)
|
||||
|
||||
## Building
|
||||
|
||||
To build `ctop` from source, ensure you have a recent version of [glide](http://glide.sh/) installed and run:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/bcicen/ctop.git $GOPATH/src/github.com/bcicen/ctop && \
|
||||
cd $GOPATH/src/github.com/bcicen/ctop && \
|
||||
glide install && \
|
||||
go build
|
||||
```
|
||||
Build steps can be found [here][build].
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -80,4 +76,5 @@ s | Select container sort field
|
||||
r | Reverse container sort order
|
||||
q | Quit ctop
|
||||
|
||||
[build]: _docs/build.md
|
||||
[expanded_view]: _docs/expanded.md
|
||||
|
||||
20
_docs/build.md
Normal file
20
_docs/build.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Build
|
||||
|
||||
To build `ctop` from source, ensure you have a recent version of [glide](https://github.com/Masterminds/glide) installed and run:
|
||||
|
||||
```bash
|
||||
go get github.com/bcicen/ctop && \
|
||||
cd $GOPATH/src/github.com/bcicen/ctop && \
|
||||
make build
|
||||
```
|
||||
|
||||
To build a minimal Docker image containing only `ctop`:
|
||||
```bash
|
||||
make image
|
||||
```
|
||||
|
||||
Now you can run your local image:
|
||||
|
||||
```bash
|
||||
docker run -ti --name ctop --rm -v /var/run/docker.sock:/var/run/docker.sock ctop
|
||||
```
|
||||
24
_docs/debug.md
Normal file
24
_docs/debug.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Debug Mode
|
||||
|
||||
`ctop` comes with a built-in logging facility and local socket server to simplify debugging at run time. Debug mode can be enabled via the `CTOP_DEBUG` environment variable:
|
||||
|
||||
```bash
|
||||
CTOP_DEBUG=1 ./ctop
|
||||
```
|
||||
|
||||
While `ctop` is running, you can connect to the logging socket via socat or similar tools:
|
||||
```bash
|
||||
socat unix-connect:/tmp/ctop.sock stdio
|
||||
```
|
||||
|
||||
example output:
|
||||
```
|
||||
15:06:43.881 ▶ NOTI 002 logger initialized
|
||||
15:06:43.881 ▶ INFO 003 loaded config param: "filterStr": ""
|
||||
15:06:43.881 ▶ INFO 004 loaded config param: "sortField": "state"
|
||||
15:06:43.881 ▶ INFO 005 loaded config switch: "sortReversed": false
|
||||
15:06:43.881 ▶ INFO 006 loaded config switch: "allContainers": true
|
||||
15:06:43.881 ▶ INFO 007 loaded config switch: "enableHeader": true
|
||||
15:06:43.883 ▶ INFO 008 collector started for container: 7120f83ca...
|
||||
...
|
||||
```
|
||||
@@ -7,7 +7,7 @@ machine:
|
||||
dependencies:
|
||||
override:
|
||||
- docker info
|
||||
- docker build --build-arg CTOP_VERSION=$(cat VERSION) -t ctop .
|
||||
- make image
|
||||
|
||||
test:
|
||||
override:
|
||||
|
||||
@@ -18,7 +18,6 @@ func Init() {
|
||||
GlobalParams = append(GlobalParams, p)
|
||||
log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
|
||||
}
|
||||
|
||||
for _, s := range switches {
|
||||
GlobalSwitches = append(GlobalSwitches, s)
|
||||
log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)
|
||||
|
||||
@@ -17,11 +17,6 @@ var switches = []*Switch{
|
||||
Val: true,
|
||||
Label: "Enable Status Header",
|
||||
},
|
||||
&Switch{
|
||||
Key: "loggingEnabled",
|
||||
Val: false,
|
||||
Label: "Enable Logging Server",
|
||||
},
|
||||
}
|
||||
|
||||
type Switch struct {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/op/go-logging"
|
||||
@@ -13,7 +14,7 @@ const (
|
||||
var (
|
||||
Log *CTopLogger
|
||||
exited bool
|
||||
level = logging.INFO
|
||||
level = logging.INFO // default level
|
||||
format = logging.MustStringFormatter(
|
||||
`%{color}%{time:15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
||||
)
|
||||
@@ -33,6 +34,11 @@ func Init() *CTopLogger {
|
||||
logging.NewMemoryBackend(size),
|
||||
}
|
||||
|
||||
if debugMode() {
|
||||
level = logging.DEBUG
|
||||
StartServer()
|
||||
}
|
||||
|
||||
backendLvl := logging.AddModuleLevel(Log.backend)
|
||||
backendLvl.SetLevel(level, "")
|
||||
|
||||
@@ -71,3 +77,5 @@ func (log *CTopLogger) Exit() {
|
||||
exited = true
|
||||
StopServer()
|
||||
}
|
||||
|
||||
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
|
||||
|
||||
15
main.go
15
main.go
@@ -25,9 +25,6 @@ var (
|
||||
func main() {
|
||||
defer panicExit()
|
||||
|
||||
// init global config
|
||||
config.Init()
|
||||
|
||||
// parse command line arguments
|
||||
var versionFlag = flag.Bool("v", false, "output version information and exit")
|
||||
var helpFlag = flag.Bool("h", false, "display this help dialog")
|
||||
@@ -48,6 +45,12 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// init logger
|
||||
log = logging.Init()
|
||||
|
||||
// init global config
|
||||
config.Init()
|
||||
|
||||
// override default config values with command line flags
|
||||
if *filterFlag != "" {
|
||||
config.Update("filterStr", *filterFlag)
|
||||
@@ -66,12 +69,6 @@ func main() {
|
||||
config.Toggle("sortReversed")
|
||||
}
|
||||
|
||||
// init logger
|
||||
log = logging.Init()
|
||||
if config.GetSwitchVal("loggingEnabled") {
|
||||
logging.StartServer()
|
||||
}
|
||||
|
||||
// init ui
|
||||
if *invertFlag {
|
||||
InvertColorMap()
|
||||
|
||||
Reference in New Issue
Block a user