Compare commits

...

18 Commits
v0.5 ... v0.5.1

Author SHA1 Message Date
Bradley Cicenas
5db90f31dc v0.5.1 2017-03-21 10:35:24 +10:00
Bradley Cicenas
82677d52ef add build section to docs 2017-03-20 08:39:57 +10:00
Bradley Cicenas
2b2338805b update circleci to build image from source 2017-03-19 16:14:56 +10:00
Bradley Cicenas
60213f1551 add debug section to docs 2017-03-19 15:10:03 +10:00
Bradley Cicenas
8aa932b29f Toggle debug mode via env var
remove logging param from global config, allowing logging server and
level to be configured inside logging subpackage from CTOP_DEBUG env var
2017-03-19 15:10:03 +10:00
Bradley Cicenas
35cc8d095d include Makefile instructions for building image from source 2017-03-19 15:10:03 +10:00
bradley
30530bc2a1 Merge pull request #52 from InTheCloudDan/patch-1
change glide to github repo, url is expired.
2017-03-19 10:50:33 +10:00
Dan O'Brien
2c282923c0 change glide to github repo, url is expired. 2017-03-18 20:39:53 -04:00
bradley
d0d39749de Merge pull request #47 from thomasleveil/patch-1
README: optimize install instructions
2017-03-18 10:47:19 +10:00
Bradley Cicenas
26b88a9790 add Makefile 2017-03-18 10:38:03 +10:00
bradley
a135a67c06 Merge pull request #49 from firecat53/patch-2
Add minimal Docker image build instructions
2017-03-17 16:57:29 +10:00
Scott Hansen
19b212f45d Add minimal Docker image build instructions
Update README to include instructions for building from source a minimal Docker image with only ctop.
2017-03-16 11:53:45 -07:00
Thomas LÉVEIL
34987df010 README: optimize install instructions 2017-03-15 20:22:08 +01:00
bradley
e2bc4d0a08 fix newline 2017-03-15 22:54:23 +10:00
bradley
4ac1348fbb Merge pull request #43 from mieciu/patch-1
Update README.md
2017-03-15 20:21:38 +10:00
mieciu
66d78a7d74 Update README.md 2017-03-15 11:14:00 +01:00
Bradley Cicenas
e62a8881a2 add brew install steps 2017-03-15 19:45:41 +10:00
Bradley Cicenas
a5b2e7b074 update aur link 2017-03-15 12:49:42 +10:00
12 changed files with 119 additions and 40 deletions

View File

@@ -1,10 +1,3 @@
FROM quay.io/vektorcloud/glibc:latest FROM scratch
COPY ./ctop /ctop
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
ENTRYPOINT ["/ctop"] ENTRYPOINT ["/ctop"]

12
Dockerfile_build Normal file
View 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
View 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

View File

@@ -1,4 +1,5 @@
<p align="center"><img width="200px" src="/_docs/img/logo.png" alt="ctop"/></p> <p align="center"><img width="200px" src="/_docs/img/logo.png" alt="ctop"/></p>
# #
Top-like interface for container metrics Top-like interface for container metrics
@@ -17,16 +18,18 @@ Fetch the [latest release](https://github.com/bcicen/ctop/releases) for your pla
#### Linux #### Linux
```bash ```bash
wget https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-linux-amd64 -O ctop sudo wget https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-linux-amd64 -O /usr/local/bin/ctop
sudo mv ctop /usr/local/bin/
sudo chmod +x /usr/local/bin/ctop sudo chmod +x /usr/local/bin/ctop
``` ```
#### OS X #### OS X
```bash ```bash
curl -Lo ctop https://github.com/bcicen/ctop/releases/download/v0.5/ctop-0.5-darwin-amd64 brew install ctop
sudo mv ctop /usr/local/bin/ ```
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 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 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 ## Building
To build `ctop` from source, ensure you have a recent version of [glide](http://glide.sh/) installed and run: Build steps can be found [here][build].
```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
```
## Usage ## Usage
@@ -80,4 +76,5 @@ s | Select container sort field
r | Reverse container sort order r | Reverse container sort order
q | Quit ctop q | Quit ctop
[build]: _docs/build.md
[expanded_view]: _docs/expanded.md [expanded_view]: _docs/expanded.md

View File

@@ -1 +1 @@
0.5 0.5.1

20
_docs/build.md Normal file
View 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
View 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...
...
```

View File

@@ -7,7 +7,7 @@ machine:
dependencies: dependencies:
override: override:
- docker info - docker info
- docker build --build-arg CTOP_VERSION=$(cat VERSION) -t ctop . - make image
test: test:
override: override:

View File

@@ -18,7 +18,6 @@ func Init() {
GlobalParams = append(GlobalParams, p) GlobalParams = append(GlobalParams, p)
log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val)) log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
} }
for _, s := range switches { for _, s := range switches {
GlobalSwitches = append(GlobalSwitches, s) GlobalSwitches = append(GlobalSwitches, s)
log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val) log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)

View File

@@ -17,11 +17,6 @@ var switches = []*Switch{
Val: true, Val: true,
Label: "Enable Status Header", Label: "Enable Status Header",
}, },
&Switch{
Key: "loggingEnabled",
Val: false,
Label: "Enable Logging Server",
},
} }
type Switch struct { type Switch struct {

View File

@@ -1,6 +1,7 @@
package logging package logging
import ( import (
"os"
"time" "time"
"github.com/op/go-logging" "github.com/op/go-logging"
@@ -13,7 +14,7 @@ const (
var ( var (
Log *CTopLogger Log *CTopLogger
exited bool exited bool
level = logging.INFO level = logging.INFO // default level
format = logging.MustStringFormatter( format = logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`, `%{color}%{time:15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
) )
@@ -33,6 +34,11 @@ func Init() *CTopLogger {
logging.NewMemoryBackend(size), logging.NewMemoryBackend(size),
} }
if debugMode() {
level = logging.DEBUG
StartServer()
}
backendLvl := logging.AddModuleLevel(Log.backend) backendLvl := logging.AddModuleLevel(Log.backend)
backendLvl.SetLevel(level, "") backendLvl.SetLevel(level, "")
@@ -71,3 +77,5 @@ func (log *CTopLogger) Exit() {
exited = true exited = true
StopServer() StopServer()
} }
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }

15
main.go
View File

@@ -25,9 +25,6 @@ var (
func main() { func main() {
defer panicExit() defer panicExit()
// init global config
config.Init()
// parse command line arguments // parse command line arguments
var versionFlag = flag.Bool("v", false, "output version information and exit") var versionFlag = flag.Bool("v", false, "output version information and exit")
var helpFlag = flag.Bool("h", false, "display this help dialog") var helpFlag = flag.Bool("h", false, "display this help dialog")
@@ -48,6 +45,12 @@ func main() {
os.Exit(0) os.Exit(0)
} }
// init logger
log = logging.Init()
// init global config
config.Init()
// override default config values with command line flags // override default config values with command line flags
if *filterFlag != "" { if *filterFlag != "" {
config.Update("filterStr", *filterFlag) config.Update("filterStr", *filterFlag)
@@ -66,12 +69,6 @@ func main() {
config.Toggle("sortReversed") config.Toggle("sortReversed")
} }
// init logger
log = logging.Init()
if config.GetSwitchVal("loggingEnabled") {
logging.StartServer()
}
// init ui // init ui
if *invertFlag { if *invertFlag {
InvertColorMap() InvertColorMap()