Skip to content

Commit 7d7f4e3

Browse files
committed
Innitial commit
0 parents  commit 7d7f4e3

File tree

20 files changed

+1556
-0
lines changed

20 files changed

+1556
-0
lines changed

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Basic dependabot.yml file with
2+
# minimum configuration for two package managers
3+
4+
version: 2
5+
updates:
6+
# Enable version updates for pip (Python)
7+
- package-ecosystem: "pip"
8+
directory: "/"
9+
schedule:
10+
interval: "weekly"
11+
# Only allow updates to the lockfile for pip and
12+
# ignore any version updates that affect the manifest
13+
versioning-strategy: lockfile-only
14+
15+
# Enable version updates for Docker
16+
- package-ecosystem: "docker"
17+
# Look for a `Dockerfile` in the `root` directory
18+
directory: "/"
19+
# Check for updates once a week
20+
schedule:
21+
interval: "weekly"

.github/workflows/publish.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: publish
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
env:
7+
REGISTRY: ghcr.io
8+
IMAGE_NAME: ${{ github.repository }}
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Create GitHub release
15+
uses: Roang-zero1/github-create-release-action@master
16+
with:
17+
version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
21+
build-and-push-image:
22+
runs-on: ubuntu-latest
23+
permissions:
24+
contents: read
25+
packages: write
26+
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v3
30+
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
46+
with:
47+
context: .
48+
push: true
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
local*
14+
15+
# Dependency directories (remove the comment below to include it)
16+
# vendor/

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-ast

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## v1.0.0
4+
5+
Innitial release

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM python:3.9.10 AS build
2+
COPY requirements.txt .
3+
RUN pip install -r ./requirements.txt
4+
5+
FROM gcr.io/distroless/python3:nonroot
6+
7+
COPY --from=build /usr/local/lib/python3.9/site-packages/ \
8+
/usr/lib/python3.9/.
9+
10+
ENV LC_ALL C.UTF-8
11+
WORKDIR /usr/src/app
12+
COPY src/*.py .
13+
14+
# https://github.com/GoogleContainerTools/distroless/blob/main/experimental/python3/BUILD#L77
15+
USER nonroot
16+
CMD ["exporter.py"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Chainlink Labs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# EVM RPC Websocket Exporter
2+
Simple exporter used to scrape different metrics from EVM compatible websocket RPCs.
3+
4+
## Metrics
5+
For list of metrics and explanations please check [collect method](src/exporter.py#L42-L79) in exporter source-code.
6+
For available labels please see [metric_labels](src/exporter.py#L37-L40) list in exporter source-code.
7+
8+
# Disclaimer
9+
Please note that this tool is in early development stage, and as such should not be used to influence business crictical decisions.
10+
The project in it's current form suits our short-term needs and will receive limited support. We encourage you to fork the project, and extend it with additional functionality you might need.
11+
This project was inspired by [blackbox-websocket-exporter](https://github.com/smohsensh/blackbox-websocket-exporter)
12+
13+
## Development
14+
It is recommended that you install [pre-commit](https://pre-commit.com/) so that automated linting and formatting checks are performed before each commit. Run:
15+
```bash
16+
pip install pre-commit
17+
pre-commit install
18+
```
19+
### Running locally
20+
1. Make sure you have python3 installed (>3.9.10)
21+
1. Set-up your python environment
22+
```bash
23+
pip3 install virtualenv
24+
virtualenv venv
25+
source venv/bin/activate
26+
pip install -r requirements.txt
27+
```
28+
1. Generate valid exporter config and validation file. For example see [config example](config/exporter_example/config.yml) and [validation example](config/exporter_example/validation.yml).
29+
1. Export paths of generated configuration files relative to `src/exporter.py`:
30+
```bash
31+
export VALIDATION_FILE_PATH="validation.yml" # For example if we saved validation config file in src/validation.yml
32+
export CONFIG_FILE_PATH="config.yml" # For example if we saved config file in src/config.yml
33+
```
34+
1. Finally you can run the exporter
35+
```bash
36+
python exporter.py
37+
```
38+
### Run with docker-compose
39+
1. Generate valid exporter config and validation file. For example see [config example](config/exporter_example/config.yml) and [validation example](config/exporter_example/validation.yml).
40+
1. Export paths of generated configuration files relative to `docker-compose.yml`:
41+
```bash
42+
export VALIDATION_FILE_PATH="src/validation.yml" # For example if we saved validation config file in src/validation.yml
43+
export CONFIG_FILE_PATH="src/config.yml" # For example if we saved config file in src/config.yml
44+
```
45+
1. Execute
46+
```bash
47+
docker-compose build
48+
docker-compose-up
49+
curl localhost:8000/metrics # Exporter
50+
curl localhost:3000 # Grafana
51+
curl localhost:9090 # Prometheus
52+
```

config/exporter_example/config.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
blockchain: "Example Chain" # Name of blockchain i.e "Ethereum"
2+
chain_id: 1 # Chain ID, can be found at https://chainlist.org/
3+
network_name: "Example" # Name of the blokckchain network i.e Rinkeby
4+
network_type: "Example" # Type of the blockchain network, only two values allowed (Mainnet|Testnet)
5+
connection_timeout_seconds : 5 # Amount in seconds before websocket client drops a connection that has not finished connection handshake and labels the RPC node as unhealhty.
6+
slo: # Metrics below 'slo' will only affect `ws_rpc_sla_compliant` metric. In case any of the threshold are breached, this metric will be set to 0 for that perticular RPC endpoint.
7+
max_pool_deviation_block_count: 10 # Threshold for max allowed deviation in block height, compared to the node with the highest block count in the pool.
8+
max_response_latency_miliseconds: 500 # Threshold for max allowed latency.
9+
validation: # Validation section makes sure that "endpoints" can only be added with specific providers / chain. This is done to make sure labels in metrics are consistent.
10+
providers:
11+
- Provider1
12+
- Provider2
13+
- Provider3
14+
blockchains:
15+
- "Example Chain"
16+
endpoints: # List of endpoints with their metadata.
17+
- url: wss://example-rpc-1.com/ws # RPC Endpoint (Must start with wss://)
18+
provider: Provider1 # Provider (Must be present in allowed providers list. Please check src/settings.py line 24) The purpose is to make sure we do not have same providers spelled differently
19+
- url: wss://example-rpc-2.com/ws
20+
provider: Provider2
21+
- url: wss://example-rpc-3.com/ws
22+
provider: Provider3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# To enforce uniform labels in your metrics, we need to limit what providers and blockchains users can specify in their exporter configuration.
2+
allowed_providers: # When adding endpoints, these are the only values you will be able to add as providers. Otherwise program will exit with error.
3+
- Provider1
4+
- Provider2
5+
- Provider3
6+
allowed_blockchains: # When setting Blockchain key in your config file, it will be validate against this list.`
7+
- Example Chain
8+
- Example Chain2
9+
- Example Chain3

0 commit comments

Comments
 (0)