Skip to content

Commit

Permalink
Refactor: remove split into dynamic/static modes
Browse files Browse the repository at this point in the history
as only the latter was implemented. Also "static" was
a bad name, invalidating what the project name promises...

Call "interactive" what use to by "dynamic".
  • Loading branch information
gdubicki committed Mar 20, 2022
1 parent a9f6dbe commit 8b932ce
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 90 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ it, then something IS wrong with the server, isn't it?).
![Dynamotd](dynamotd.png)

* **Useful default info** - CPU load, memory use, disk space use etc.,
* **Semantic colors** - <span style="color:red">red</span> ~ problem, <span style="color:orange">orange</span> ~ warning.
* **Semantic colors** - <span style="color:red">red</span> ~ problem, <span style="color:yellow">yellow</span> ~ warning.
* **Customizable** - reorder or remove lines,
* **Fast** - native app,

Expand All @@ -27,8 +27,8 @@ Check out the available command-line arguments by running `dynamotd -help`.


If you like it you can add it to your system as a dynamic MOTD by following one of these great guides:
* [Ubuntu/Debian](https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/),
* (TODO: add RedHat/Centos and more)
* [Debian/Ubuntu](https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/),
* (TODO: add RedHat/Centos/Rocky and more)

## Building

Expand All @@ -45,11 +45,10 @@ How-to build:
These features will be implemented in the future:

* **Pluggable** - add custom lines with any label and any command(s) output as the value,
* **Static and dynamic mode** - the former just prints the current state, the latter updates every 2 seconds,
like htop,
* **Keyboard shortcuts** - to run popular tools (in dynamic mode only) like htop, iftop etc.
* **Interactive mode** - show the output like `htop`, updated every 2 seconds,
* **Keyboard shortcuts** - in interactive mode only, to run popular tools like htop, iftop etc.
* **Circuit-breaker** - minimal info mode in case of server overload detection,
* **Native packages for Centos and Ubuntu** - so you can easily install it on (almost) all of your servers.
* **Native packages for RedHat/Centos/Rocky and Debian/Ubuntu** - easy install it on (almost) all of your servers.

We also don't have the tests yet and the building pipeline (but they WILL be created if we decide to go ahead with the project).

Expand Down
6 changes: 0 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var MaxRows = 40
var config = viper.New()

func init() {
config.SetDefault("mode", "static")
config.SetDefault("rows", []string{
"timestamp",
"",
Expand Down Expand Up @@ -40,11 +39,6 @@ func init() {
}
}

func IsModeStatic() bool {
mode := config.GetString("mode")
return mode == "static"
}

func GetRows() []Row {
var rows []Row

Expand Down
6 changes: 1 addition & 5 deletions dynamotd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ func main() {
}

rows := GetRows()
if IsModeStatic() {
PrintStatic(rows)
} else {
ShowDynamic(rows)
}
Print(rows)
}
4 changes: 0 additions & 4 deletions dynamotd.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# This is a configuration file example.
# It is completely optional. The values below represent the defaults.

mode: static

example_data: true

rows:
- "timestamp"
- ""
Expand Down
48 changes: 0 additions & 48 deletions dynamotd/dynamic.go

This file was deleted.

8 changes: 4 additions & 4 deletions dynamotd/static.go → dynamotd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"github.com/fatih/color"
)

func PrintStatic(rows []Row) {
func Print(rows []Row) {
for _, row := range rows {
printStaticRow(row)
printRow(row)
}
}

func printStaticRow(row Row) {
func printRow(row Row) {
if row.isEmptyLine() {
fmt.Print("\n")
} else {
Expand All @@ -35,7 +35,7 @@ func getStringToPrint(colorString ColorString) string {
// generate function that prints in given color
// (https://github.com/fatih/color#insert-into-noncolor-strings-sprintfunc)
// TODO: pregenerate (store in struct?) the color printing functions
colorPrint := color.New(colorString.Color.staticColor).SprintFunc()
colorPrint := color.New(colorString.Color).SprintFunc()

return fmt.Sprintf("%s", colorPrint(colorString.Text))
}
18 changes: 7 additions & 11 deletions dynamotd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,17 @@ type ColorText struct {
}

type ColorString struct {
Color Color
Color color.Attribute
Text string
}

type Color struct {
staticColor color.Attribute
dynamicColor string
}
var LabelColor = color.FgWhite

var LabelColor = Color{color.FgWhite, "white"}
var ValueDescriptionColor = Color{color.FgWhite, "white"}
var ValueNeutralColor = Color{color.FgBlue, "lightblue"}
var ValueOkColor = Color{color.FgGreen, "lightgreen"}
var ValueWarningColor = Color{color.FgYellow, "lightgoldenrodyellow"}
var ValueCriticalColor = Color{color.FgRed, "indianred"}
var ValueDescriptionColor = color.FgWhite
var ValueNeutralColor = color.FgBlue
var ValueOkColor = color.FgGreen
var ValueWarningColor = color.FgYellow
var ValueCriticalColor = color.FgRed

func ValueDescription(text string) ColorString {
return ColorString{ValueDescriptionColor, text}
Expand Down
3 changes: 2 additions & 1 deletion plugins/diskspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugins
import (
"fmt"
"github.com/Tonyfilla/go-humanize"
"github.com/fatih/color"
. "github.com/gdubicki/dynamotd/dynamotd"
"github.com/minio/minio/pkg/disk"
)
Expand All @@ -11,7 +12,7 @@ func DiskSpace(path string) Row {
var warningThreshold = 75.0
var criticalThreshold = 90.0

var color Color
var color color.Attribute

di, err := disk.GetInfo(path)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion plugins/ip.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package plugins

import (
"github.com/fatih/color"
. "github.com/gdubicki/dynamotd/dynamotd"
"io/ioutil"
"net"
Expand All @@ -13,7 +14,7 @@ func Ip() Row {
localIP := getLocalIP()
externalIP := getExternalIP()

var localIPcolor, externalIPcolor Color
var localIPcolor, externalIPcolor color.Attribute

if strings.Contains(localIP, "can't") {
localIPcolor = ValueCriticalColor
Expand Down
3 changes: 2 additions & 1 deletion plugins/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package plugins
import (
"fmt"
"github.com/Tonyfilla/go-humanize"
"github.com/fatih/color"
. "github.com/gdubicki/dynamotd/dynamotd"
memoryLib "github.com/mackerelio/go-osstat/memory"
)
Expand All @@ -11,7 +12,7 @@ func Memory() Row {
var warningThreshold = 90.0
var criticalThreshold = 95.0

var color Color
var color color.Attribute

memoryStat, err := memoryLib.Get()
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions plugins/uptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugins

import (
"fmt"
"github.com/fatih/color"
. "github.com/gdubicki/dynamotd/dynamotd"
"github.com/shirou/gopsutil/host"
)
Expand All @@ -18,8 +19,8 @@ func Uptime() Row {
}
}

func getUptimeColorAndString() (Color, string) {
var color Color
func getUptimeColorAndString() (color.Attribute, string) {
var color color.Attribute

uptime, _ := host.Uptime()

Expand Down

0 comments on commit 8b932ce

Please sign in to comment.