Skip to content

Commit

Permalink
Documentation and example
Browse files Browse the repository at this point in the history
  • Loading branch information
spacez320 committed Jan 22, 2025
1 parent 1285947 commit 20e4234
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 13 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ You can also execute Shui from standard input, which works like query mode.
while true; do uptime; sleep 1; done | shui
```

### Configuration

Shui can accept instruction from flags or from a configuration file. By default it will look for a
`shui.toml` in the user's config directory (see: <https://pkg.go.dev/os#UserConfigDir>), but one may
also be provided explicitly.

```sh
shui --config path/to/config # Default is "${HOME}/.config/shui/shui.toml".
```

See [examples/shui.toml](examples/shui.toml) for an example.

> NOTE: Most options may be mixed, but queries and expressions may only be supplied with flags or
> configuration, not both.
### Persistence

Shui, by default, will store results and load them when re-executing the same query.
Expand Down
26 changes: 13 additions & 13 deletions cmd/shui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,19 @@ var (
// Aliases to apply for configuration settings, mainly to account for differences between flags
// (the left column) and configuration files (the right column).
configurationAliases = map[string]string{
"elasticsearch-addr": "elasticsearch.addr",
"elasticsearch-index": "elasticsearch.index",
"elasticsearch-password": "elasticsearch.password",
"elasticsearch-user": "elasticsearch.user",
"outer-padding-bottom": "tui.padding.bottom",
"outer-padding-left": "tui.padding.left",
"outer-padding-right": "tui.padding.right",
"outer-padding-top": "tui.padding.top",
"prometheus-exporter": "prometheus.exporter",
"prometheus-pushgateway": "prometheus.pushgateway",
"show-help": "tui.show.help",
"show-logs": "tui.show.logs",
"show-status": "tui.show.status",
"elasticsearch.addr": "elasticsearch-addr",
"elasticsearch.index": "elasticsearch-index",
"elasticsearch.password": "elasticsearch-password",
"elasticsearch.user": "elasticsearch-user",
"tui.padding.bottom": "outer-padding-bottom",
"tui.padding.left": "outer-padding-left",
"tui.padding.right": "outer-padding-right",
"tui.padding.top": "outer-padding-top",
"prometheus.exporter": "prometheus-exporter",
"prometheus.pushgateway": "prometheus-pushgateway",
"tui.show.help": "show-help",
"tui.show.logs": "show-logs",
"tui.show.status": "show-status",
}

logger = log.Default() // Logging system.
Expand Down
52 changes: 52 additions & 0 deletions example/shui.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Sample configuration file for Shui that reads CPU load averages.

count = -1
display = 4
history = false
log-level = "debug"

filters = [
"CPU load average"
]

labels = [
"CPU load average"
]

expressions = [
"get(result, 'CPU load average') * 100"
]

[tui.padding]
bottom = 0
top = 0
left = 0
right = 0

[tui.show]
help = true
logs = true
status = true

# 1 minute CPU load average
[[query]]
command = "uptime | awk '{print $10}' | tr -d ','"

# 5 minute CPU load average
[[query]]
command = "uptime | awk '{print $11}' | tr -d ','"

# 15 minute CPU load average
[[query]]
command = "uptime | awk '{print $12}' | tr -d ','"

# [elasticsearch]
# addr = "https://localhost:9200"
# index = "shui"
# password = ""
# user = "elastic"

# [prometheus]
# exporter = "127.0.0.1:9898"
# pushgateway = "127.0.0.1:9091"

0 comments on commit 20e4234

Please sign in to comment.