Skip to content

Commit c0a8cc7

Browse files
authored
Merge pull request #104 from zwopir/feature/add_version_info
add version command line parameter and metric
2 parents 58cb4e6 + 040cd20 commit c0a8cc7

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

main.go

+11
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import (
1313
"github.com/go-kit/kit/log/level"
1414
"github.com/justwatchcom/elasticsearch_exporter/collector"
1515
"github.com/prometheus/client_golang/prometheus"
16+
"github.com/prometheus/common/version"
1617
)
1718

1819
func main() {
1920
var (
21+
Name = "elasticsearch_exporter"
2022
listenAddress = flag.String("web.listen-address", ":9108", "Address to listen on for web interface and telemetry.")
2123
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
2224
esURI = flag.String("es.uri", "http://localhost:9200", "HTTP API address of an Elasticsearch node.")
@@ -26,9 +28,15 @@ func main() {
2628
esCA = flag.String("es.ca", "", "Path to PEM file that conains trusted CAs for the Elasticsearch connection.")
2729
esClientPrivateKey = flag.String("es.client-private-key", "", "Path to PEM file that conains the private key for client auth when connecting to Elasticsearch.")
2830
esClientCert = flag.String("es.client-cert", "", "Path to PEM file that conains the corresponding cert for the private key to connect to Elasticsearch.")
31+
showVersion = flag.Bool("version", false, "Show version and exit")
2932
)
3033
flag.Parse()
3134

35+
if *showVersion {
36+
fmt.Print(version.Print(Name))
37+
os.Exit(0)
38+
}
39+
3240
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout))
3341
logger = log.With(logger,
3442
"ts", log.DefaultTimestampUTC,
@@ -54,6 +62,9 @@ func main() {
5462
},
5563
}
5664

65+
// version metric
66+
versionMetric := version.NewCollector(Name)
67+
prometheus.MustRegister(versionMetric)
5768
prometheus.MustRegister(collector.NewClusterHealth(logger, httpClient, esURL))
5869
prometheus.MustRegister(collector.NewNodes(logger, httpClient, esURL, *esAllNodes))
5970
if *esExportIndices {

vendor/github.com/prometheus/common/version/info.go

+89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/vendor.json

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
"revision": "3233b24a36715a2fe36d162260457857a56d672d",
8181
"revisionTime": "2017-06-15T07:20:16Z"
8282
},
83+
{
84+
"checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=",
85+
"path": "github.com/prometheus/common/version",
86+
"revision": "bc8b88226a1210b016e9993b1d75f858c9c8f778",
87+
"revisionTime": "2017-08-30T19:05:55Z"
88+
},
8389
{
8490
"checksumSHA1": "W218eJZPXJG783fUr/z6IaAZyes=",
8591
"path": "github.com/prometheus/procfs",

0 commit comments

Comments
 (0)