2016-12-22 22:04:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-03-03 07:57:26 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2017-02-07 03:33:09 +00:00
|
|
|
"github.com/bcicen/ctop/config"
|
2017-03-06 03:03:05 +00:00
|
|
|
"github.com/bcicen/ctop/cwidgets/compact"
|
2017-02-04 02:01:52 +00:00
|
|
|
"github.com/bcicen/ctop/logging"
|
2017-03-06 03:03:05 +00:00
|
|
|
"github.com/bcicen/ctop/widgets"
|
2017-01-01 22:48:35 +00:00
|
|
|
ui "github.com/gizak/termui"
|
2016-12-22 22:04:21 +00:00
|
|
|
)
|
|
|
|
|
2017-03-06 03:03:05 +00:00
|
|
|
var (
|
2017-03-07 01:04:45 +00:00
|
|
|
build = "none"
|
2017-03-07 00:13:48 +00:00
|
|
|
version = "dev-build"
|
|
|
|
|
2017-03-06 03:03:05 +00:00
|
|
|
log *logging.CTopLogger
|
|
|
|
cursor *GridCursor
|
2017-03-07 01:04:45 +00:00
|
|
|
cGrid *compact.CompactGrid
|
|
|
|
header *widgets.CTopHeader
|
2017-03-06 03:03:05 +00:00
|
|
|
)
|
2017-02-04 02:01:52 +00:00
|
|
|
|
2016-12-25 23:05:22 +00:00
|
|
|
func main() {
|
2017-03-07 01:04:45 +00:00
|
|
|
readArgs()
|
|
|
|
defer panicExit()
|
|
|
|
|
|
|
|
// init ui
|
2017-03-07 23:40:03 +00:00
|
|
|
ui.ColorMap = ColorMap // override default colormap
|
2017-03-07 01:04:45 +00:00
|
|
|
if err := ui.Init(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer ui.Close()
|
2017-03-06 03:03:05 +00:00
|
|
|
|
2017-03-07 01:04:45 +00:00
|
|
|
// init global config
|
2017-02-16 03:49:41 +00:00
|
|
|
config.Init()
|
2017-03-07 00:09:46 +00:00
|
|
|
|
|
|
|
// init logger
|
2017-02-12 05:14:50 +00:00
|
|
|
log = logging.Init()
|
2017-02-16 04:06:05 +00:00
|
|
|
if config.GetSwitchVal("loggingEnabled") {
|
2017-02-17 06:48:38 +00:00
|
|
|
logging.StartServer()
|
2017-02-12 05:14:50 +00:00
|
|
|
}
|
2017-03-07 00:09:46 +00:00
|
|
|
|
2017-03-07 01:04:45 +00:00
|
|
|
// init grid, cursor, header
|
2017-03-07 00:09:46 +00:00
|
|
|
cursor = NewGridCursor()
|
2017-03-07 01:04:45 +00:00
|
|
|
cGrid = compact.NewCompactGrid()
|
|
|
|
header = widgets.NewCTopHeader()
|
2017-01-03 17:37:09 +00:00
|
|
|
|
2017-01-01 22:42:13 +00:00
|
|
|
for {
|
2017-03-06 03:03:05 +00:00
|
|
|
exit := Display()
|
2017-01-01 22:42:13 +00:00
|
|
|
if exit {
|
2017-02-05 00:25:30 +00:00
|
|
|
log.Notice("shutting down")
|
|
|
|
log.Exit()
|
2017-01-01 22:48:35 +00:00
|
|
|
return
|
2017-01-01 22:42:13 +00:00
|
|
|
}
|
2016-12-22 22:04:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-07 01:04:45 +00:00
|
|
|
|
|
|
|
func readArgs() {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, arg := range os.Args[1:] {
|
|
|
|
switch arg {
|
|
|
|
case "-v", "version":
|
|
|
|
printVersion()
|
|
|
|
os.Exit(0)
|
|
|
|
case "-h", "help":
|
|
|
|
printHelp()
|
|
|
|
os.Exit(0)
|
|
|
|
default:
|
|
|
|
fmt.Printf("invalid option or argument: \"%s\"\n", arg)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func panicExit() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
ui.Clear()
|
|
|
|
fmt.Printf("panic: %s\n", r)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-08 23:40:35 +00:00
|
|
|
var helpMsg = `ctop - container metric viewer
|
2017-03-07 01:04:45 +00:00
|
|
|
|
|
|
|
usage: ctop [options]
|
|
|
|
|
|
|
|
options:
|
|
|
|
-h display this help dialog
|
|
|
|
-v output version information and exit
|
|
|
|
`
|
|
|
|
|
|
|
|
func printHelp() {
|
|
|
|
fmt.Println(helpMsg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func printVersion() {
|
2017-03-08 23:40:35 +00:00
|
|
|
fmt.Printf("ctop version %v, build %v\n", version, build)
|
2017-03-07 01:04:45 +00:00
|
|
|
}
|