Skip to content

Commit 369b045

Browse files
committed
Merge branch 'FEAT/web-dashboard' of https://github.com/bisohns/saido into FEAT/web-dashboard
2 parents 50dbf50 + 95e95d7 commit 369b045

33 files changed

+481
-205
lines changed

.air.toml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: goreleaser
2+
on:
3+
push:
4+
branches: [main]
5+
tags:
6+
- 'v*'
7+
jobs:
8+
goreleaser:
9+
runs-on: ubuntu-latest
10+
if: success() && startsWith(github.ref, 'refs/tags/')
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
- uses: actions/setup-go@v3
16+
with:
17+
go-version: '>=1.19.3'
18+
cache: true
19+
- run: make dependencies
20+
- run: make build-frontend
21+
- uses: goreleaser/goreleaser-action@v2
22+
with:
23+
distribution: goreleaser
24+
version: latest
25+
args: release --rm-dist
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
28+

.github/workflows/test-macos.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
on:
22
push:
3-
branches: [ main, develop ]
3+
branches: [ main, develop]
44
pull_request:
5-
branches: [ main ]
5+
branches: [ main]
66
name: Test-MacOs
77
jobs:
88
test:
@@ -11,11 +11,16 @@ jobs:
1111
- name: Install Go
1212
uses: actions/setup-go@v2
1313
with:
14-
go-version: 1.16
14+
go-version: '>=1.16'
1515
- name: Checkout code
1616
uses: actions/checkout@v2
1717
- name: Setup config script
1818
# using locals for mac-OS because github CI mac platforms don't have docker
19-
run: make prep-ci-local
19+
run: |
20+
make prep-ci-local
21+
make dependencies
22+
make build-frontend
2023
- name: Test
21-
run: go test -v ./...
24+
run: |
25+
go mod tidy
26+
go test -v ./...

.github/workflows/test-ssh.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
on:
22
push:
3-
branches: [ main, develop ]
3+
branches: [ main, develop]
44
pull_request:
5-
branches: [ main ]
5+
branches: [ main]
66
name: Test-Linux
77
jobs:
88
test:
@@ -11,11 +11,16 @@ jobs:
1111
- name: Install Go
1212
uses: actions/setup-go@v2
1313
with:
14-
go-version: 1.16
14+
go-version: '>=1.16'
1515
- name: Checkout code
1616
uses: actions/checkout@v2
1717
- name: Setup SSH server and config
1818
# run docker ssh container for ssh tests
19-
run: make prep-ci-ssh
19+
run: |
20+
make prep-ci-ssh
21+
make dependencies
22+
make build-frontend
2023
- name: Test
21-
run: go test -v ./...
24+
run: |
25+
go mod tidy
26+
go test -v ./...

.github/workflows/test-windows.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
on:
22
push:
3-
branches: [ main, develop ]
3+
branches: [ main, develop]
44
pull_request:
5-
branches: [ main ]
5+
branches: [ main]
66
name: Test-Windows
77
jobs:
88
test:
@@ -11,7 +11,7 @@ jobs:
1111
- name: Install Go
1212
uses: actions/setup-go@v2
1313
with:
14-
go-version: 1.16
14+
go-version: '>=1.16'
1515
- name: Checkout code
1616
uses: actions/checkout@v2
1717
- name: Choco Install make
@@ -20,6 +20,11 @@ jobs:
2020
args: install make
2121
- name: Setup config script
2222
# using locals for Windows because github CI Windows platforms don't have docker
23-
run: make prep-ci-local-windows
23+
run: |
24+
make prep-ci-local-windows
25+
make dependencies
26+
make build-frontend
2427
- name: Test
25-
run: go test -v ./...
28+
run: |
29+
go mod tidy
30+
go test -v ./...

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ ssh-key/ci/
1515
config-ci.yaml
1616
config-test.yaml
1717
tmp/
18+
cmd/build/
19+
*-packr.go
20+
.air.toml

.goreleaser.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
- go generate ./...
5+
builds:
6+
- env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
- windows
11+
- darwin
12+
archives:
13+
- replacements:
14+
darwin: Darwin
15+
linux: Linux
16+
windows: Windows
17+
386: i386
18+
amd64: x86_64
19+
checksum:
20+
name_template: 'checksums.txt'
21+
#snapshot:
22+
# name_template: "{{ incpatch .Version }}-next"
23+
changelog:
24+
sort: asc
25+
filters:
26+
exclude:
27+
- '^docs:'
28+
- '^test:'
29+
- '^intergration:'
30+
- '^assets:'
31+
nfpms:
32+
- maintainer: Bisohns Corp.
33+
description: YAML based tool for monitoring metrics across multiple hosts
34+
homepage: https://github.com/bisohns/saido
35+
license: Apache License 2.0
36+
formats:
37+
- deb
38+
- rpm
39+
- apk

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
version=fake
2+
ifeq ($(OS),Windows_NT)
3+
bin=main.exe
4+
build_bin=tmp\main.exe
5+
else
6+
bin=main
7+
build_bin=tmp/main
8+
endif
29
# Example:
310
# make
411
# make prep-ci-ssh
@@ -31,3 +38,23 @@ else
3138
upgrade:
3239
@echo "Version not set - use syntax \`make upgrade version=0.x.x\`"
3340
endif
41+
42+
dependencies:
43+
ifeq ($(bin),main.exe)
44+
@make prep-ci-local-windows
45+
yarn add react-scripts@latest
46+
else
47+
@make prep-ci-local
48+
endif
49+
go get .
50+
cd web && yarn install && cd ..
51+
52+
.PHONY: build-frontend
53+
build-frontend:
54+
cd web && export BUILD_PATH=../cmd/build && CI=false yarn build && cd ..
55+
56+
.PHONY: serve-backend
57+
serve-backend:
58+
air --build.cmd "go build -o ./tmp/$(bin) ." --build.bin "$(build_bin)" --build.exclude_dir "assets,docs,tmp,web,scripts,ssh-key,.github,.git" --build.include_ext "go,yaml,html,js" --build.exclude_file "config.example.yaml" --build.args_bin "dashboard,--config,config-test.yaml" --build.stop_on_error true --misc.clean_on_exit true --log.time true
59+
60+
app: build-frontend serve-backend

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,28 @@ For personal usage, install latest from [Github Releases](https://github.com/bis
1919

2020
```bash
2121
# binary is downloaded and named as saido
22-
saido api
22+
saido dashboard --config config.yaml --port 3000
2323
```
2424

2525

2626
### Development
2727

28-
With Golang installed, run
28+
#### Requirements
29+
- [Golang](https://go.dev/doc/install)
30+
- [Docker](https://docs.docker.com/get-docker/)
31+
- [Yarn](https://classic.yarnpkg.com/lang/en/docs/install/)
32+
- [Air](https://github.com/cosmtrek/air)
2933

3034
```bash
3135
git clone https://github.com/bisohns/saido
3236
cd saido
33-
## Update Golang dependencies
34-
go get .
37+
## Update dependencies
38+
make dependencies
3539

36-
## Update yarn dependencies
37-
cd web
38-
yarn install
40+
# Build and serve frontend
41+
make app
3942

40-
# Run websocket server and serve frontend
41-
go run main.go dashboard --config config-test.yaml
43+
# Modify generated `config-test.yaml` file and air would reload server
4244
```
4345

4446
## Deployment

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (client *Client) Write() {
2121
if err != nil {
2222
log.Error("Error inside client write ", err)
2323
// check socket connection has been closed and end writer
24-
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) {
24+
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure, websocket.CloseInternalServerErr) || err == websocket.ErrCloseSent {
2525
return
2626
}
2727
}

client/controller.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ func (hosts *HostsController) sendMetric(host config.Host, client *Client) {
7474
hosts.resetDriver(host)
7575
}
7676
for metric, custom := range hosts.Info.Metrics {
77-
driver := hosts.getDriver(host.Address)
78-
initializedMetric, err := inspector.Init(metric, driver, custom)
77+
inspectorDriver := hosts.getDriver(host.Address)
78+
initializedMetric, err := inspector.Init(metric, inspectorDriver, custom)
7979
if err != nil {
8080
log.Error(err)
8181
}
@@ -86,7 +86,7 @@ func (hosts *HostsController) sendMetric(host config.Host, client *Client) {
8686
message := &SendMessage{
8787
Message: Message{
8888
Host: host.Address,
89-
Platform: (*driver).GetDetails().Name,
89+
Platform: (*inspectorDriver).GetDetails().Name,
9090
Name: metric,
9191
Data: unmarsh,
9292
},
@@ -99,12 +99,15 @@ func (hosts *HostsController) sendMetric(host config.Host, client *Client) {
9999
// check for error 127 which means command was not found
100100
var errorContent string
101101
if !strings.Contains(fmt.Sprintf("%s", err), "127") {
102-
errorContent = fmt.Sprintf("Could not retrieve metric %s from driver %s with error %s, resetting connection...", metric, host.Address, err)
102+
errorContent = fmt.Sprintf("Could not retrieve metric %s from driver %s with error %s", metric, host.Address, err)
103103
} else {
104104
errorContent = fmt.Sprintf("Command %s not found on driver %s", metric, host.Address)
105105
}
106-
log.Error(errorContent)
107-
hosts.resetDriver(host)
106+
log.Debug(errorContent)
107+
//FIXME: what kind of errors do we especially want to reset driver for
108+
if _, ok := err.(*driver.SSHConnectError); ok {
109+
hosts.resetDriver(host)
110+
}
108111
message := &SendMessage{
109112
Message: ErrorMessage{
110113
Error: errorContent,
@@ -128,7 +131,7 @@ func (hosts *HostsController) Poll(client *Client) {
128131
go hosts.sendMetric(host, client)
129132
}
130133
}
131-
log.Infof("Delaying for %d seconds", hosts.Info.PollInterval)
134+
log.Debugf("Delaying for %d seconds", hosts.Info.PollInterval)
132135
time.Sleep(time.Duration(hosts.Info.PollInterval) * time.Second)
133136
}
134137
}

0 commit comments

Comments
 (0)