Skip to content

Commit

Permalink
Merge pull request #14 from woblerr/listen_address
Browse files Browse the repository at this point in the history
Bump prometheus/exporter-toolkit from v0.7.3 to v0.9.1.
  • Loading branch information
woblerr authored Oct 27, 2023
2 parents 26d4307 + 93525fd commit 4b6e159
Show file tree
Hide file tree
Showing 113 changed files with 3,886 additions and 6,934 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Exclude vendor folder from ignore
!/vendor/**/*
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ARG REPO_BUILD_TAG="unknown"

FROM golang:1.18-alpine AS builder
FROM golang:1.20-alpine AS builder
ARG REPO_BUILD_TAG
WORKDIR /go/src/github.com/woblerr/authlog_exporter
COPY . .
Expand All @@ -11,7 +11,7 @@ RUN apk update \
-ldflags "-X main.version=${REPO_BUILD_TAG}" \
-o authlog_exporter authlog_exporter.go

FROM alpine:3.16
FROM alpine:3.17
ARG REPO_BUILD_TAG
RUN apk add --no-cache --update ca-certificates \
&& rm -rf /var/cache/apk/*
Expand Down
41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,46 @@ make build
./authlog_exporter <flags>
```

By default, metrics will be collecting from `/var/log/auth.log` and will be available at http://localhost:9991/metrics. This means that the user who runs `authlog_exporter` should have read permission to file `/var/log/auth.log`. You can changed log file location, port and endpoint by using the`--auth.log`, `--prom.port` and `--prom.endpoint` flags.
By default, metrics will be collecting from `/var/log/auth.log` and will be available at http://localhost:9991/metrics.
This means that the user who runs `authlog_exporter` should have read permission to file `/var/log/auth.log`.
You can changed log file location by using the`--auth.log` flag.

For geoIP analyze you need to specify `--geo.type` flag:
* `db` - for local geoIP database file,
* `url` - for geoIP database API.

For local geoIP database usage you also need specify `--geo.db` flag (path to geoIP database file).

The flag `--prom.web-config` allows to specify the path to the configuration for TLS and/or basic authentication.<br>
The description of TLS configuration and basic authentication can be found at [exporter-toolkit/web](https://github.com/prometheus/exporter-toolkit/blob/v0.7.1/docs/web-configuration.md).
The flag `--web.config.file` allows to specify the path to the configuration for TLS and/or basic authentication.<br>
The description of TLS configuration and basic authentication can be found at [exporter-toolkit/web](https://github.com/prometheus/exporter-toolkit/blob/v0.9.1/docs/web-configuration.md).

Available configuration flags:

```bash
./authlog_exporter --help
usage: authlog_exporter [<flags>]


Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
-h, --[no-]help Show context-sensitive help (also try --help-long and --help-man).
--auth.log="/var/log/auth.log"
Path to auth.log.
--prom.endpoint="/metrics"
Endpoint used for metrics.
--prom.port="9991" Port for prometheus metrics to listen on.
--prom.web-config="" [EXPERIMENTAL] Path to config yaml file that can enable TLS or authentication.
--geo.db="" Path to geoIP database file.
--geo.lang="en" Output language format.
--geo.timeout=2 Timeout in seconds for waiting response from geoIP database API.
--geo.type="" Type of geoIP database: db, url.
Path to auth.log.
--web.endpoint="/metrics" Endpoint used for metrics.
--web.listen-address=:9991 ...
Addresses on which to expose metrics and web interface. Repeatable for multiple addresses.
--web.config.file="" [EXPERIMENTAL] Path to configuration file that can enable TLS or authentication.
--geo.db="" Path to geoIP database file.
--geo.lang="en" Output language format.
--geo.timeout=2 Timeout in seconds for waiting response from geoIP database API.
--geo.type="" Type of geoIP database: db, url.
--geo.url="https://reallyfreegeoip.org/json/"
URL for geoIP database API.
--metric.hideip Set this flag to hide IPs in the output and therefore drastically reduce the amount of metrics published.
--metric.hideuser Set this flag to hide user accounts in the output and therefore drastically reduce the amount of metrics published.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
URL for geoIP database API.
--[no-]metric.hideip Set this flag to hide IPs in the output and therefore drastically reduce the amount of metrics
published.
--[no-]metric.hideuser Set this flag to hide user accounts in the output and therefore drastically reduce the amount of metrics
published.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
```

### geoIP
Expand Down
29 changes: 12 additions & 17 deletions authlog_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"path/filepath"
"syscall"

kingpin "github.com/alecthomas/kingpin/v2"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/exporter-toolkit/web/kingpinflag"
"github.com/woblerr/authlog_exporter/promexporter"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)

var version = "unknown"
Expand All @@ -22,19 +23,12 @@ func main() {
"auth.log",
"Path to auth.log.",
).Default("/var/log/auth.log").String()
promPath = kingpin.Flag(
"prom.endpoint",
webPath = kingpin.Flag(
"web.endpoint",
"Endpoint used for metrics.",
).Default("/metrics").String()
promPort = kingpin.Flag(
"prom.port",
"Port for prometheus metrics to listen on.",
).Default("9991").String()
promTLSConfigFile = kingpin.Flag(
"prom.web-config",
"[EXPERIMENTAL] Path to config yaml file that can enable TLS or authentication.",
).Default("").String()
geodbPath = kingpin.Flag(
webAdditionalToolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9991")
geodbPath = kingpin.Flag(
"geo.db",
"Path to geoIP database file.",
).Default("").String()
Expand Down Expand Up @@ -92,13 +86,14 @@ func main() {
"version", version,
)
// Setup parameters for exporter.
promexporter.SetExporterParams(*authlogPath, *promPort, *promPath, *promTLSConfigFile, *metricHideIP, *metricHideUser)
promexporter.SetExporterParams(*authlogPath, *webPath, *webAdditionalToolkitFlags, *metricHideIP, *metricHideUser)
level.Info(logger).Log(
"mgs", "Use exporter parameters",
"authlog", *authlogPath,
"mgs", "Use port and HTTP endpoint",
"port", *promPort,
"endpoint", *promPath,
"web-config", *promTLSConfigFile,
"endpoint", *webPath,
"config.file", *webAdditionalToolkitFlags.WebConfigFile,
"hideip", *metricHideIP,
"hideuser", *metricHideUser,
)
promexporter.SetGeodbPath(*geodbType, *geodbPath, *geodbLang, *geodbURL, *geodbTimeout, logger)
// Start exporter.
Expand Down
6 changes: 3 additions & 3 deletions authlog_exporter.service.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Description=authlog_exporter
[Service]
Type=simple
Environment="AUTH_LOG_PATH=/var/log/auth.log"
Environment="ENDPOINT=/metrics"
Environment="PORT=9991"
ExecStart=/usr/bin/authlog_exporter --auth.log=${AUTH_LOG_PATH} --prom.endpoint=${ENDPOINT} --prom.port=${PORT}
Environment="EXPORTER_ENDPOINT=/metrics"
Environment="EXPORTER_PORT=9991"
ExecStart=/usr/bin/authlog_exporter --auth.log=${AUTH_LOG_PATH} --web.endpoint=${EXPORTER_ENDPOINT} --web.listen-address=:${EXPORTER_PORT}
Restart=always
RestartSec=5s

Expand Down
2 changes: 1 addition & 1 deletion authlog_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestMain(t *testing.T) {
port := 50000 + int(n.Int64())
os.Args = []string{
"authlog_exporter",
"--prom.port=" + strconv.Itoa(port),
"--web.listen-address=:" + strconv.Itoa(port),
"--auth.log",
"./test_data/auth.log"}
finished := make(chan struct{})
Expand Down
25 changes: 14 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@ module github.com/woblerr/authlog_exporter
go 1.20

require (
github.com/go-kit/log v0.2.0
github.com/alecthomas/kingpin/v2 v2.3.2
github.com/go-kit/log v0.2.1
github.com/nxadm/tail v1.4.8
github.com/oschwald/geoip2-golang v1.5.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.37.0
github.com/prometheus/exporter-toolkit v0.7.3
gopkg.in/alecthomas/kingpin.v2 v2.2.6
github.com/prometheus/common v0.41.0
github.com/prometheus/exporter-toolkit v0.9.1
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/fsnotify/fsnotify v1.5.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/oschwald/maxminddb-golang v1.8.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 4b6e159

Please sign in to comment.