Skip to content

Commit df72fc1

Browse files
authored
Merge pull request #25 from wileyj/chore/prometheus
Chore/prometheus
2 parents f84c24a + b397988 commit df72fc1

File tree

5 files changed

+110
-9
lines changed

5 files changed

+110
-9
lines changed

.dclintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
rules:
44
services-alphabetical-order: 0
55
service-image-require-explicit-tag: 0
6+
require-quotes-in-ports: 0
67
quiet: false
78
debug: true

.github/workflows/linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1212
- uses: docker-compose-linter/dclint-github-action@18659f6a7956706cb67cf9c1ad5e55f4352cbc17 # 1.6.0
1313
with:
14-
path: ./docker/docker-compose.yml
14+
path: ./docker/
1515
recursive: true

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ genesis: check-not-running | build $(CHAINSTATE_DIR) /usr/bin/sudo
105105
# Secondary name to boot the genesis network
106106
up-genesis: genesis
107107

108+
up-prom:
109+
@echo "Starting $(PROJECT) prometheus monitoring"
110+
docker compose -f docker/docker-compose.prom.yml --profile default -p monitoring up -d
111+
112+
down-prom:
113+
@echo "Shutting down $(PROJECT) prometheus monitoring"
114+
docker compose -f docker/docker-compose.prom.yml --profile default -p monitoring down
115+
108116
# Shut down the network (chainstate and logs will be preserved)
109117
down: backup-logs current-chainstate-dir
110118
@echo "Shutting down $(PROJECT) network"

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ make log stacks-signer-1 -- -f
5858
make log stacks-signer-1
5959
```
6060

61+
### Container management
6162
#### Pause/Unpause service
6263
To pause all services on the network
6364
```sh
@@ -88,6 +89,19 @@ Restart the stopped service
8889
make start <service name>
8990
```
9091

92+
#### Force stop the hacknet network
93+
If the network is in a "stuck" state where the Makefile targets are not stopping the services (i.e. the `.current-chainstate-dir` file was removed while network was running), `down-force` may be used to force stop the network.
94+
95+
```sh
96+
make down-force
97+
```
98+
99+
Additionally, `clean` target will call `down-force` *and also* delete any chainstates on disk in `./docker/chainstate/*`
100+
```sh
101+
make clean
102+
```
103+
104+
### Additional Features
91105
#### Stress the CPU
92106
To simulate CPU load. Can be modified with:
93107
- `STRESS_CORES` to target how many worker threads (default will use all cores)
@@ -99,6 +113,12 @@ make stress
99113
STRESS_CORES=10 STRESS_TIMEOUT=60 make stress
100114
```
101115

116+
#### Monitor chain heights
117+
Run a script outputting the current chain heights of each miner
118+
```sh
119+
make monitor
120+
```
121+
102122
#### Create a chainstate snapshot
103123
- Setting the env var `PAUSE_HEIGHT` is optional to pause the chain at a specific height, else a default of Bitcoin block `999999999999` is used.
104124
- Setting the env var `MINE_INTERVAL_EPOCH3` is recommended to reach the `PAUSE_HEIGHT` more quickly to create the snapshot
@@ -129,19 +149,17 @@ ex:
129149
CHAINSTATE_ARCHIVE=./docker/chainstate_new.tar.zstd make up
130150
```
131151

132-
#### Force stop the hacknet network
133-
If the network is in a "stuck" state where the Makefile targets are not stopping the services (i.e. the `.current-chainstate-dir` file was removed while network was running), `down-force` may be used to force stop the network.
134-
152+
#### Prometheus sidecar
153+
##### Run prometheus and cadvisor
154+
Runs a prometheus container to record data collected by `cadvisor` for tracking host/container metrics
135155
```sh
136-
make down-force
156+
make up-prom
137157
```
138-
139-
Additionally, `clean` target will call `down-force` *and also* delete any chainstates on disk in `./docker/chainstate/*`
158+
##### Stop prometheus and cadvisor
140159
```sh
141-
make clean
160+
make down-prom
142161
```
143162

144-
145163
## Containers
146164

147165
- **bitcoin**: Runs a bitcoin regtest node

docker/docker-compose.prom.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
x-common-vars:
2+
- &DOCKER_NETWORK ${DOCKER_NETWORK:-stacks}
3+
- &DOCKER_NETWORK_CIDR 10.0.0.0/24
4+
- &DOCKER_NETWORK_GATEWAY 10.0.0.1
5+
- &PROMETHEUS_IP 10.0.0.252
6+
- &CADVISOR_IP 10.0.0.253
7+
8+
name: monitoring
9+
services:
10+
prometheus:
11+
image: prom/prometheus:latest
12+
container_name: prometheus
13+
depends_on:
14+
- cadvisor
15+
configs:
16+
- source: prometheus.yml
17+
target: /etc/prometheus/prometheus.yml
18+
ports:
19+
- "0.0.0.0:9090:9090"
20+
networks:
21+
default:
22+
ipv4_address: *PROMETHEUS_IP
23+
command:
24+
- --config.file=/etc/prometheus/prometheus.yml
25+
cadvisor:
26+
image: gcr.io/cadvisor/cadvisor:latest
27+
container_name: cadvisor
28+
volumes:
29+
- /:/rootfs:ro
30+
- /var/run:/var/run:rw
31+
- /sys:/sys:ro
32+
- /var/lib/docker/:/var/lib/docker:ro
33+
ports:
34+
- "0.0.0.0:8080:8080"
35+
networks:
36+
default:
37+
ipv4_address: *CADVISOR_IP
38+
command: "--enable_metrics=cpu,cpuLoad,disk,diskIO,memory"
39+
40+
networks:
41+
default:
42+
name: *DOCKER_NETWORK
43+
ipam:
44+
driver: default
45+
config:
46+
- subnet: *DOCKER_NETWORK_CIDR
47+
gateway: *DOCKER_NETWORK_GATEWAY
48+
49+
configs:
50+
# prometheus scraping config
51+
prometheus.yml:
52+
content: |
53+
# Global config
54+
global:
55+
external_labels:
56+
monitor: "hacknet"
57+
# A scrape configuration containing Prometheus and Docker
58+
scrape_configs:
59+
- job_name: cadvisor
60+
scrape_interval: 5s
61+
static_configs:
62+
- targets:
63+
- cadvisor:8080
64+
metric_relabel_configs:
65+
- source_labels: [ __name__ ]
66+
regex: '^(go_|cadvisor_version_info).+'
67+
action: drop
68+
- job_name: stacks
69+
scrape_interval: 5s
70+
static_configs:
71+
- targets:
72+
- stacks-miner-1:9153
73+
- stacks-miner-2:9153
74+
- stacks-miner-3:9153

0 commit comments

Comments
 (0)