Commit a756c1f3 authored by Ben Wilson's avatar Ben Wilson

Removed OVM string, added success in calling metric

parent 71bfa3fe
SHELL := /bin/bash
GITCOMMIT := $(shell git rev-parse HEAD)
GITDATE := $(shell git show -s --format='%ct')
GITVERSION := $(shell cat package.json | jq .version)
VERSION := `git describe --abbrev=0`
GITCOMMIT := `git rev-parse HEAD`
BUILDDATE := `date +%Y-%m-%d`
BUILDUSER := `whoami`
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
LDFLAGSSTRING +=-X main.GitVersion=$(GITVERSION)
LDFLAGS :=-ldflags "$(LDFLAGSSTRING)"
l2geth-exporter:
env GO111MODULE=on go build $(LDFLAGS)
all: build
build:
CGO_ENABLED=0 go build $(LDFLAGS)
clean:
rm l2geth-exporter
......@@ -24,15 +27,15 @@ lint:
binding:
$(eval temp := $(shell mktemp))
cat ../../packages/contracts/deployments/mainnet/OVM_CanonicalTransactionChain.json \
cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq -r .bytecode > $(temp)
cat ../../packages/contracts/deployments/mainnet/OVM_CanonicalTransactionChain.json \
cat ../../packages/contracts/deployments/mainnet/CanonicalTransactionChain.json \
| jq .abi \
| abigen --pkg bindings \
--abi - \
--out bindings/OVM_CanonicalTransactionChain.go \
--type OVMCanonicalTransactionChain \
--out bindings/CanonicalTransactionChain.go \
--type CanonicalTransactionChain \
--bin $(temp)
rm $(temp)
This diff is collapsed.
......@@ -6,15 +6,21 @@ import (
//Define the metrics we wish to expose
var (
ovmctcTotalElements = prometheus.NewGaugeVec(
ctcTotalElements = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "ovmctc_total_elements",
Help: "OVM CTC GetTotalElements value."},
Name: "l2geth_ctc_total_elements",
Help: "CTC GetTotalElements value."},
[]string{"state"},
)
ctcTotalElementsCallSuccess = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "l2geth_ctc_total_elements_call_success",
Help: "CTC GetTotalElements call success."},
)
)
func init() {
//Register metrics with prometheus
prometheus.MustRegister(ovmctcTotalElements)
prometheus.MustRegister(ctcTotalElements)
prometheus.MustRegister(ctcTotalElementsCallSuccess)
}
module github.com/optimisticben/optimism/go/l2geth-exporter
module github.com/ethereum-optimism/optimism/go/l2geth-exporter
go 1.16
require (
github.com/ethereum/go-ethereum v1.10.8
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.11.0
)
This diff is collapsed.
......@@ -4,28 +4,28 @@ import (
"context"
"math/big"
"github.com/ethereum-optimism/optimism/go/l2geth-exporter/bindings"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/optimisticben/optimism/go/l2geth-exporter/bindings"
)
// OVMCTC interacts with the OVM CTC contract
type OVMCTC struct {
// CTC interacts with the OVM CTC contract
type CTC struct {
Ctx context.Context
Address common.Address
Client *ethclient.Client
}
func (ovmctc *OVMCTC) GetTotalElements() (*big.Int, error) {
func (ctc *CTC) GetTotalElements() (*big.Int, error) {
contract, err := bindings.NewOVMCanonicalTransactionChainCaller(ovmctc.Address, ovmctc.Client)
contract, err := bindings.NewCanonicalTransactionChainCaller(ctc.Address, ctc.Client)
if err != nil {
return nil, err
}
totalElements, err := contract.GetTotalElements(&bind.CallOpts{
Context: ovmctc.Ctx,
Context: ctc.Ctx,
})
if err != nil {
return nil, err
......
......@@ -6,10 +6,10 @@ import (
"os"
"time"
"github.com/ethereum-optimism/optimism/go/l2geth-exporter/l1contracts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/log"
"github.com/optimisticben/optimism/go/l2geth-exporter/l1contracts"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
......@@ -19,19 +19,21 @@ func main() {
listenAddress = ":9100"
}
gethUrl := os.Getenv("GETH_URL")
if gethUrl == "" {
log.Error("GETH_URL environmental variable is required")
log.Root().SetHandler(log.CallerFileHandler(log.StdoutHandler))
l1Url := os.Getenv("L1_URL")
if l1Url == "" {
log.Error("L1_URL environmental variable is required")
os.Exit(1)
}
ovmCtcAddress := os.Getenv("OVM_CTC_ADDRESS")
if ovmCtcAddress == "" {
log.Error("OVM_CTC_ADDRESS environmental variable is required")
ctcAddress := os.Getenv("CTC_ADDRESS")
if ctcAddress == "" {
log.Error("CTC_ADDRESS environmental variable is required")
os.Exit(1)
}
client, err := ethclient.Dial(gethUrl)
client, err := ethclient.Dial(l1Url)
if err != nil {
log.Error("Problem connecting to GETH: %s", err)
log.Error("Problem connecting to L1: %s", err)
}
http.Handle("/metrics", promhttp.Handler())
......@@ -44,17 +46,17 @@ func main() {
</body>
</html>`))
})
go getCTCTotalElements(ovmCtcAddress, client)
go getCTCTotalElements(ctcAddress, client)
log.Info("Listening on", listenAddress)
log.Info("Program starting", "listenAddress", listenAddress, "GETH_URL", l1Url, "CTC_ADDRESS", ctcAddress)
if err := http.ListenAndServe(listenAddress, nil); err != nil {
log.Error("Can't start http server: %s", err)
log.Error("Can't start http server", "error", err)
}
}
func getCTCTotalElements(address string, client *ethclient.Client) {
ovmCTC := l1contracts.OVMCTC{
ctc := l1contracts.CTC{
Address: common.HexToAddress(address),
Client: client,
}
......@@ -62,16 +64,18 @@ func getCTCTotalElements(address string, client *ethclient.Client) {
ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()
for {
<-ticker.C
totalElements, err := ovmCTC.GetTotalElements()
totalElements, err := ctc.GetTotalElements()
if err != nil {
log.Error("Error calling GetTotalElements: %s", err)
ctcTotalElementsCallSuccess.Set(0)
log.Error("Error calling GetTotalElements", "error", err)
continue
}
ctcTotalElementsCallSuccess.Set(1)
totalElementsFloat, _ := new(big.Float).SetInt(totalElements).Float64()
ovmctcTotalElements.WithLabelValues(
ctcTotalElements.WithLabelValues(
"latest").Set(totalElementsFloat)
<-ticker.C
}
}
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