Compare commits

...

17 Commits

Author SHA1 Message Date
Kevin Schoon
47b27a7786 vendor dependencies with glide 2017-03-13 08:05:40 +11:00
Bradley Cicenas
b28beed3ee v0.4.1 2017-03-10 20:20:00 +11:00
Bradley Cicenas
2e51406d00 add lock to container map in dockersource 2017-03-10 20:10:39 +11:00
Bradley Cicenas
c84b52ce40 add docker image usage to readme 2017-03-10 20:00:00 +11:00
Bradley Cicenas
4ee8cf621a use latest parsed version in dockerfile 2017-03-10 19:51:31 +11:00
Bradley Cicenas
192298c045 add circleci config for docker build 2017-03-10 19:45:04 +11:00
Bradley Cicenas
258536740d build docker image from alpine 2017-03-10 19:37:46 +11:00
bradley
ef69744249 Merge pull request #23 from firecat53/patch-1
Update Dockerfile
2017-03-10 19:19:20 +11:00
Scott Hansen
07f95a04b0 Update Dockerfile
It may not be as easy to read, but combining the three RUN statements together saves you some substantial megabytes:

    ctop_deb_orig        latest              149596353f88        4 seconds ago       187 MB
    ctop_deb_new        latest              d01f954b3adc        2 minutes ago       139 MB

This is because each RUN statement is creating a whole new layer in the image, so you're actually hanging on to all the stuff you were trying to get rid of!

Scott
2017-03-09 20:38:01 -08:00
Bradley Cicenas
b2184bbc6d fixes out of bounds error on filtered selection #7 2017-03-10 12:01:13 +11:00
Bradley Cicenas
96b01eb3b9 add support for TLS via NewClientFromEnv(), remove dockerHost config param 2017-03-10 12:01:13 +11:00
bradley
03d4869361 Merge pull request #14 from francislavoie/master
Add Dockerfile
2017-03-10 11:57:15 +11:00
bradley
4b7257908f Merge pull request #15 from huguesalary/master
Fixing a typo
2017-03-10 11:55:49 +11:00
Hugues Alary
1875013a76 Fixing a typo 2017-03-09 16:16:40 -08:00
Francis Lavoie
dab2f926b9 Add Dockerfile 2017-03-09 19:08:35 -05:00
Bradley Cicenas
ddce54f991 add AUR to README
fix typo
2017-03-10 09:24:44 +11:00
Bradley Cicenas
168e8f3aae implement Buffer() method for ctop header 2017-03-09 19:33:25 +11:00
12 changed files with 183 additions and 21 deletions

7
Dockerfile Normal file
View File

@@ -0,0 +1,7 @@
FROM quay.io/vektorcloud/glibc:latest
RUN ctop_url=$(wget -q -O - https://api.github.com/repos/bcicen/ctop/releases/latest | grep 'browser_' | cut -d\" -f4 |grep 'linux-amd64') && \
wget -q $ctop_url -O /ctop && \
chmod +x /ctop
ENTRYPOINT ["/ctop"]

View File

@@ -3,12 +3,12 @@
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>
as well as an [expanded view][expanded_view] for inspecting a specific container.
ctop currently comes with built-in support for Docker; connectors for other container and cluster systems are planned for future releases.
`ctop` currently comes with built-in support for Docker; connectors for other container and cluster systems are planned for future releases.
## Install
@@ -17,7 +17,7 @@ Fetch the [latest release](https://github.com/bcicen/ctop/releases) for your pla
#### Linux
```bash
wget https://github.com/bcicen/ctop/releases/download/v0.4/ctop-0.4-linux-amd64 -O ctop
wget https://github.com/bcicen/ctop/releases/download/v0.4.1/ctop-0.4.1-linux-amd64 -O ctop
sudo mv ctop /usr/local/bin/
sudo chmod +x /usr/local/bin/ctop
```
@@ -25,14 +25,30 @@ sudo chmod +x /usr/local/bin/ctop
#### OS X
```bash
curl -Lo ctop https://github.com/bcicen/ctop/releases/download/v0.4/ctop-0.4-darwin-amd64
curl -Lo ctop https://github.com/bcicen/ctop/releases/download/v0.4.1/ctop-0.4.1-darwin-amd64
sudo mv ctop /usr/local/bin/
sudo chmod +x /usr/local/bin/ctop
```
or run via Docker:
```bash
docker run -ti -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/)
## Building
To build `ctop` from source ensure you have a recent version of [glide](http://glide.sh/) installed.
```bash
cd $GOPATH/src/github.com/bcicen/ctop
glide install
```
## Usage
ctop requires no arguments and will configure itself using the `DOCKER_HOST` environment variable
`ctop` requires no arguments and will configure itself using the `DOCKER_HOST` environment variable
```bash
export DOCKER_HOST=tcp://127.0.0.1:4243
ctop

View File

@@ -1 +1 @@
0.4
0.4.1

24
circle.yml Normal file
View File

@@ -0,0 +1,24 @@
machine:
services:
- docker
dependencies:
override:
- docker info
- |
if [[ "$CIRCLE_BRANCH" == "master" ]]; then
docker build -t quay.io/vektorlab/ctop:latest .
else
docker build -t quay.io/vektorlab/ctop:${CIRCLE_BRANCH} .
fi
test:
override:
- docker run -t --entrypoint /bin/sh quay.io/vektorlab/ctop:latest -v
deployment:
hub:
branch: master
commands:
- docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS quay.io
- docker push quay.io/vektorlab/ctop:latest

View File

@@ -2,11 +2,6 @@ package config
// defaults
var params = []*Param{
&Param{
Key: "dockerHost",
Val: getEnv("DOCKER_HOST", "unix:///var/run/docker.sock"),
Label: "Docker API URL",
},
&Param{
Key: "filterStr",
Val: "",

View File

@@ -17,7 +17,14 @@ func NewGridCursor() *GridCursor {
}
func (gc *GridCursor) Len() int { return len(gc.filtered) }
func (gc *GridCursor) Selected() *Container { return gc.filtered[gc.Idx()] }
func (gc *GridCursor) Selected() *Container {
idx := gc.Idx()
if idx < gc.Len() {
return gc.filtered[idx]
}
return nil
}
// Refresh containers from source
func (gc *GridCursor) RefreshContainers() (lenChanged bool) {

View File

@@ -16,7 +16,7 @@ func NewInfo(id string) *Info {
p.Height = 4
p.Width = colWidth[0]
p.FgColor = ui.ThemeAttr("par.text.fg")
p.Seperator = false
p.Separator = false
i := &Info{p, make(map[string]string)}
i.Set("id", id)
return i

View File

@@ -3,8 +3,8 @@ package main
import (
"sort"
"strings"
"sync"
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/metrics"
"github.com/fsouza/go-dockerclient"
)
@@ -18,11 +18,12 @@ type DockerContainerSource struct {
client *docker.Client
containers map[string]*Container
needsRefresh chan string // container IDs requiring refresh
lock sync.RWMutex
}
func NewDockerContainerSource() *DockerContainerSource {
// init docker client
client, err := docker.NewClient(config.GetVal("dockerHost"))
client, err := docker.NewClientFromEnv()
if err != nil {
panic(err)
}
@@ -30,6 +31,7 @@ func NewDockerContainerSource() *DockerContainerSource {
client: client,
containers: make(map[string]*Container),
needsRefresh: make(chan string, 60),
lock: sync.RWMutex{},
}
go cm.Loop()
cm.refreshAll()
@@ -113,28 +115,36 @@ func (cm *DockerContainerSource) MustGet(id string) *Container {
collector := metrics.NewDocker(cm.client, id)
// create container
c = NewContainer(id, collector)
cm.lock.Lock()
cm.containers[id] = c
cm.lock.Unlock()
}
return c
}
// Get a single container, by ID
func (cm *DockerContainerSource) Get(id string) (*Container, bool) {
cm.lock.Lock()
c, ok := cm.containers[id]
cm.lock.Unlock()
return c, ok
}
// Remove containers by ID
func (cm *DockerContainerSource) delByID(id string) {
cm.lock.Lock()
delete(cm.containers, id)
cm.lock.Unlock()
log.Infof("removed dead container: %s", id)
}
// Return array of all containers, sorted by field
func (cm *DockerContainerSource) All() (containers Containers) {
cm.lock.Lock()
for _, c := range cm.containers {
containers = append(containers, c)
}
cm.lock.Unlock()
sort.Sort(containers)
containers.Filter()
return containers

85
glide.lock generated Normal file
View File

@@ -0,0 +1,85 @@
hash: c13011881e895378f374b68596a59a0ea6def372b4f5239b2d8aa342eaa46a4b
updated: 2017-03-12T09:53:35.212073637+07:00
imports:
- name: github.com/Azure/go-ansiterm
version: fa152c58bc15761d0200cb75fe958b89a9d4888e
subpackages:
- winterm
- name: github.com/docker/docker
version: ce07fb6b0f1b8765b92022e45f96bd4349812e06
subpackages:
- api/types
- api/types/blkiodev
- api/types/container
- api/types/filters
- api/types/mount
- api/types/network
- api/types/registry
- api/types/strslice
- api/types/swarm
- api/types/versions
- opts
- pkg/archive
- pkg/fileutils
- pkg/homedir
- pkg/idtools
- pkg/ioutils
- pkg/jsonlog
- pkg/jsonmessage
- pkg/longpath
- pkg/pools
- pkg/promise
- pkg/stdcopy
- pkg/system
- pkg/term
- pkg/term/windows
- name: github.com/docker/go-connections
version: a2afab9802043837035592f1c24827fb70766de9
subpackages:
- nat
- name: github.com/docker/go-units
version: 0dadbb0345b35ec7ef35e228dabb8de89a65bf52
- name: github.com/fsouza/go-dockerclient
version: 318513eb1ab27495afbc67f671ba1080513d8aa0
- name: github.com/gizak/termui
version: ea10e6ccee219e572ffad0ac1909f1a17f6db7d6
repo: https://github.com/bcicen/termui
vcs: git
- name: github.com/hashicorp/go-cleanhttp
version: 3573b8b52aa7b37b9358d966a898feb387f62437
- name: github.com/jgautheron/codename-generator
version: 16d037c7cc3c9b552fe4af9828b7338d752dbaf9
- name: github.com/maruel/panicparse
version: 25bcac0d793cf4109483505a0d66e066a3a90a80
subpackages:
- stack
- name: github.com/mattn/go-runewidth
version: 14207d285c6c197daabb5c9793d63e7af9ab2d50
- name: github.com/Microsoft/go-winio
version: fff283ad5116362ca252298cfc9b95828956d85d
- name: github.com/mitchellh/go-wordwrap
version: ad45545899c7b13c020ea92b2072220eefad42b8
- name: github.com/nsf/termbox-go
version: 91bae1bb5fa9ee504905ecbe7043fa30e92feaa3
- name: github.com/nu7hatch/gouuid
version: 179d4d0c4d8d407a32af483c2354df1d2c91e6c3
- name: github.com/op/go-logging
version: b2cb9fa56473e98db8caba80237377e83fe44db5
- name: github.com/opencontainers/runc
version: 31980a53ae7887b2c8f8715d13c3eb486c27b6cf
subpackages:
- libcontainer/system
- libcontainer/user
- name: github.com/Sirupsen/logrus
version: 1deb2db2a6fff8a35532079061b903c3a25eed52
- name: golang.org/x/net
version: a6577fac2d73be281a500b310739095313165611
subpackages:
- context
- context/ctxhttp
- name: golang.org/x/sys
version: 99f16d856c9836c42d24e7ab64ea72916925fa97
subpackages:
- unix
- windows
testImports: []

11
glide.yaml Normal file
View File

@@ -0,0 +1,11 @@
package: github.com/bcicen/ctop
import:
- package: github.com/fsouza/go-dockerclient
- package: github.com/gizak/termui
version: barchart-numfmt
repo: https://github.com/bcicen/termui
vcs: git
- package: github.com/jgautheron/codename-generator
- package: github.com/nu7hatch/gouuid
- package: github.com/op/go-logging
version: ^1.0.0

View File

@@ -28,7 +28,7 @@ func RedrawRows(clr bool) {
log.Debugf("screen cleared")
}
if config.GetSwitchVal("enableHeader") {
header.Render()
ui.Render(header)
}
cGrid.Align()
ui.Render(cGrid)
@@ -132,7 +132,10 @@ func Display() bool {
return false
}
if expand {
ExpandView(cursor.Selected())
c := cursor.Selected()
if c != nil {
ExpandView(c)
}
return false
}
return true

View File

@@ -23,10 +23,14 @@ func NewCTopHeader() *CTopHeader {
}
}
func (c *CTopHeader) Render() {
func (c *CTopHeader) Buffer() ui.Buffer {
buf := ui.NewBuffer()
c.Time.Text = timeStr()
ui.Render(c.bg)
ui.Render(c.Time, c.Count, c.Filter)
buf.Merge(c.bg.Buffer())
buf.Merge(c.Time.Buffer())
buf.Merge(c.Count.Buffer())
buf.Merge(c.Filter.Buffer())
return buf
}
func (c *CTopHeader) Align() {