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

monitoring dashboard #876

Merged
merged 15 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 12 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
8 changes: 7 additions & 1 deletion cmd/algorand-indexer/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,14 @@ func handleBlock(block *rpcs.EncodedBlockCert, imp importer.Importer) error {
// Ignore round 0 (which is empty).
if block.Block.Round() > 0 {
metrics.BlockImportTimeSeconds.Observe(dt.Seconds())
metrics.ImportedTxnsPerBlock.Observe(float64(len(block.Block.Payset)))
metrics.ImportedRoundGauge.Set(float64(block.Block.Round()))
txnCountByType := make(map[string]int)
for _, txn := range block.Block.Payset {
txnCountByType[string(txn.Txn.Type)]++
}
for k, v := range txnCountByType {
metrics.ImportedTxnsPerBlock.WithLabelValues(k).Set(float64(v))
}
}

logger.Infof("round r=%d (%d txn) imported in %s", block.Block.Round(), len(block.Block.Payset), dt.String())
Expand Down
13 changes: 13 additions & 0 deletions fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/algorand/go-algorand-sdk/client/v2/algod"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/rpcs"
"github.com/algorand/indexer/util/metrics"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -111,7 +112,13 @@ func (bot *fetcherImpl) catchupLoop(ctx context.Context) error {
var blockbytes []byte
aclient := bot.Algod()
for {
start := time.Now()

blockbytes, err = aclient.BlockRaw(bot.nextRound).Do(ctx)

dt := time.Since(start)
metrics.GetAlgodRawBlockTimeSeconds.Observe(dt.Seconds())

if err != nil {
// If context has expired.
if ctx.Err() != nil {
Expand Down Expand Up @@ -150,7 +157,13 @@ func (bot *fetcherImpl) followLoop(ctx context.Context) error {
"r=%d error getting status %d", retries, bot.nextRound)
continue
}
start := time.Now()

blockbytes, err = aclient.BlockRaw(bot.nextRound).Do(ctx)

dt := time.Since(start)
metrics.GetAlgodRawBlockTimeSeconds.Observe(dt.Seconds())

if err == nil {
break
} else if ctx.Err() != nil { // if context has expired
Expand Down
1 change: 1 addition & 0 deletions monitoring/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DB_CONNECTION = "host=indexer-db port=5432 user=algorand password=algorand dbname=indexer_db sslmode=disable"
shiqizng marked this conversation as resolved.
Show resolved Hide resolved
31 changes: 31 additions & 0 deletions monitoring/Dockerfile-indexer
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM alpine:latest

RUN apk add --no-cache git make musl-dev go bash libtool autoconf automake build-base libsodium-dev boost-dev

# Configure Go
ENV GOROOT /usr/lib/go
ENV GOPATH /go
ENV PATH /go/bin:$PATH

RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin

# Build and run indexer
RUN mkdir /work
WORKDIR /work
ADD . ./
RUN make
WORKDIR /work/cmd/algorand-indexer
ENV CGO_ENABLED="1"
RUN go build

# The sleep is to wait until postgres starts
CMD ["/bin/sh", "-c", "\
echo $ALGOD_NET && \
echo $CONNECTION_STRING &&\
sleep 5 && \
./algorand-indexer daemon \
--server \":${PORT}\" \
-P \"${CONNECTION_STRING}\" \
--metrics-mode VERBOSE \
--algod-net \"${ALGOD_NET}\" \
--algod-token ${ALGOD_TOKEN}"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get alpine working, @bricerisingalgorand suggested there is an issue with musl and I should try ubuntu. This configuration started:

ARG GO_VERSION=1.17.5
FROM golang:$GO_VERSION

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y apt-utils curl git git-core bsdmainutils python3


# Build go-algorand
RUN mkdir /work
WORKDIR /work
ADD . ./
WORKDIR /work/third_party/go-algorand
RUN ./scripts/configure_dev.sh
RUN make

# Build indexer
WORKDIR /work
RUN make
WORKDIR /work/cmd/algorand-indexer
ENV CGO_ENABLED="1"
RUN go build

# The sleep is to wait until postgres starts
CMD ["/bin/sh", "-c", "\
  echo $ALGOD_NET && \
  echo $CONNECTION_STRING &&\
  sleep 5 && \
  ./algorand-indexer daemon \
    --server \":${PORT}\" \
    -P \"${CONNECTION_STRING}\" \
    --metrics-mode VERBOSE \
    --algod-net \"${ALGOD_NET}\" \
    --algod-token ${ALGOD_TOKEN}"]

57 changes: 57 additions & 0 deletions monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## Indexer Monitoring Dashboard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to update these instructions to make it clear that they are for starting a demo. The top-level README should also get some additional instructions for installing the dashboard on an existing prometheus/grafana instance.

To that end, I think you can leave out details about how the docker-compose file can be updated to connect to a different indexer.

A monitoring dashboard displaying indexer performance metrics.

### To start a monitoring dashboard
Configurable env vars, `DB_CONNECTION`, `ALGOD_NET` and `ALGOD_TOKEN`. The defaults are set in `.env`. User must provide a valid `ALGOD_NET` and `ALGOD_TOKEN` pair.

if indexer is not already running, start all services in `docker-compose.yml`

`docker-compose up -d`

if indexer is already running, start monitoring services only.

`docker-compose up -d prometheus grafana`

prometheus target should be updated to listen to a correct indexer address (host:port),

```json
static_configs:
- targets: ['indexer:8888']
```

By default,
- indexer is running on http://localhost:8888
- grafana is running on http://localhost:3000; default login (admin/admin)

### View metrics on grafana

- In grafana configurations, add a PostgreSQL datasource. See example below.
- Go to Import and upload dashboard.json
- Run `create extension pg_stat_statements;` sql on db to enable query stats from Postgres
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working for me. After importing the dashboard everything is blank:
image

In the panels there is an error:
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to import on deployment outside of docker, but the postgres portion didn't seem to work. The query ran fine in pqsl but didn't show up in grafana.


![](examples/postgresql_conn.png)
![](examples/widgets.png)


**Default widgets**:

Importing
- Block import time
- Transactions per block by type
- TPS
- Round #

Query

- Request duration
- Request duraton by url
- Postgres Eval Time

System

- average CPU usage
- average Heap Alloc
- Postgres table info
- Postgres queries info


Loading