Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: switch to exporter-toolkit, use std embed instead of go-bindata #16

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '>=1.21.0'
- name: Build
env:
GOOS: ${{ matrix.GOOS }}
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Go Lint

on:
push:
pull_request:

jobs:
test:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.21.0'
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.21.0'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Go Test

on:
push:
pull_request:

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '>=1.21.0'
id: go
- name: Test
run: go test -v ./...
45 changes: 45 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
builds:
- # First Build
env:
- CGO_ENABLED=0
main: nsd_exporter.go
ldflags: >-
-s -w
-X github.com/prometheus/common/version.Version={{.Version}}
-X github.com/prometheus/common/version.Revision={{.FullCommit}}
-X github.com/prometheus/common/version.Branch={{.Branch}}
-X github.com/prometheus/common/version.BuildUser=goreleaser@github-actions
-X github.com/prometheus/common/version.BuildDate={{time "20060102-15:04:05"}}

# Set the binary output location to bin/ so archive will comply with Sensu Go Asset structure
binary: bin/{{ .ProjectName }}
goos:
- linux
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 5
- 6
- 7
targets:
- linux_386
- linux_amd64
- linux_arm_5
- linux_arm_6
- linux_arm_7
- linux_arm64

checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_sha512-checksums.txt"
algorithm: sha512

archives:
- id: tar
format: tar.gz
files:
- LICENSE
- README.md
- nsd_exporter.service
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
build: generate
go build
build:
CGO_ENABLED=0 go build -ldflags "-s -w"

generate:
go generate

clean:
rm -f nsd_exporter

all: clean build
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,28 @@ You will need to launch the process as a user that has permissions to the NSD co

### Examples
```
# Defaults listening to 127.0.0.1:8080/metrics
# Defaults listening to 127.0.0.1:9167/metrics
% nsd_exporter

# Specify a different port to listen on
% nsd_exporter -listen-address :9167
% nsd_exporter --web.listen-address :9167

# Specify an alternate configuration location to autodetect from
% nsd_exporter -config-file /opt/nsd/nsd.conf
% nsd_exporter --nsd.config /opt/nsd/nsd.conf

# Manually specify NSD socket and certificates
% nsd_exporter -ca /etc/nsd/nsd_server.pem -key /etc/nsd/nsd_control.key -cert /etc/nsd/nsd_control.pem -nsd-address 127.0.0.1:8952
% nsd_exporter --control.ca /etc/nsd/nsd_server.pem --control.key /etc/nsd/nsd_control.key --control.cert /etc/nsd/nsd_control.pem --control.address 127.0.0.1:8952
```

### Add/Modify metrics
If `nsd` has a new version with new metrics or you want to change the description of the existing metrics, you can make changes to the metrics that `nsd_exporter` emits by using your own metrics config file.

1. Download the metrics config from [`config/config.yaml`](https://raw.githubusercontent.com/optix2000/nsd_exporter/master/config/config.yaml)
2. Make any additions or modifications you want.
3. Load it by running `nsd_exporter -metric-config my-custom-config.yaml`. This will use your config instead of the internal metrics config file.
3. Load it by running `nsd_exporter --metrics-config my-custom-config.yaml`. This will use your config instead of the internal metrics config file.

## Building
### Making config changes
This is only needed if you want to modify the embedded metric configuration file.

Install go-bindata.
```
go install github.com/go-bindata/go-bindata/go-bindata@latest
make
```
Make any metric config modifications to `config/config.yaml`.

Run `go generate` to generate a new embedded config file. Don't forget to check it in.
Loading