Skip to content

Commit

Permalink
Merge pull request #5 from patrickjahns/improve_exporter
Browse files Browse the repository at this point in the history
configure exporter via environment variables
  • Loading branch information
patrickjahns authored Apr 28, 2020
2 parents 0e6ca44 + c53f24c commit bac4317
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ generate:
.PHONY: lint
lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u golang.org/x/lint/golint; \
GO111MODULE=off $(GO) get -u golang.org/x/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;

.PHONY: test
test:
@which goverage > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/haya14busa/goverage; \
GO111MODULE=off $(GO) get -u github.com/haya14busa/goverage; \
fi
go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES)
goverage -v -coverprofile coverage.out $(PACKAGES)

.PHONY: build
build: $(BIN)/$(EXECUTABLE)
Expand All @@ -87,7 +87,7 @@ release-dirs:
.PHONY: release-build
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mitchellh/gox; \
GO111MODULE=off $(GO) get -u github.com/mitchellh/gox; \
fi
gox -arch="386 amd64 arm" -verbose -ldflags '-w $(LDFLAGS)' -output="$(DIST)/$(EXECUTABLE)-{{.OS}}-{{.Arch}}" ./cmd/$(NAME)

Expand Down
22 changes: 18 additions & 4 deletions pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,41 @@ func Run() error {
Aliases: []string{"web.listen-address"},
Value: "0.0.0.0:9176",
Usage: "Address to bind the metrics server",
EnvVars: []string{"OPENVPN_EXPORTER_WEB_ADDRESS"},
Destination: &cfg.Server.Addr,
},
&cli.StringFlag{
Name: "web.path",
Aliases: []string{"web.telemetry-path"},
Value: "/metrics",
Usage: "Path to bind the metrics server",
EnvVars: []string{"OPENVPN_EXPORTER_WEB_PATH"},
Destination: &cfg.Server.Path,
},
&cli.StringFlag{
Name: "web.root",
Value: "/",
Usage: "Root path to exporter endpoints",
EnvVars: []string{"OPENVPN_EXPORTER_WEB_ROOT"},
Destination: &cfg.Server.Root,
},
&cli.StringSliceFlag{
Name: "status-file",
Usage: "The OpenVPN status file(s) to export (example test:./example/version1.status )",
EnvVars: []string{"OPENVPN_EXPORTER_STATUS_FILE"},
Required: true,
},
&cli.BoolFlag{
Name: "disable-client-metrics",
Usage: "Disables per client (bytes_received, bytes_sent, connected_since) metrics",
EnvVars: []string{"OPENVPN_EXPORTER_DISABLE_CLIENT_METRICS"},
},
&cli.BoolFlag{
Name: "enable-golang-metrics",
Value: false,
Usage: "Enables golang and process metrics for the exporter) ",
EnvVars: []string{"OPENVPN_EXPORTER_ENABLE_GOLANG_METRICS"},
Destination: &cfg.ExportGoMetrics,
},
}

Expand Down Expand Up @@ -98,10 +110,12 @@ func run(c *cli.Context, cfg *config.Config) error {
"goVersion", version.GoVersion,
)

// enable profiler
r := prometheus.NewRegistry()
r.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
r.MustRegister(prometheus.NewGoCollector())
if cfg.ExportGoMetrics {
// enable profiler
r.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}))
r.MustRegister(prometheus.NewGoCollector())
}
r.MustRegister(collector.NewGeneralCollector(
logger,
version.Version,
Expand Down Expand Up @@ -152,7 +166,7 @@ func parseStatusFileSlice(statusFile string) (string, string) {
if len(parts) > 1 {
return parts[0], parts[1]
}
return "server", parts[0]
return parts[0], parts[0]
}

func setupLogging(cfg *config.Config) log.Logger {
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Config struct {
Server Server
Logs Logs
StatusCollector StatusCollector
ExportGoMetrics bool
}

// StatusCollector contains configuration for the OpenVPN status collector
Expand Down

0 comments on commit bac4317

Please sign in to comment.