Skip to content

Commit

Permalink
Refactor config and get rid of some dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
laura-zelenku authored Jan 4, 2025
1 parent 32e9b7e commit aa54ee5
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 351 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Builder image
FROM golang:1.23.4 as builder
FROM golang:1.23.4 AS builder
WORKDIR /workspace

ENV GO111MODULE=on
Expand Down
56 changes: 20 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,48 @@
# IPsec Prometheus Exporter
# IPSec Prometheus Exporter

_The IPsec Prometheus exporter subscribes to the strongSwan via Vici API and exposes [Security Associations](https://github.com/strongswan/strongswan/blob/master/src/libcharon/plugins/vici/README.md#list-sa) (SAs) metrics._
_The IPSec Prometheus exporter subscribes to the strongSwan via Vici API and exposes [Security Associations](https://github.com/strongswan/strongswan/blob/master/src/libcharon/plugins/vici/README.md#list-sa) (SAs) metrics._

Collected metrics (together with application metrics) are exposed on `/metrics` endpoint. Prometheus target is then configured with this endpoint and port e.g. `http://localhost:8079/metrics`.

## Configuration

IPsec Prometheus exporter configuration yaml file is optional. If not provided, the default values are used.
IPSec Prometheus exporter is configured via command-line arguments. If not provided, the default values are used.

### Config file
### Command-line arguments

If the default value match with your choice you can omit it.

```yaml
# Logger configuration
logging:
# logging level - default: INFO
level: DEBUG

# HTTP server configuration
server:
# server port - default: 8079
port: 8080

# Vici configuration
vici:
# Vici network scheme - default: tcp
network: "udp"
# Vici host is the ip-address or hostname.
# Default values for hostname is "localhost".
# IPv6 is supported. Use host in format of "[fd12:3456:789a::1]".
host: "127.0.0.1"
# Vici port - default: 4502
port: 30123
```
Options and default values:
--server-port=8079 Application port where the collected metrics are available
--log-level=info Logging level (debug, info, warn, error)
--vici-network=tcp Vici network scheme (tcp, udp, unix)
--vici-address=localhost:4502 IP address or hostname with a port or unix socket path
IPv6 is supported. Use address in format of "[fd12:3456:789a::1]:4502"
```

## Value Definition

| Metric | Value | Description |
|--------|-------|-------------|
| strongswan_*_status | 0 | The tunnel is installed and is up and running. |
| strongswan_*_status | 1 | The connection is established. |
| strongswan_*_status | 2 | The tunnel or connection is down. |
| strongswan_*_status | 3 | The tunnel or connection status is not recognized. |
| Metric | Value | Description |
|---------------------|-------|----------------------------------------------------|
| strongswan_*_status | 0 | The tunnel is installed and is up and running. |
| strongswan_*_status | 1 | The connection is established. |
| strongswan_*_status | 2 | The tunnel or connection is down. |
| strongswan_*_status | 3 | The tunnel or connection status is not recognized. |

## Build & Run
To build the binary run:
```bash
make build
```

Run the binary with optional `config` parameter provided:
Run the binary with optional arguments provided:
```bash
./ipsec-prometheus-exporter [--config=<path to yaml config file>]
./ipsec-prometheus-exporter [--server-port=8079] [--log-level=info] [--vici-network=tcp] [--vici-address=localhost:4502]
```

## Docker image
Public docker image is available for multiple platforms: https://hub.docker.com/r/torilabs/ipsec-prometheus-exporter
```
docker run -it -p 8079:8079 -v $(pwd)/my-config.yaml:/config.yaml --rm torilabs/ipsec-prometheus-exporter:latest
docker run -it -p 8079:8079 --rm torilabs/ipsec-prometheus-exporter:latest --server-port=8079
```
98 changes: 0 additions & 98 deletions cmd/cmd.go

This file was deleted.

50 changes: 0 additions & 50 deletions config/config.go

This file was deleted.

90 changes: 0 additions & 90 deletions config/config_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ require (
github.com/etherlabsio/healthcheck/v2 v2.0.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/strongswan/govici v0.7.0
go.uber.org/zap v1.27.0
Expand All @@ -19,31 +17,15 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit aa54ee5

Please sign in to comment.