-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from charlie-haley/feat/v3
feat: controller metrics, better naming, toggle collectors
- Loading branch information
Showing
12 changed files
with
376 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
name: Check | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout the code | ||
uses: actions/checkout@v1 | ||
|
||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v1 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
- name: Lint with golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
|
||
- name: Run GoReleaser check | ||
uses: goreleaser/[email protected] | ||
with: | ||
version: latest | ||
args: build --skip-validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# dist folder | ||
/dist | ||
|
||
# generated metrics table | ||
gen-metrics-table.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
lint: | ||
golangci-lint run | ||
|
||
generate-metrics-table: | ||
sh ./scripts/metric-markdown-table.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func (c *Client) GetController() (*Controller, error) { | ||
loggedIn, err := c.IsLoggedIn() | ||
if err != nil { | ||
log.Error(err) | ||
return nil, err | ||
} | ||
if !loggedIn { | ||
log.Info(fmt.Errorf("not logged in, logging in with user: %s", c.Config.String("username"))) | ||
err := c.Login() | ||
if err != nil || c.token == "" { | ||
log.Error(fmt.Errorf("failed to login: %s", err)) | ||
return nil, err | ||
} | ||
} | ||
|
||
url := fmt.Sprintf("%s/%s/api/v2/maintenance/controllerStatus?", c.Config.String("host"), c.omadaCID) | ||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
log.Error(err) | ||
return nil, err | ||
} | ||
|
||
setHeaders(req, c.token) | ||
resp, err := c.httpClient.Do(req) | ||
if err != nil { | ||
log.Error(err) | ||
return nil, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
log.Error(err) | ||
return nil, err | ||
} | ||
|
||
controllerData := controllerResponse{} | ||
err = json.Unmarshal(body, &controllerData) | ||
|
||
return &controllerData.Result, err | ||
} | ||
|
||
type controllerResponse struct { | ||
Result Controller `json:"result"` | ||
} | ||
type Controller struct { | ||
Name string `json:"name"` | ||
MacAddress string `json:"macAddress"` | ||
FirmwareVersion string `json:"firmwareVersion"` | ||
ControllerVersion string `json:"controllerVersion"` | ||
Model string `json:"model"` | ||
Uptime float64 `json:"upTime"` | ||
Storage []hwcStorage `json:"hwcStorage"` | ||
} | ||
type hwcStorage struct { | ||
Name string `json:"name"` | ||
Total float64 `json:"totalStorage"` | ||
Used float64 `json:"usedStorage"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.