Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bisohns/saido into FEAT/web-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurudeen38 committed Nov 10, 2022
2 parents dfc350e + 6204f59 commit f8b3a38
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
55 changes: 55 additions & 0 deletions .air.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format

# Working directory
# . or absolute path, please note that the directories following must be under root.
root = "."
tmp_dir = "tmp"

[build]
# Just plain old shell command. You could use `make` as well.
cmd = "go build -o ./tmp/main ."
# Binary file yields from `cmd`.
bin = "tmp/main"
# Watch these filename extensions.
include_ext = ["go", "tpl", "tmpl", "html", "yaml"]
# Ignore these filename extensions or directories.
exclude_dir = ["assets", "docs", "tmp", "web", "scripts", "ssh-key", ".github", ".git"]
# Watch these directories if you specified.
include_dir = []
# Watch these files.
include_file = []
# Exclude files.
exclude_file = ["config.example.yaml"]
# Exclude specific regular expressions.
exclude_regex = ["_test\\.go"]
# Exclude unchanged files.
exclude_unchanged = true
# Follow symlink for directories
follow_symlink = true
# This log file places in your tmp_dir.
log = "air.log"
# It's not necessary to trigger build each time file changes if it's too frequent.
delay = 0 # ms
# Stop running old binary when build errors occur.
stop_on_error = true
# Send Interrupt signal before killing process (windows does not support this feature)
send_interrupt = false
# Delay after sending Interrupt signal
kill_delay = 500 # ms
# Add additional arguments when running binary (bin/full_bin). Will run './tmp/main hello world'.
args_bin = ["dashboard", "--config", "config-test.yaml"]

[log]
# Show log time
time = false

[color]
# Customize each part's color. If no color found, use the raw app log.
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"

[misc]
# Delete tmp directory on exit
clean_on_exit = true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ docker-compose.yaml
ssh-key/ci/
config-ci.yaml
config-test.yaml
tmp/
4 changes: 3 additions & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ metrics:
memory:
tcp:
# custom command to show uptime
custom: "cat /proc/uptime"
custom-uptime: "cat /proc/uptime"
custom-dir: 'dir C:\'
custom-echo: 'echo $HOME'
poll-interval: 30
27 changes: 17 additions & 10 deletions inspector/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ package inspector
import (
"errors"
"fmt"
"strings"

"github.com/bisohns/saido/driver"
)

// CustomCommand : every custom command must be prefixed by this
var CustomCommand = `custom`

// Inspector : defines a particular metric supported by a driver
type Inspector interface {
Parse(output string)
Expand All @@ -18,22 +22,22 @@ type Inspector interface {
type NewInspector func(driver *driver.Driver, custom ...string) (Inspector, error)

var inspectorMap = map[string]NewInspector{
`disk`: NewDF,
`docker`: NewDockerStats,
`uptime`: NewUptime,
`memory`: NewMemInfo,
`process`: NewProcess,
`loadavg`: NewLoadAvg,
`tcp`: NewTcp,
`custom`: NewCustom,
`disk`: NewDF,
`docker`: NewDockerStats,
`uptime`: NewUptime,
`memory`: NewMemInfo,
`process`: NewProcess,
`loadavg`: NewLoadAvg,
`tcp`: NewTcp,
CustomCommand: NewCustom,
// NOTE: Inactive for now
`responsetime`: NewResponseTime,
}

// Valid : checks if inspector is a valid inspector
func Valid(name string) bool {
for key, _ := range inspectorMap {
if name == key {
for key := range inspectorMap {
if name == key || strings.HasPrefix(name, CustomCommand) {
return true
}
}
Expand All @@ -42,6 +46,9 @@ func Valid(name string) bool {

// Init : initializes the specified inspector using name and driver
func Init(name string, driver *driver.Driver, custom ...string) (Inspector, error) {
if strings.HasPrefix(name, CustomCommand) {
name = "custom"
}
val, ok := inspectorMap[name]
if ok {
inspector, err := val(driver, custom...)
Expand Down

0 comments on commit f8b3a38

Please sign in to comment.