Skip to content

Commit

Permalink
Add viper/cobra to support a config file
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
Caleb Lloyd authored and caleblloyd committed Jul 6, 2022
1 parent 22c2ef0 commit ae25255
Show file tree
Hide file tree
Showing 15 changed files with 718 additions and 242 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
name: Testing
on: [push, pull_request]
on:
pull_request: {}
push:
branches:
- main

jobs:
test:
strategy:
matrix:
go: [1.17]
os: [ubuntu-latest, macOS-latest]
go: [ 1.18 ]
os: [ ubuntu-latest, macOS-latest ]
runs-on: ${{matrix.os}}
steps:
- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.17
go-version: 1.18
- name: Install deps
shell: bash --noprofile --norc -x -eo pipefail {0}
env:
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-alpine3.15 AS build
FROM golang:1.18-alpine3.16 AS build
COPY . /go/src/nats-surveyor
WORKDIR /go/src/nats-surveyor
ENV GO111MODULE=on
Expand All @@ -7,7 +7,7 @@ RUN go build
FROM alpine:latest as osdeps
RUN apk add --no-cache ca-certificates

FROM alpine:3.15
FROM alpine:3.16
COPY --from=build /go/src/nats-surveyor/nats-surveyor /nats-surveyor
COPY --from=osdeps /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

Expand Down
82 changes: 49 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,34 @@ must be enabled to use surveyor.
## Usage

```text
Usage of ./nats-surveyor:
-a string
Network host to listen on. (default "0.0.0.0")
-addr string
Network host to listen on. (default "0.0.0.0")
-c int
Expected number of servers (default 1)
-creds string
Credentials File for the system account when using jwt authentication
-nkey string
NKey Seed File for the system account when using nkey authenication
-http_pass string
Set the password for HTTP scrapes. NATS bcrypt supported.
-http_user string
Enable basic auth and set user name for HTTP scrapes.
-p int
Port to listen on. (default 7777)
-port int
Port to listen on. (default 7777)
-prefix string
Replace the default prefix for all the metrics.
-s string
NATS Cluster url(s) (default "nats://localhost:4222")
-timeout duration
Polling timeout (default 3s)
-tlscacert string
Client certificate CA for verification (used with HTTPS).
-tlscert string
Server certificate file (Enables HTTPS).
-tlskey string
Private key for server certificate (used with HTTPS).
-version
Show exporter version and exit.
Usage:
nats-surveyor [flags]
Flags:
--accounts Export per account metrics
-a, --addr string Network host to listen on. (default "0.0.0.0")
--config string config file (default is ./nats-surveyor.yaml)
-c, --count int Expected number of servers (default 1)
--creds string Credentials File
-h, --help help for nats-surveyor
--http-pass string Set the password for HTTP scrapes. NATS bcrypt supported.
--http-tlscacert string Client certificate CA for verification (used with HTTPS).
--http-tlscert string Server certificate file (Enables HTTPS).
--http-tlskey string Private key for server certificate (used with HTTPS).
--http-user string Enable basic auth and set user name for HTTP scrapes.
--jetstream string Listen for JetStream Advisories based on config files in a directory.
--nkey string Nkey Seed File
--observe string Listen for observation statistics based on config files in a directory.
--password string NATS user password
-p, --port int Port to listen on. (default 7777)
--prefix string Replace the default prefix for all the metrics.
-s, --servers string NATS Cluster url(s) (default "nats://127.0.0.1:4222")
--timeout duration Polling timeout (default 3s)
--tlscacert string Client certificate CA on NATS connecctions.
--tlscert string Client certificate file for NATS connections.
--tlskey string Client private key for NATS connections.
--user string NATS user name or token
-v, --version version for nats-surveyor
```

At this time, NATS 2.0 System credentials are required for meaningful usage.
Expand All @@ -59,6 +54,27 @@ At this time, NATS 2.0 System credentials are required for meaningful usage.
2019/10/14 21:35:40 Prometheus exporter listening at http://0.0.0.0:7777/metrics
```

## Config

### Config Files

Surveyor uses Viper to read configs so it will support all file types that Viper supports (JSON, TOML, YAML, HCL, envfile, and Java properties)

To use a config file pass the `--config` flag. The defaults are `/etc/nats-surveyor/nats-surveyor[.ext]` and `./nats-surveyor[.ext]` with one of the supported extensions.

The config is simple, just set each flag in the config file. For example:

```
servers: nats://127.0.0.1:4222
accounts: true
```

### Environment Variables

Environment variables are also taken into account. Any environment variable that is prefixed with `NATS_SURVEYOR` will be read.

For example to enable accounts set `NATS_SURVEYOR_ACCOUNTS=true`

## Metrics

Scrape output is the in form of nats_core_NNNN_metric, where NNN is `server`, `route`, or `gateway`.
Expand Down
Loading

0 comments on commit ae25255

Please sign in to comment.