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 (
|
var (
|
||||||
DefaultRegistry = NewRegistry()
|
DefaultRegistry = NewRegistry()
|
||||||
EphemeralRegistry = NewRegistry()
|
EphemeralRegistry = NewRegistry()
|
||||||
|
AccountingRegistry = NewRegistry()
|
||||||
)
|
)
|
||||||
|
|
||||||
// Call the given function for each registered metric.
|
// Call the given function for each registered metric.
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,6 @@ var (
|
||||||
mPeerDrops metrics.Counter
|
mPeerDrops metrics.Counter
|
||||||
// how many times local node overdrafted and dropped
|
// how many times local node overdrafted and dropped
|
||||||
mSelfDrops metrics.Counter
|
mSelfDrops metrics.Counter
|
||||||
|
|
||||||
MetricsRegistry metrics.Registry
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Prices defines how prices are being passed on to the accounting instance
|
// 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
|
// It also instantiates the given metrics and starts the persisting go-routine which
|
||||||
// at the passed interval writes the metrics to a LevelDB
|
// at the passed interval writes the metrics to a LevelDB
|
||||||
func SetupAccountingMetrics(reportInterval time.Duration, path string) *AccountingMetrics {
|
func SetupAccountingMetrics(reportInterval time.Duration, path string) *AccountingMetrics {
|
||||||
// create an empty registry
|
|
||||||
MetricsRegistry = metrics.NewRegistry()
|
|
||||||
// instantiate the metrics
|
// instantiate the metrics
|
||||||
mBalanceCredit = metrics.NewRegisteredCounterForced("account.balance.credit", MetricsRegistry)
|
mBalanceCredit = metrics.NewRegisteredCounterForced("account.balance.credit", metrics.AccountingRegistry)
|
||||||
mBalanceDebit = metrics.NewRegisteredCounterForced("account.balance.debit", MetricsRegistry)
|
mBalanceDebit = metrics.NewRegisteredCounterForced("account.balance.debit", metrics.AccountingRegistry)
|
||||||
mBytesCredit = metrics.NewRegisteredCounterForced("account.bytes.credit", MetricsRegistry)
|
mBytesCredit = metrics.NewRegisteredCounterForced("account.bytes.credit", metrics.AccountingRegistry)
|
||||||
mBytesDebit = metrics.NewRegisteredCounterForced("account.bytes.debit", MetricsRegistry)
|
mBytesDebit = metrics.NewRegisteredCounterForced("account.bytes.debit", metrics.AccountingRegistry)
|
||||||
mMsgCredit = metrics.NewRegisteredCounterForced("account.msg.credit", MetricsRegistry)
|
mMsgCredit = metrics.NewRegisteredCounterForced("account.msg.credit", metrics.AccountingRegistry)
|
||||||
mMsgDebit = metrics.NewRegisteredCounterForced("account.msg.debit", MetricsRegistry)
|
mMsgDebit = metrics.NewRegisteredCounterForced("account.msg.debit", metrics.AccountingRegistry)
|
||||||
mPeerDrops = metrics.NewRegisteredCounterForced("account.peerdrops", MetricsRegistry)
|
mPeerDrops = metrics.NewRegisteredCounterForced("account.peerdrops", metrics.AccountingRegistry)
|
||||||
mSelfDrops = metrics.NewRegisteredCounterForced("account.selfdrops", MetricsRegistry)
|
mSelfDrops = metrics.NewRegisteredCounterForced("account.selfdrops", metrics.AccountingRegistry)
|
||||||
|
|
||||||
// create the DB and start persisting
|
// 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
|
// Send takes a peer, a size and a msg and
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ var (
|
||||||
Name: "metrics.influxdb.export",
|
Name: "metrics.influxdb.export",
|
||||||
Usage: "Enable metrics export/push to an external InfluxDB database",
|
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{
|
MetricsInfluxDBEndpointFlag = cli.StringFlag{
|
||||||
Name: "metrics.influxdb.endpoint",
|
Name: "metrics.influxdb.endpoint",
|
||||||
Usage: "Metrics InfluxDB endpoint",
|
Usage: "Metrics InfluxDB endpoint",
|
||||||
|
|
@ -66,6 +70,7 @@ var (
|
||||||
var Flags = []cli.Flag{
|
var Flags = []cli.Flag{
|
||||||
utils.MetricsEnabledFlag,
|
utils.MetricsEnabledFlag,
|
||||||
MetricsEnableInfluxDBExportFlag,
|
MetricsEnableInfluxDBExportFlag,
|
||||||
|
MetricsEnableInfluxDBAccountingExportFlag,
|
||||||
MetricsInfluxDBEndpointFlag,
|
MetricsInfluxDBEndpointFlag,
|
||||||
MetricsInfluxDBDatabaseFlag,
|
MetricsInfluxDBDatabaseFlag,
|
||||||
MetricsInfluxDBUsernameFlag,
|
MetricsInfluxDBUsernameFlag,
|
||||||
|
|
@ -78,6 +83,7 @@ func Setup(ctx *cli.Context) {
|
||||||
log.Info("Enabling swarm metrics collection")
|
log.Info("Enabling swarm metrics collection")
|
||||||
var (
|
var (
|
||||||
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
enableExport = ctx.GlobalBool(MetricsEnableInfluxDBExportFlag.Name)
|
||||||
|
enableAccountingExport = ctx.GlobalBool(MetricsEnableInfluxDBAccountingExportFlag.Name)
|
||||||
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
|
endpoint = ctx.GlobalString(MetricsInfluxDBEndpointFlag.Name)
|
||||||
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
|
database = ctx.GlobalString(MetricsInfluxDBDatabaseFlag.Name)
|
||||||
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
|
username = ctx.GlobalString(MetricsInfluxDBUsernameFlag.Name)
|
||||||
|
|
@ -94,5 +100,12 @@ func Setup(ctx *cli.Context) {
|
||||||
"host": hosttag,
|
"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