Skip to content

Commit de13eff

Browse files
committed
Changed daemon target from flag to url param. Build files.
1 parent f21791a commit de13eff

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

.promu

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
go:
2+
cgo: false
3+
repository:
4+
path: github.com/RobustPerception/nrpe_exporter
5+
build:
6+
binaries:
7+
- name: nrpe_exporter
8+
flags: -a -tags netgo
9+
ldflags: |
10+
-X {{repoPath}}/version.Version={{.Version}}
11+
-X {{repoPath}}/version.Revision={{.Revision}}
12+
-X {{repoPath}}/version.Branch={{.Branch}}
13+
-X {{repoPath}}/version.BuildUser={{user}}@{{host}}
14+
-X {{repoPath}}/version.BuildDate={{date "20060102-15:04:05"}}
15+
tarball:
16+
prefix: .
17+
files:
18+
- LICENSE
19+
crossbuild:
20+
platforms:
21+
- linux/amd64
22+
- linux/386
23+
- darwin/amd64
24+
- darwin/386
25+
- windows/amd64
26+
- windows/386
27+
- freebsd/amd64
28+
- freebsd/386
29+
- openbsd/amd64
30+
- openbsd/386
31+
- netbsd/amd64
32+
- netbsd/386
33+
- dragonfly/amd64
34+
- linux/arm
35+
- linux/arm64
36+
- freebsd/arm
37+
- openbsd/arm
38+
- netbsd/arm
39+
- linux/ppc64
40+
- linux/ppc64le
41+
- linux/mips64
42+
- linux/mips64le

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ The NRPE exporter allows for the exposing of nrpe server command's metrics, name
77
### Local Build
88

99
go build nrpe_exporter.go
10-
./nrpe_exporter --nrpe-server-address=<nrpe-server-address>
10+
./nrpe_exporter
1111

12-
Visiting [http://localhost:9275/export?command=check_load](http://localhost:9275/export?command=check_load)
13-
will return metrics for the command 'check_load' agaisnt a locally running nrpe-server.
12+
Visiting [http://localhost:9275/export?command=check_load&target=127.0.0.1:5666](http://localhost:9275/export?command=check_load&target=127.0.0.1:5666)
13+
will return metrics for the command 'check_load' against a locally running NRPE server.
1414

1515
### Building with Docker
1616

@@ -28,7 +28,7 @@ Note: The NRPE server you're connecting to must be configured with SSL disabled
2828

2929
## Prometheus Configuration
3030

31-
The NRPE exporter needs to be passed a nrpe server command as a parameter, this can be
31+
The NRPE exporter needs to be passed a NRPE server command as a parameter, this can be
3232
done with relabelling.
3333

3434
Example config:
@@ -39,6 +39,7 @@ scrape_configs:
3939
- job_name: nrpe
4040
metrics_path: /export
4141
params:
42+
target: [127.0.0.1:5666]
4243
command: [check_load]
4344
static_configs:
4445
- targets:

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

nrpe_exporter.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import (
1818
)
1919

2020
var (
21-
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests.").Default(":9275").String()
22-
nrpeServerAddress = kingpin.Flag("nrpe-server-address", "The address of the NRPE server.").Required().String()
21+
listenAddress = kingpin.Flag("web.listen-address", "The address to listen on for HTTP requests.").Default(":9275").String()
2322
)
2423

2524
// Collector type containing issued command and a logger
2625
type Collector struct {
2726
command string
27+
target string
2828
logger log.Logger
2929
}
3030

@@ -61,7 +61,7 @@ func collectCommandMetrics(cmd string, conn net.Conn, logger log.Logger) (Comman
6161
// Collect dials nrpe-server and issues given command, recording metrics based on the result.
6262
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
6363
// Connect to NRPE server
64-
conn, err := net.Dial("tcp", *nrpeServerAddress)
64+
conn, err := net.Dial("tcp", c.target)
6565
if err != nil {
6666
level.Error(c.logger).Log("msg", "Error dialing NRPE server", "err", err)
6767
return
@@ -92,22 +92,28 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
9292
}
9393

9494
// NewCollector returns new collector with logger and given command
95-
func NewCollector(command string, logger log.Logger) *Collector {
95+
func NewCollector(command, target string, logger log.Logger) *Collector {
9696
return &Collector{
9797
command: command,
98+
target: target,
9899
logger: logger,
99100
}
100101
}
101102

102103
func handler(w http.ResponseWriter, r *http.Request, logger log.Logger) {
103104
params := r.URL.Query()
105+
target := params.Get("target")
106+
if target == "" {
107+
http.Error(w, "Target parameter is missing", 400)
108+
return
109+
}
104110
cmd := params.Get("command")
105111
if cmd == "" {
106112
http.Error(w, "Command parameter is missing", 400)
107113
return
108114
}
109115
registry := prometheus.NewRegistry()
110-
collector := NewCollector(cmd, logger)
116+
collector := NewCollector(cmd, target, logger)
111117
registry.MustRegister(collector)
112118
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
113119
h.ServeHTTP(w, r)
@@ -130,10 +136,7 @@ func main() {
130136
<body>
131137
<h1>NRPE Exporter</h1>
132138
<p><a href="/metrics">Metrics</a></p>
133-
<form action="/export">
134-
<label>NRPE Command:</label> <input type="text" name="command" placeholder="check_load" value="check_load">
135-
<input type="submit" value="Submit">
136-
</form>
139+
<p><a href="/export?command=check_load&target=127.0.0.1:5666">check_load against localhost:5666</a></p>
137140
</body>
138141
</html>`))
139142
})

0 commit comments

Comments
 (0)