mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/metrics: Send the accounting registry to InfluxDB
This commit is contained in:
parent
1636d9574b
commit
cbd51d2ee1
3 changed files with 30 additions and 19 deletions
|
|
@ -314,6 +314,7 @@ func (r *PrefixedRegistry) UnregisterAll() {
|
|||
var (
|
||||
DefaultRegistry = NewRegistry()
|
||||
EphemeralRegistry = NewRegistry()
|
||||
AccountingRegistry = NewRegistry()
|
||||
)
|
||||
|
||||
// Call the given function for each registered metric.
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ var (
|
|||
mPeerDrops metrics.Counter
|
||||
// how many times local node overdrafted and dropped
|
||||
mSelfDrops metrics.Counter
|
||||
|
||||
MetricsRegistry metrics.Registry
|
||||
)
|
||||
|
||||
// Prices defines how prices are being passed on to the accounting instance
|
||||
|
|
@ -115,19 +113,18 @@ func NewAccounting(balance Balance, po Prices) *Accounting {
|
|||
// It also instantiates the given metrics and starts the persisting go-routine which
|
||||
// at the passed interval writes the metrics to a LevelDB
|
||||
func SetupAccountingMetrics(reportInterval time.Duration, path string) *AccountingMetrics {
|
||||
// create an empty registry
|
||||
MetricsRegistry = metrics.NewRegistry()
|
||||
// instantiate the metrics
|
||||
mBalanceCredit = metrics.NewRegisteredCounterForced("account.balance.credit", MetricsRegistry)
|
||||
mBalanceDebit = metrics.NewRegisteredCounterForced("account.balance.debit", MetricsRegistry)
|
||||
mBytesCredit = metrics.NewRegisteredCounterForced("account.bytes.credit", MetricsRegistry)
|
||||
mBytesDebit = metrics.NewRegisteredCounterForced("account.bytes.debit", MetricsRegistry)
|
||||
mMsgCredit = metrics.NewRegisteredCounterForced("account.msg.credit", MetricsRegistry)
|
||||
mMsgDebit = metrics.NewRegisteredCounterForced("account.msg.debit", MetricsRegistry)
|
||||
mPeerDrops = metrics.NewRegisteredCounterForced("account.peerdrops", MetricsRegistry)
|
||||
mSelfDrops = metrics.NewRegisteredCounterForced("account.selfdrops", MetricsRegistry)
|
||||
mBalanceCredit = metrics.NewRegisteredCounterForced("account.balance.credit", metrics.AccountingRegistry)
|
||||
mBalanceDebit = metrics.NewRegisteredCounterForced("account.balance.debit", metrics.AccountingRegistry)
|
||||
mBytesCredit = metrics.NewRegisteredCounterForced("account.bytes.credit", metrics.AccountingRegistry)
|
||||
mBytesDebit = metrics.NewRegisteredCounterForced("account.bytes.debit", metrics.AccountingRegistry)
|
||||
mMsgCredit = metrics.NewRegisteredCounterForced("account.msg.credit", metrics.AccountingRegistry)
|
||||
mMsgDebit = metrics.NewRegisteredCounterForced("account.msg.debit", metrics.AccountingRegistry)
|
||||
mPeerDrops = metrics.NewRegisteredCounterForced("account.peerdrops", metrics.AccountingRegistry)
|
||||
mSelfDrops = metrics.NewRegisteredCounterForced("account.selfdrops", metrics.AccountingRegistry)
|
||||
|
||||
// create the DB and start persisting
|
||||
return NewAccountingMetrics(MetricsRegistry, reportInterval, path)
|
||||
return NewAccountingMetrics(metrics.AccountingRegistry, reportInterval, path)
|
||||
}
|
||||
|
||||
// Send takes a peer, a size and a msg and
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ var (
|
|||
Name: "metrics.influxdb.export",
|
||||
Usage: "Enable metrics export/push to an external InfluxDB database",
|
||||
}
|
||||
MetricsEnableInfluxDBAccountingExportFlag = cli.BoolFlag{
|
||||
Name: "metrics.influxdb.accounting",
|
||||
Usage: "Enable accounting metrics export/push to an external InfluxDB database",
|
||||
}
|
||||
MetricsInfluxDBEndpointFlag = cli.StringFlag{
|
||||
Name: "metrics.influxdb.endpoint",
|
||||
Usage: "Metrics InfluxDB endpoint",
|
||||
|
|
@ -66,6 +70,7 @@ var (
|
|||
var Flags = []cli.Flag{
|
||||
utils.MetricsEnabledFlag,
|
||||
MetricsEnableInfluxDBExportFlag,
|
||||
MetricsEnableInfluxDBAccountingExportFlag,
|
||||
MetricsInfluxDBEndpointFlag,
|
||||
MetricsInfluxDBDatabaseFlag,
|
||||
MetricsInfluxDBUsernameFlag,
|
||||
|
|
@ -77,12 +82,13 @@ func Setup(ctx *cli.Context) {
|
|||
if gethmetrics.Enabled {
|
||||
log.Info("Enabling swarm metrics collection")
|
||||
var (
|
||||
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
||||
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
|
||||
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
|
||||
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
|
||||
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
|
||||
hosttag = ctx.GlobalString(MetricsInfluxDBHostTagFlag.Name)
|
||||
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
||||
enableAccountingExport = ctx.GlobalBool(MetricsEnableInfluxDBAccountingExportFlag.Name)
|
||||
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
|
||||
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
|
||||
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
|
||||
password = ctx.GlobalString(MetricsInfluxDBPasswordFlag.Name)
|
||||
hosttag = ctx.GlobalString(MetricsInfluxDBHostTagFlag.Name)
|
||||
)
|
||||
|
||||
// Start system runtime metrics collection
|
||||
|
|
@ -94,5 +100,12 @@ func Setup(ctx *cli.Context) {
|
|||
"host": hosttag,
|
||||
})
|
||||
}
|
||||
|
||||
if enableAccountingExport {
|
||||
log.Info("Enabling accounting metrics export to InfluxDB")
|
||||
go influxdb.InfluxDBWithTags(gethmetrics.AccountingRegistry, 10*time.Second, endpoint, database, username, password, "accounting.", map[string]string{
|
||||
"host": hosttag,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue