Skip to content

Commit a35e5dd

Browse files
authored
Namespace support for dynamic environments (#41)
* Update readme cmd and env * metric namespce support
1 parent 6cf8000 commit a35e5dd

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,25 @@ go run main.go
5454

5555
### Flags
5656

57-
- `locust.uri`
57+
- `--locust.uri`
5858
Address of Locust. Default is `http://localhost:8089`.
5959

60-
- `locust.timeout`
60+
- `--locust.timeout`
6161
Timeout request to Locust. Default is `5s`.
6262

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

66-
- `web.telemetry-path`
66+
- `--web.telemetry-path`
6767
Path under which to expose metrics. Default is `/metrics`.
6868

69-
- `log.level`
69+
- `--locust.namespace`
70+
Namespace for prometheus metrics. Default `locust`.
71+
72+
- `--log.level`
7073
Set logging level: one of `debug`, `info`, `warn`, `error`, `fatal`
7174

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

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

95+
- `LOCUST_METRIC_NAMESPACE`
96+
Namespace for prometheus metrics. Default `locust`.
97+
9298
### Grafana
9399

94100
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).

main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
"gopkg.in/alecthomas/kingpin.v2"
2020
)
2121

22-
const (
23-
namespace = "locust"
22+
var (
23+
namespace string
24+
NameSpace *string
2425
)
2526

2627
// Exporter structure
@@ -419,11 +420,11 @@ func countWorkersByState(stats locustStats, state string) float64 {
419420
}
420421

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

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

436+
namespace = *NameSpace
435437
log.Infoln("Starting locust_exporter", version.Info())
436438
log.Infoln("Build context", version.BuildContext())
437439

0 commit comments

Comments
 (0)