Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit da042f8

Browse files
caiwcwccaiwccai
authored
Caiwc/multi target (#234)
* feat(): support scrape multi target rebase branch && update Makefile version * add multi-target explain to readme * docs: correct dns example port of readme --------- Co-authored-by: wccai <[email protected]> Co-authored-by: wccai <wccai@easyops>
1 parent aad2f8e commit da042f8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ OS_TYPE ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
33
ARCH_TYPE ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH)))
44
GOOS ?= $(shell go env GOOS)
55
GOARCH ?= $(shell go env GOARCH)
6-
VERSION ?= 0.4.2
6+
VERSION ?= 0.4.3
77
MAJOR_VERSION ?= 21
88
MINOR_VERSION ?= 8
99
ORACLE_VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION)

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,10 @@ using the `--web.config` parameter. The format of the file is described
533533

534534
Note that the TLS and basic authentication settings affect all HTTP endpoints:
535535
/metrics for scraping, /probe for probing, and the web UI.
536+
537+
538+
## Multi-target support
539+
540+
This exporter supports the multi-target pattern. This allows running a single instance of this exporter for multiple Oracle targets.
541+
542+
To use the multi-target functionality, send a http request to the endpoint `/scrape?target=foo:1521` where target is set to the DSN of the Oracle instance to scrape metrics from.

main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ func main() {
610610
ErrorHandling: promhttp.ContinueOnError,
611611
}
612612
http.Handle(*metricPath, promhttp.HandlerFor(prometheus.DefaultGatherer, opts))
613+
http.HandleFunc("/scrape", scrapeHandle(logger))
613614

614615
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
615616
w.Write([]byte("<html><head><title>Oracle DB Exporter " + Version + "</title></head><body><h1>Oracle DB Exporter " + Version + "</h1><p><a href='" + *metricPath + "'>Metrics</a></p></body></html>"))
@@ -621,3 +622,19 @@ func main() {
621622
os.Exit(1)
622623
}
623624
}
625+
626+
func scrapeHandle(logger log.Logger) func(w http.ResponseWriter, r *http.Request) {
627+
return func(w http.ResponseWriter, r *http.Request) {
628+
target := r.URL.Query().Get("target")
629+
exporter := NewExporter(target, logger)
630+
registry := prometheus.NewRegistry()
631+
registry.MustRegister(exporter)
632+
gatherers := prometheus.Gatherers{
633+
prometheus.DefaultGatherer,
634+
registry,
635+
}
636+
// Delegate http serving to Prometheus client library, which will call collector.Collect.
637+
h := promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{})
638+
h.ServeHTTP(w, r)
639+
}
640+
}

0 commit comments

Comments
 (0)