Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
11123565
Unverified
Commit
11123565
authored
Aug 24, 2022
by
Ben Wilson
Committed by
GitHub
Aug 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add op-exporter feature to collect baseFee (#3306)
Co-authored-by:
Matthew Slipper
<
me@matthewslipper.com
>
parent
b2898008
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
2 deletions
+63
-2
collector.go
op-exporter/collector.go
+14
-1
main.go
op-exporter/main.go
+49
-1
No files found.
op-exporter/collector.go
View file @
11123565
...
...
@@ -6,6 +6,18 @@ import (
//Define the metrics we wish to expose
var
(
gasBaseFeeMetric
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"op_baseFee"
,
Help
:
"Gas base fee."
},
[]
string
{
"network"
,
"layer"
},
)
gasUsedMetric
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"op_gasUsed"
,
Help
:
"Gas Used."
},
[]
string
{
"network"
,
"layer"
},
)
gasPrice
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"op_gasPrice"
,
...
...
@@ -38,5 +50,6 @@ func init() {
prometheus
.
MustRegister
(
blockNumber
)
prometheus
.
MustRegister
(
healthySequencer
)
prometheus
.
MustRegister
(
opExporterVersion
)
prometheus
.
MustRegister
(
gasBaseFeeMetric
)
prometheus
.
MustRegister
(
gasUsedMetric
)
}
op-exporter/main.go
View file @
11123565
...
...
@@ -53,6 +53,14 @@ var (
"k8s.enable"
,
"Enable kubernetes info lookup."
,
)
.
Default
(
"false"
)
.
Bool
()
enableRollUpGasPrices
=
kingpin
.
Flag
(
"rollUpGasPrices.enable"
,
"Enable rollUpGasPrices info lookup."
,
)
.
Default
(
"false"
)
.
Bool
()
enableGasBaseFee
=
kingpin
.
Flag
(
"gaseBaseFee.enable"
,
"Enable gaseBaseFee info lookup."
,
)
.
Default
(
"false"
)
.
Bool
()
)
type
healthCheck
struct
{
...
...
@@ -64,6 +72,11 @@ type healthCheck struct {
version
*
string
}
type
getBlockByNumberResponse
struct
{
BaseFeePerGas
string
`json:"baseFeePerGas"`
GasUsed
string
`json:"gasUsed"`
}
func
healthHandler
(
health
*
healthCheck
)
http
.
HandlerFunc
{
return
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
health
.
mu
.
RLock
()
...
...
@@ -105,8 +118,16 @@ func main() {
</body>
</html>`
))
})
go
getRollupGasPrices
()
go
getBlockNumber
(
&
health
)
if
*
enableRollUpGasPrices
{
go
getRollupGasPrices
()
}
if
*
enableGasBaseFee
{
go
getBaseFee
()
}
if
*
enableK8sQuery
{
client
,
err
:=
k8sClient
.
Newk8sClient
()
if
err
!=
nil
{
...
...
@@ -203,6 +224,33 @@ func getBlockNumber(health *healthCheck) {
}
}
func
getBaseFee
()
{
rpcClient
:=
jsonrpc
.
NewClientWithOpts
(
*
rpcProvider
,
&
jsonrpc
.
RPCClientOpts
{})
var
getBlockByNumbeResponse
*
getBlockByNumberResponse
for
{
if
err
:=
rpcClient
.
CallFor
(
&
getBlockByNumbeResponse
,
"eth_getBlockByNumber"
,
"latest"
,
false
);
err
!=
nil
{
log
.
Errorln
(
"Error calling eth_getBlockByNumber"
,
err
)
}
else
{
log
.
Infoln
(
"Got baseFee response: "
,
*
getBlockByNumbeResponse
)
baseFeePerGas
,
err
:=
hexutil
.
DecodeUint64
(
getBlockByNumbeResponse
.
BaseFeePerGas
)
if
err
!=
nil
{
log
.
Warnln
(
"Error converting baseFeePerGas "
+
getBlockByNumbeResponse
.
BaseFeePerGas
)
}
gasBaseFeeMetric
.
WithLabelValues
(
*
networkLabel
,
"layer2"
)
.
Set
(
float64
(
baseFeePerGas
))
gasUsed
,
err
:=
hexutil
.
DecodeUint64
(
getBlockByNumbeResponse
.
GasUsed
)
if
err
!=
nil
{
log
.
Warnln
(
"Error converting gasUsed "
+
getBlockByNumbeResponse
.
GasUsed
)
}
gasUsedMetric
.
WithLabelValues
(
*
networkLabel
,
"layer2"
)
.
Set
(
float64
(
gasUsed
))
}
time
.
Sleep
(
time
.
Duration
(
*
sequencerPollingSeconds
)
*
time
.
Second
)
}
}
func
getRollupGasPrices
()
{
rpcClient
:=
jsonrpc
.
NewClientWithOpts
(
*
rpcProvider
,
&
jsonrpc
.
RPCClientOpts
{})
var
rollupGasPrices
*
GetRollupGasPrices
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment