Stats (Statistics) - is a service designed to calculate and present statistical information from a Blockscout instance. This service establishes a connection with the Blockscout database and periodically updates a collection of charts, including lines and counters, based on a predefined schedule. The calculated data is then made available through a REST API, allowing users to access and utilize the statistical information.
The service consists of 2 parts, a stats calculation library and a transport layer that serves requests:
- stats - implements actual chart calculation logic as a library and exposes an interface to be used by the transport layer;
- A transport layer that implements some APIs over the service (stats-server).
- Postgresql database for this service
- Access to Blockscout database
-
You can build the provided sources using Dockerfile
-
Alternatively, you can use docker images from our registry
- You can use compose file from blockscout main repo to run latest version of stats with database
cargo install --git https://github.com/blockscout/blockscout-rs stats-server
stats-server
Variable | Description | Default value |
---|---|---|
STATS__DB_URL | Postgres URL to stats db | '' |
STATS__BLOCKSCOUT_DB_URL | Postgres URL to blockscout db | '' |
STATS__CREATE_DATABASE | Boolean. Creates database on start | false |
STATS__RUN_MIGRATIONS | Boolean. Runs migrations on start | false |
STATS__CHARTS_CONFIG | Path to charts.json config file |
./config/charts.json |
STATS__LAYOUT_CONFIG | Path to layout.json config file |
./config/layout.json |
STATS__UPDATE_GROUPS_CONFIG | Path to update_groups.json config file |
./config/update_groups.json |
STATS__FORCE_UPDATE_ON_START | Boolean. Fully recalculates all charts on start | false |
STATS__CONCURRENT_START_UPDATES | Integer. Amount of concurrent charts update on start | 3 |
Blockscout provides a collection of predefined charts to visualize statistics. You can enable or disable these charts by modifying the charts.json
file. Layout of the charts (which is returned by the server) is configurable in layout.json
. Schedule of updated charts for each group is set up in update_groups.json
.
The default configurations can be found here. You can use these files as a base for customization.
If non-default config files are used, respective environment variables (e.g. STATS__CHARTS_CONFIG
) should be set to the new files.
To disable unnecessary charts, open the charts.json
file and set enabled: false
for them. Other parameters can also be set/modified there.
Categories for line charts, category metadata, and chart order within category are set in layout.json
.
Charts dependant on each other are combined in update groups. Charts within one update group are updated together according to their dependency relations. Updates are scheduled for each such group in update_groups.json
file.
just start-postgres
-
Start blockscout instance with varialbe
DATABASE_URL=postgres://postgres:[email protected]:5432/blockscout
-
Start stats server:
export STATS__RUN_MIGRATIONS=true
export STATS__DB_URL="postgres://postgres:admin@localhost:5432/stats"
export STATS__BLOCKSCOUT_DB_URL="postgres://postgres:admin@localhost:5432/blockscout"
cargo run --bin stats-server
Alternatively, you can use docker-compose.dev.yml
for simplicity.
- Set
ETHEREUM_JSONRPC_HTTP_URL
andETHEREUM_JSONRPC_TRACE_URL
to ethereum node you have access to (inbackend
(Blockscout) service) - Set
FIRST_BLOCK
to some recent block for less load on the node - Update
ETHEREUM_JSONRPC_VARIANT
if necessary - Run
docker compose -f docker-compose.dev.yml up -d