Skip to content

Commit

Permalink
configurable solr context path (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziofortino authored and noony committed Oct 9, 2017
1 parent 1fb5e8a commit 77f0bca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ prometheus-solr-exporter --help
| Argument | Description |
| -------- | ----------- |
| solr.address | URI on which to scrape Solr. (default "http://localhost:8983") |
| solr.context-path | Solr webapp context path. (default "/solr") |
| solr.pid-file | Path to Solr pid file |
| solr.timeout | Timeout for trying to get stats from Solr. (default 5s) |
| web.listen-address | Address to listen on for web interface and telemetry. (default ":9231")|
Expand Down
8 changes: 4 additions & 4 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const (
mbeansPath = "/admin/mbeans?stats=true&wt=json&cat=CORE&cat=QUERYHANDLER&cat=UPDATEHANDLER&cat=CACHE"
adminCoresPath = "/solr/admin/cores?action=STATUS&wt=json"
adminCoresPath = "/admin/cores?action=STATUS&wt=json"
)

var (
Expand Down Expand Up @@ -112,7 +112,7 @@ type Exporter struct {
}

// NewExporter returns an initialized Exporter.
func NewExporter(solrURI string, timeout time.Duration) *Exporter {
func NewExporter(solrURI string, solrContextPath string, timeout time.Duration) *Exporter {
gaugeAdmin := make(map[string]*prometheus.GaugeVec, len(gaugeAdminMetrics))
gaugeCore := make(map[string]*prometheus.GaugeVec, len(gaugeCoreMetrics))
gaugeQuery := make(map[string]*prometheus.GaugeVec, len(gaugeQueryMetrics))
Expand Down Expand Up @@ -158,8 +158,8 @@ func NewExporter(solrURI string, timeout time.Duration) *Exporter {
}, []string{"core", "handler", "class"})
}

mbeansUrl := fmt.Sprintf("%s/solr/%s%s", solrURI, "%s", mbeansPath)
adminCoreUrl := fmt.Sprintf("%s%s", solrURI, adminCoresPath)
mbeansUrl := fmt.Sprintf("%s%s/%s%s", solrURI, solrContextPath, "%s", mbeansPath)
adminCoreUrl := fmt.Sprintf("%s%s%s", solrURI, solrContextPath, adminCoresPath)

// Init our exporter.
return &Exporter{
Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const (
)

var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9231").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
solrURI = kingpin.Flag("solr.address", "URI on which to scrape Solr.").Default("http://localhost:8983").String()
solrTimeout = kingpin.Flag("solr.timeout", "Timeout for trying to get stats from Solr.").Default("5s").Duration()
solrPidFile = kingpin.Flag("solr.pid-file", "").Default(pidFileHelpText).String()
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9231").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
solrURI = kingpin.Flag("solr.address", "URI on which to scrape Solr.").Default("http://localhost:8983").String()
solrContextPath = kingpin.Flag("solr.context-path", "Solr webapp context path.").Default("/solr").String()
solrTimeout = kingpin.Flag("solr.timeout", "Timeout for trying to get stats from Solr.").Default("5s").Duration()
solrPidFile = kingpin.Flag("solr.pid-file", "").Default(pidFileHelpText).String()
)

var landingPage = []byte(`<html>
Expand All @@ -52,7 +53,7 @@ func main() {
log.Infoln("Starting solr_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())

exporter := NewExporter(*solrURI, *solrTimeout)
exporter := NewExporter(*solrURI, *solrContextPath, *solrTimeout)
prometheus.MustRegister(exporter)
prometheus.MustRegister(version.NewCollector("solr_exporter"))

Expand Down

0 comments on commit 77f0bca

Please sign in to comment.