Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services/horizon: Add additional DB metrics #2844

Merged
merged 3 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions services/horizon/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this
file. This project adheres to [Semantic Versioning](http://semver.org/).x

## Unreleased

* Add new DB metrics ([#2844](https://github.com/stellar/go/pull/2844)):
* `db_in_use_connections` - number of opened DB connections in use (not idle),
* `db_wait_count` - number of connections waited for,
* `db_wait_duration` - total time blocked waiting for a new connection.

## v1.6.0

* Add `--parallel-workers` and `--parallel-job-size` to `horizon db reingest range`. `--parallel-workers` will parallelize reingestion using the supplied number of workers. ([#2724](https://github.com/stellar/go/pull/2724))
Expand Down
11 changes: 9 additions & 2 deletions services/horizon/internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ type App struct {
metrics metrics.Registry
historyLatestLedgerGauge metrics.Gauge
historyElderLedgerGauge metrics.Gauge
horizonConnGauge metrics.Gauge
dbOpenConnectionsGauge metrics.Gauge
dbInUseConnectionsGauge metrics.Gauge
dbWaitCountGauge metrics.Gauge
dbWaitDurationTimer metrics.Timer
coreLatestLedgerGauge metrics.Gauge
goroutineGauge metrics.Gauge
}
Expand Down Expand Up @@ -404,12 +407,16 @@ func (a *App) UpdateStellarCoreInfo() {
// db connections and ledger state
func (a *App) UpdateMetrics() {
a.goroutineGauge.Update(int64(runtime.NumGoroutine()))

ls := ledger.CurrentState()
a.historyLatestLedgerGauge.Update(int64(ls.HistoryLatest))
a.historyElderLedgerGauge.Update(int64(ls.HistoryElder))
a.coreLatestLedgerGauge.Update(int64(ls.CoreLatest))

a.horizonConnGauge.Update(int64(a.historyQ.Session.DB.Stats().OpenConnections))
a.dbOpenConnectionsGauge.Update(int64(a.historyQ.Session.DB.Stats().OpenConnections))
a.dbInUseConnectionsGauge.Update(int64(a.historyQ.Session.DB.Stats().InUse))
a.dbWaitCountGauge.Update(int64(a.historyQ.Session.DB.Stats().WaitCount))
a.dbWaitDurationTimer.Update(a.historyQ.Session.DB.Stats().WaitDuration)
}

// DeleteUnretainedHistory forwards to the app's reaper. See
Expand Down
21 changes: 15 additions & 6 deletions services/horizon/internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,26 @@ func initLogglyLog(app *App) {
}

func initDbMetrics(app *App) {
app.historyLatestLedgerGauge = metrics.NewGauge()
app.historyElderLedgerGauge = metrics.NewGauge()
app.coreLatestLedgerGauge = metrics.NewGauge()
app.horizonConnGauge = metrics.NewGauge()
app.goroutineGauge = metrics.NewGauge()
app.metrics.Register("goroutines", app.goroutineGauge)

app.historyLatestLedgerGauge = metrics.NewGauge()
app.metrics.Register("history.latest_ledger", app.historyLatestLedgerGauge)
app.historyElderLedgerGauge = metrics.NewGauge()
app.metrics.Register("history.elder_ledger", app.historyElderLedgerGauge)
app.coreLatestLedgerGauge = metrics.NewGauge()
app.metrics.Register("stellar_core.latest_ledger", app.coreLatestLedgerGauge)

app.dbOpenConnectionsGauge = metrics.NewGauge()
app.metrics.Register("db.open_connections", app.dbOpenConnectionsGauge)
app.dbInUseConnectionsGauge = metrics.NewGauge()
app.metrics.Register("db.in_use_connections", app.dbInUseConnectionsGauge)
app.dbWaitCountGauge = metrics.NewGauge()
app.metrics.Register("db.wait_count", app.dbWaitCountGauge)
app.dbWaitDurationTimer = metrics.NewTimer()
app.metrics.Register("db.wait_duration", app.dbWaitDurationTimer)

app.metrics.Register("order_book_stream.latest_ledger", app.orderBookStream.LatestLedgerGauge)
app.metrics.Register("history.open_connections", app.horizonConnGauge)
app.metrics.Register("goroutines", app.goroutineGauge)
}

// initIngestMetrics registers the metrics for the ingestion into the provided
Expand Down