-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6a240c
commit 3be8c0c
Showing
13 changed files
with
405 additions
and
145 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 |
---|---|---|
|
@@ -20,4 +20,6 @@ | |
# Go workspace file | ||
go.work | ||
*opnsense-exporter-local | ||
local.Makefile | ||
local.Makefile | ||
key | ||
secret |
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,45 @@ | ||
## Contributing | ||
|
||
### Requirements | ||
|
||
- Go 1.22 | ||
- GNU Make | ||
- Docker (optional) | ||
- OPNsense Box with admin access | ||
|
||
### Environment | ||
|
||
This guide is for osx and Linux. | ||
|
||
### Create API key and secret in OPNsense | ||
|
||
`SYSTEM>ACCESS>USERS>[user]>API KEYS` | ||
|
||
[OPNsense Documentation](https://docs.opnsense.org/development/how-tos/api.html#creating-keys) | ||
|
||
### Run the exporter locally | ||
|
||
```bash | ||
OPS_ADDRESS="ops.example.com" OPS_API_KEY=your-api-key OPS_API_SECRET=your-api-secret make local-run | ||
``` | ||
|
||
- test it | ||
|
||
```bash | ||
curl http://localhost:8080/metrics | ||
``` | ||
|
||
### Before PR | ||
|
||
- Make sure to sync the vendor if the dependencies have changed. | ||
|
||
```bash | ||
make sync-vendor | ||
``` | ||
|
||
- Make sure to run the tests and linters. | ||
|
||
```bash | ||
make test | ||
make lint | ||
``` |
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,34 @@ | ||
package options | ||
|
||
import "github.com/alecthomas/kingpin/v2" | ||
|
||
var ( | ||
arpTableCollectorDisabled = kingpin.Flag( | ||
"exporter.disable-arp-table", | ||
"Disable the scraping of the ARP table", | ||
).Envar("OPNSENSE_EXPORTER_DISABLE_ARP_TABLE").Default("false").Bool() | ||
cronTableCollectorDisabled = kingpin.Flag( | ||
"exporter.disable-cron-table", | ||
"Disable the scraping of the cron table", | ||
).Envar("OPNSENSE_EXPORTER_DISABLE_CRON_TABLE").Default("false").Bool() | ||
wireguardCollectorDisabled = kingpin.Flag( | ||
"exporter.disable-wireguard", | ||
"Disable the scraping of Wireguard service", | ||
).Envar("OPNSENSE_EXPORTER_DISABLE_WIREGUARD").Default("false").Bool() | ||
) | ||
|
||
// Collectors holds the configuration for the collectors | ||
type CollectorsSwitches struct { | ||
ARP bool | ||
Cron bool | ||
Wireguard bool | ||
} | ||
|
||
// Collectors returns the configuration for the collectors | ||
func Collectors() CollectorsSwitches { | ||
return CollectorsSwitches{ | ||
ARP: !*arpTableCollectorDisabled, | ||
Cron: !*cronTableCollectorDisabled, | ||
Wireguard: !*wireguardCollectorDisabled, | ||
} | ||
} |
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 @@ | ||
package options | ||
|
||
import ( | ||
"github.com/alecthomas/kingpin/v2" | ||
"github.com/prometheus/exporter-toolkit/web/kingpinflag" | ||
) | ||
|
||
var ( | ||
MetricsPath = kingpin.Flag( | ||
"web.telemetry-path", | ||
"Path under which to expose metrics.", | ||
).Default("/metrics").String() | ||
DisableExporterMetrics = kingpin.Flag( | ||
"web.disable-exporter-metrics", | ||
"Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).", | ||
).Envar("OPNSENSE_EXPORTER_DISABLE_EXPORTER_METRICS").Bool() | ||
MaxProcs = kingpin.Flag( | ||
"runtime.gomaxprocs", | ||
"The target number of CPUs that the Go runtime will run on (GOMAXPROCS)", | ||
).Envar("GOMAXPROCS").Default("2").Int() | ||
InstanceLabel = kingpin.Flag( | ||
"exporter.instance-label", | ||
"Label to use to identify the instance in every metric. "+ | ||
"If you have multiple instances of the exporter, you can differentiate them by using "+ | ||
"different value in this flag, that represents the instance of the target OPNsense.", | ||
).Envar("OPNSENSE_EXPORTER_INSTANCE_LABEL").Required().String() | ||
|
||
WebConfig = kingpinflag.AddFlags(kingpin.CommandLine, ":8080") | ||
) |
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,13 @@ | ||
package options | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/alecthomas/kingpin/v2" | ||
) | ||
|
||
func Init() { | ||
kingpin.CommandLine.UsageWriter(os.Stdout) | ||
kingpin.HelpFlag.Short('h') | ||
kingpin.Parse() | ||
} |
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,38 @@ | ||
package options | ||
|
||
import ( | ||
"github.com/alecthomas/kingpin/v2" | ||
"github.com/go-kit/log" | ||
"github.com/prometheus/common/promlog" | ||
) | ||
|
||
var ( | ||
logLevel = kingpin.Flag( | ||
"log.level", | ||
"Log level. One of: [debug, info, warn, error]"). | ||
Default("info"). | ||
String() | ||
logFormat = kingpin.Flag( | ||
"log.format", | ||
"Log format. One of: [logfmt, json]"). | ||
Default("logfmt"). | ||
String() | ||
) | ||
|
||
func Logger() (log.Logger, error) { | ||
|
||
promlogConfig := &promlog.Config{ | ||
Level: &promlog.AllowedLevel{}, | ||
Format: &promlog.AllowedFormat{}, | ||
} | ||
|
||
if err := promlogConfig.Level.Set(*logLevel); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := promlogConfig.Format.Set(*logFormat); err != nil { | ||
return nil, err | ||
} | ||
|
||
return promlog.New(promlogConfig), nil | ||
} |
Oops, something went wrong.