Skip to content

Commit

Permalink
feat(logs): add alloy + loki
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNineteen committed Jan 2, 2025
1 parent e439c9d commit f2a4f09
Show file tree
Hide file tree
Showing 9 changed files with 567 additions and 651 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/kcov-output
/results
/validator
/logs

# desktop app config
.DS_Store
Expand Down
40 changes: 14 additions & 26 deletions metrics/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
original src: https://github.com/docker/awesome-compose/tree/master/prometheus-grafana

## Setup
## Setup

requirements:
- `docker compose`
requirements:
- `docker compose`
- [https://docs.docker.com/engine/install/ubuntu/](https://docs.docker.com/engine/install/ubuntu/)
- either mac or linux supported
- either mac or linux supported

modify `/etc/hosts` to include the following line:
modify `/etc/hosts` to include the following line:
```
127.0.0.1 prometheus
127.0.0.1 loki
```


## Running
## Running

mac: `docker compose -f compose_mac.yaml up -d`
linux: `docker compose -f compose_linux.yaml up -d`

- grafana will be accessable on `localhost:3000`
- note: `username: admin password: grafana`
- prometheus will be accessable on `localhost:9090`
- sig metrics will be published to localhost:12345 (if you change this on the sig cli, you will
- sig metrics will be published to localhost:12345 (if you change this on the sig cli, you will
need to also modify the prometheus `target` to point to the different port).

## Shutting down
Expand All @@ -37,31 +37,19 @@ Project structure:
.
├── compose_linux.yaml
├── compose_mac.yaml
├── alloy -- this scrapes logs/ and pushes to loki
├── loki -- log database
├── grafana
│   └── dashboards/ -- this is where the sig dashboard lives (will need to copy .json export of dashboard from running container and push through git for any dashboard changes)
│   └── datasources/ -- this points to prometheus docker
├── prometheus
│   └── prometheus.yml
│   └── prometheus.yml
└── README.md
```

[_compose.yaml_](compose.yaml)
```
services:
prometheus:
image: prom/prometheus
...
ports:
- 9090:9090
grafana:
image: grafana/grafana
...
ports:
- 3000:3000
```
The compose file defines a stack with two services `prometheus` and `grafana`.
When deploying the stack, docker compose maps port the default ports for each service to the equivalent ports on the host in order to inspect easier the web interface of each service.
Make sure the ports 9090 and 3000 on the host are not already in use.
## Run with logs

`./zig-out/bin/sig gossip -n testnet 2>&1 | tee -a logs/sig.log`

## Deploy with docker compose

Expand Down
16 changes: 16 additions & 0 deletions metrics/alloy/config.alloy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local.file_match "local_files" {
path_targets = [{"__path__" = "/var/log/alloy/*.log"}]
sync_period = "1s"
}

loki.source.file "log_scrape" {
targets = local.file_match.local_files.targets
forward_to = [loki.write.grafana_loki.receiver]
tail_from_end = true
}

loki.write "grafana_loki" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
}
30 changes: 30 additions & 0 deletions metrics/compose_linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,35 @@ services:
volumes:
- ./prometheus:/etc/prometheus
- prom_data:/prometheus

loki:
network_mode: "host" # -- only linux
image: grafana/loki:3.0.0
container_name: loki
ports:
- "3100:3100"
volumes:
- ./loki:/etc/loki
command:
- "--config.file=/etc/loki/loki.yml"

alloy:
network_mode: "host" # -- only linux
image: grafana/alloy:v1.3.1
ports:
- "3200:3200"
volumes:
- "./alloy/config.alloy:/etc/alloy/config.alloy"
- "../logs:/var/log/alloy"
command:
[
"run",
"--server.http.listen-addr=0.0.0.0:3200",
"/etc/alloy/config.alloy",
]
extra_hosts:
- "host.docker.internal:host-gateway"

grafana:
network_mode: "host" # -- only linux
image: grafana/grafana
Expand All @@ -25,6 +54,7 @@ services:
- ./grafana/datasources:/etc/grafana/provisioning/datasources
- ./grafana/dashboards:/etc/grafana/provisioning/dashboards
- ./grafana/dashboards:/var/lib/grafana/dashboards

node-exporter:
image: prom/node-exporter
container_name: node-exporter
Expand Down
32 changes: 29 additions & 3 deletions metrics/compose_mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@ services:
prometheus:
image: prom/prometheus
container_name: prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"
restart: unless-stopped
ports:
- 9090:9090
restart: unless-stopped
volumes:
- ./prometheus:/etc/prometheus
- prom_data:/prometheus
command:
- "--config.file=/etc/prometheus/prometheus.yml"

loki:
image: grafana/loki:3.0.0
container_name: loki
ports:
- "3100:3100"
volumes:
- ./loki:/etc/loki
command:
- "--config.file=/etc/loki/loki.yml"

alloy:
image: grafana/alloy:v1.3.1
ports:
- "3200:3200"
volumes:
- "./alloy/config.alloy:/etc/alloy/config.alloy"
- "../logs:/var/log/alloy"
command:
[
"run",
"--server.http.listen-addr=0.0.0.0:3200",
"/etc/alloy/config.alloy",
]

grafana:
image: grafana/grafana
container_name: grafana
Expand All @@ -23,6 +48,7 @@ services:
- ./grafana/datasources:/etc/grafana/provisioning/datasources
- ./grafana/dashboards:/etc/grafana/provisioning/dashboards
- ./grafana/dashboards:/var/lib/grafana/dashboards

node-exporter:
image: prom/node-exporter
container_name: node-exporter
Expand Down
Loading

0 comments on commit f2a4f09

Please sign in to comment.