Skip to content

Commit

Permalink
Namespace support for dynamic environments (#41)
Browse files Browse the repository at this point in the history
* Update readme cmd and env

* metric namespce support
  • Loading branch information
geekzoo authored May 22, 2023
1 parent 6cf8000 commit a35e5dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,25 @@ go run main.go

### Flags

- `locust.uri`
- `--locust.uri`
Address of Locust. Default is `http://localhost:8089`.

- `locust.timeout`
- `--locust.timeout`
Timeout request to Locust. Default is `5s`.

- `web.listen-address`
- `--web.listen-address`
Address to listen on for web interface and telemetry. Default is `:9646`.

- `web.telemetry-path`
- `--web.telemetry-path`
Path under which to expose metrics. Default is `/metrics`.

- `log.level`
- `--locust.namespace`
Namespace for prometheus metrics. Default `locust`.

- `--log.level`
Set logging level: one of `debug`, `info`, `warn`, `error`, `fatal`

- `log.format`
- `--log.format`
Set the log output target and format. e.g. `logger:syslog?appname=bob&local=7` or `logger:stdout?json=true`
Defaults to `logger:stderr`.

Expand All @@ -89,6 +92,9 @@ The following environment variables configure the exporter:
- `LOCUST_EXPORTER_WEB_TELEMETRY_PATH`
Path under which to expose metrics. Default is `/metrics`.

- `LOCUST_METRIC_NAMESPACE`
Namespace for prometheus metrics. Default `locust`.

### Grafana

The grafana dashboard has beed published with ID [11985](https://grafana.com/grafana/dashboards/11985) and was exported to [locust_dashboard.json](locust_dashboard.json).
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

const (
namespace = "locust"
var (
namespace string
NameSpace *string
)

// Exporter structure
Expand Down Expand Up @@ -419,11 +420,11 @@ func countWorkersByState(stats locustStats, state string) float64 {
}

func main() {

var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9646").Envar("LOCUST_EXPORTER_WEB_LISTEN_ADDRESS").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("LOCUST_EXPORTER_WEB_TELEMETRY_PATH").String()
uri = kingpin.Flag("locust.uri", "URI of Locust.").Default("http://localhost:8089").Envar("LOCUST_EXPORTER_URI").String()
NameSpace = kingpin.Flag("locust.namespace", "Namespace for prometheus metrics.").Default("locust").Envar("LOCUST_METRIC_NAMESPACE").String()
timeout = kingpin.Flag("locust.timeout", "Scrape timeout").Default("5s").Envar("LOCUST_EXPORTER_TIMEOUT").Duration()
)

Expand All @@ -432,6 +433,7 @@ func main() {
kingpin.HelpFlag.Short('h')
kingpin.Parse()

namespace = *NameSpace
log.Infoln("Starting locust_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())

Expand Down

0 comments on commit a35e5dd

Please sign in to comment.