Commit 0f68bba9 authored by Ben Wilson's avatar Ben Wilson

op-exporter version metric

parent a21cec6d
SHELL := /bin/bash SHELL := /bin/bash
VERSION := `git describe --abbrev=0` ifndef VERSION
VERSION := `jq .version package.json `
endif
ifndef GITCOMMIT
GITCOMMIT := `git rev-parse HEAD` GITCOMMIT := `git rev-parse HEAD`
endif
ifndef BUILDDATE
BUILDDATE := `date +%Y-%m-%d` BUILDDATE := `date +%Y-%m-%d`
BUILDUSER := `whoami` endif
LDFLAGSSTRING :=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.Version=$(VERSION) LDFLAGSSTRING :=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.Version=$(VERSION)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.GitCommit=$(GITCOMMIT) LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.BuildDate=$(BUILDDATE) LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.BuildDate=$(BUILDDATE)
LDFLAGSSTRING +=-X github.com/ethereum-optimism/optimism/go/op_exporter/version.BuildUser=$(BUILDUSER)
LDFLAGS :=-ldflags "$(LDFLAGSSTRING)" LDFLAGS :=-ldflags "$(LDFLAGSSTRING)"
......
...@@ -24,6 +24,12 @@ var ( ...@@ -24,6 +24,12 @@ var (
Help: "Is the sequencer healthy?"}, Help: "Is the sequencer healthy?"},
[]string{"network"}, []string{"network"},
) )
opExporterVersion = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "op_exporter_version",
Help: "Verion of the op-exporter software"},
[]string{"version", "commit", "goVersion", "buildDate"},
)
) )
func init() { func init() {
...@@ -31,4 +37,6 @@ func init() { ...@@ -31,4 +37,6 @@ func init() {
prometheus.MustRegister(gasPrice) prometheus.MustRegister(gasPrice)
prometheus.MustRegister(blockNumber) prometheus.MustRegister(blockNumber)
prometheus.MustRegister(healthySequencer) prometheus.MustRegister(healthySequencer)
prometheus.MustRegister(opExporterVersion)
} }
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"strings"
"sync" "sync"
"time" "time"
...@@ -50,7 +51,7 @@ var ( ...@@ -50,7 +51,7 @@ var (
enableK8sQuery = kingpin.Flag( enableK8sQuery = kingpin.Flag(
"k8s.enable", "k8s.enable",
"Enable kubernetes info lookup.", "Enable kubernetes info lookup.",
).Default("true").Bool() ).Default("false").Bool()
) )
type healthCheck struct { type healthCheck struct {
...@@ -81,7 +82,8 @@ func main() { ...@@ -81,7 +82,8 @@ func main() {
log.Infoln("exporter config", *listenAddress, *rpcProvider, *networkLabel) log.Infoln("exporter config", *listenAddress, *rpcProvider, *networkLabel)
log.Infoln("Starting op_exporter", version.Info()) log.Infoln("Starting op_exporter", version.Info())
log.Infoln("Build context", version.BuildContext()) log.Infoln("Build context", version.BuildContext())
opExporterVersion.WithLabelValues(
strings.Trim(version.Version, "\""), version.GitCommit, version.GoVersion, version.BuildDate).Inc()
health := healthCheck{ health := healthCheck{
mu: new(sync.RWMutex), mu: new(sync.RWMutex),
height: 0, height: 0,
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
var ( var (
Version string Version string
GitCommit string GitCommit string
BuildUser string
BuildDate string BuildDate string
GoVersion = runtime.Version() GoVersion = runtime.Version()
) )
...@@ -18,5 +17,5 @@ func Info() string { ...@@ -18,5 +17,5 @@ func Info() string {
} }
func BuildContext() string { func BuildContext() string {
return fmt.Sprintf("(go=%s, user=%s, date=%s)", GoVersion, BuildUser, BuildDate) return fmt.Sprintf("(go=%s, date=%s)", GoVersion, BuildDate)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment