Skip to content

Commit

Permalink
Features/rpi image (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
pstrobl96 authored Dec 5, 2023
1 parent d45b277 commit 9502bfd
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml → .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: ci
name: docker

on:
push:
tags:
- v*.**.**

jobs:

audit:
runs-on: ubuntu-22.04
steps:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/rpi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: rpi

on:
push:
tags:
- v*.**

jobs:
image-creation:
runs-on: ubuntu-latest
steps:
- run: |
mkdir -p exporter-stage/00-install-packages &&
{
cat > exporter-stage/prerun.sh <<-EOF
#!/bin/bash -e
if [ ! -d "${ROOTFS_DIR}" ]; then
copy_previous
fi
EOF
} &&
chmod +x exporter-stage/prerun.sh &&
{
cat > exporter-stage/00-install-packages/00-packages <<-PCK
apt-utils
curl
apt-transport-https
ca-certificates
gnupg
PCK
} &&
{
cat > exporter-stage/00-install-packages/01-run.sh <<-RUN
#!/bin/bash -e
on_chroot << EOF
curl -fsSL https://get.docker.com -o get-docker.sh
sh ./get-docker.sh
systemctl enable docker
curl https://raw.githubusercontent.com/pstrobl96/prusa_exporter/main/docs/examples/config/grafana_cloud/prusa.yml -o /boot/firmware/prusa.yml
curl https://raw.githubusercontent.com/pstrobl96/prusa_exporter/main/docs/examples/config/grafana_cloud/agent.yaml -o /boot/firmware/agent.yaml
rm -rf /opt/prusa_exporter
mkdir /opt/prusa_exporter
curl https://raw.githubusercontent.com/pstrobl96/prusa_exporter/main/docker-compose.rpi-cloud.yaml -o /opt/prusa_exporter/docker-compose.yaml
curl https://raw.githubusercontent.com/pstrobl96/prusa_exporter/main/docs/services/prusa-exporter-docker.service -o /etc/systemd/system/prusa-exporter.service
systemctl enable prusa-exporter
EOF
RUN
} && chmod +x exporter-stage/00-install-packages/01-run.sh
- uses: usimd/pi-gen-action@v1
id: build
with:
hostname: prusa_pi
compression-level: 9
compression: xz
image-name: prusa_exporter-image
stage-list: stage0 stage1 stage2 ./exporter-stage

- uses: actions/upload-artifact@v3
with:
name: pi-gen-image
path: ${{ steps.build.outputs.image-path }}
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This list contains current and future features along with completion status:
- [x] Use of Grafana Cloud
- [x] CI pipeline with Docker Hub publish
- [x] Local instance of Grafana / Prometheus / Loki
- [ ] Raspberry Pi Image
- [x] Raspberry Pi Image
- [ ] Odroid C4 Image
- [ ] Implementation with [exporter-toolkit](#22)
- [ ] Support for [connection](#21) to Einsy with username and password
Expand All @@ -51,13 +51,71 @@ First things first. You need to clone the repo and that which is very easy, righ

I've created docker-compose.yaml file, that can be used for deploy of exporter. You would need [Docker](https://docs.docker.com/engine/install/) and [docker-compose](https://docs.docker.com/compose/install/linux/) plugin installed. Right now it is possible to use `docker compose up` only with Linux because I do not build image for Linux.

### Raspberry Pi

I also created Raspberry Pi image that can be flashed to memory card. If you choose this path you'll need following.

- Raspberry Pi (*4 and 5 tested*) with 64 bit support
- At least *Class 10* and at least *16 gigs* Memory card

Of course all other accessories like computer, card reader, power supply etc. are mandatory.

#### Downloading image

Download image from [releases page](https://github.com/pstrobl96/prusa_exporter/releases) or alternatively you can choose CI pipeline run and download particular artifact. After downloading the *zip* file extract the image to your favorite folder. You'll get image_{date_of_build}-prusa_exporter-image.img.xz file that you need to flash to your memory card.

#### Raspberry Pi Imager

[Download](https://www.raspberrypi.com/software/) and install Raspberry Pi Imager. You can alternatively use different tool but rpi-imager is easiest in terms of settings.

![rpiimager0](docs/readme/rpiimager0.png)

After installing open the Raspberry Pi Imager. **Don't** click `Choose Device` instead of that click on `Choose OS`. Scroll down, you'll find `Use Custom`. Select downloaded image.

![rpiimager1](docs/readme/rpiimager1.png)

![rpiimager2](docs/readme/rpiimager2.png)

Now connect memory card to your computer and click `Choose Storage`. **BEWARE** - you can mistakenly choose wrong storage media and flashing process includes formating your drive. Now select your Raspberry Pi memory card. Now click `Next`.

![rpiimager3](docs/readme/rpiimager3.png)

Now it depends if you want to connect via LAN or WiFi.

##### WiFi

If you want to use wireless ethernet, then click at `Edit Settings`. Click at `Configure wireless LAN` and write your WiFi name (SSID) and password. Don't forget to select correct Wireless LAN country. Next be sure that `Eject media when finished` is **unchecked** . Click `Save` and after that click on `Yes`. If you are sure that all content of your memory card would be erased, click `Yes`.

![rpiimager4](docs/readme/rpiimager4.png)

![rpiimager7](docs/readme/rpiimager7.png)

![rpiimager6](docs/readme/rpiimager6.png)

##### LAN

If you want to use wired ethernet, then click at `Edit Settings`, click `Options` and be sure that `Eject media when finished` is **unchecked** . Click `Save` and after that click on `Yes`. If you are sure that all content of your memory card would be erased, click `Yes`.

![rpiimager7](docs/readme/rpiimager7.png)

![rpiimager6](docs/readme/rpiimager6.png)

#### Flashing

Now wait for the Raspberry Pi Imager to complete the flash process.

#### Config

Now we need to configure *Grafana Agent* and *prusa_exporter*. After flashing you should see new partition connected to system, can be called `boot` or `bootfs`. In Windows you'll get also letter of partition, nowadays most probably `D:` - can varies. If you don't see new partition. Eject memory card from the system and reconnect it.

In boot partition you'll find two files `agent.yaml` and `prusa.yml`. Configuration is mentioned in next part of README.

#### Config

Please take a look at the [sample configuration examples](docs/examples/config) for prusa exporter, Prometheus, and Promtail. You will need to change few things to get it up and running. Of course you can change everything you want. If you are using Grafana Cloud, you can find your API key at [grafana.com](https://grafana.com/) -> My Account -> Grafana Cloud instance -> Send Metrics / Send Logs.

I also prepared a configuration for on-premise Prometheus and Loki if you do not want to use Cloud solution and you want to have your data somewhere local. You can find these [on-premise configs](docs/examples/config/on_premise) in the on_premise subfolder.


##### prusa.yml

Prusa exporter loads [prusa.yml](docs/examples/config/prusa.yml) from an environment variable called `$PRUSA_EXPORTER_CONFIG`. If you put this file in the same folder where prusa exporter is located then simply set it to `prusa.yml`. Prusa exporter has implemented a config reloader that runs by default every 300 seconds (5 minutes).
Expand Down Expand Up @@ -106,6 +164,21 @@ printers:
type: mini **optional**
```

##### agent.yml

Grafana Agent is used in Raspberry Pi image and currently works only with Grafana Cloud - if you don't configure it different way. You need to change `url`, `username` and `password`. You can get these values in configuration of your Grafana Cloud. How you can find in [Grafana Cloud documentation](https://grafana.com/docs/grafana-cloud/send-data/metrics/metrics-prometheus/).

```
metrics:
global:
scrape_interval: 15s
remote_write:
- url: <YOUR CLOUD METRICS URL>
basic_auth:
username: "<YOUR CLOUD METRICS USERNAME>"
password: "<YOUR CLOUD METRICS PASSWORD>"
```

##### prometheus.yml

In [prometheus.yml](docs/examples/config/prometheus.yml) you need to change the `remote_write` section. This section is responsible for writing data to Grafana Cloud instance. You can get all values in config of your Grafana instance. You can get more information in [Grafana Docs](https://grafana.com/docs/grafana-cloud/data-configuration/metrics/metrics-prometheus/).
Expand Down Expand Up @@ -143,6 +216,7 @@ Starting of exporter is simple. Just change directory to where docker-compose.ya

```
docker compose up
```

:tada: if everthing went alright your instance is up and running and you can find metrics at [/metrics](http://localhost:10009/metrics) endpoint.
Expand Down
38 changes: 38 additions & 0 deletions docker-compose.rpi-cloud.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3"

networks:
prusa:

services:
exporter:
image: pubeldev/prusa_exporter:latest
container_name: exporter
restart: unless-stopped
volumes:
- type: bind
source: /boot/firmware/prusa.yml
target: /app/prusa.yml
ports:
- "10009:10009"
networks:
- prusa
agent:
image: grafana/agent:latest
container_name: grafana_agent
restart: unless-stopped
volumes:
- type: bind
source: /boot/firmware/agent.yaml
target: /etc/agent-config/agent.yaml
entrypoint:
- /bin/grafana-agent
- -server.http.address=0.0.0.0:12345
- -config.file=/etc/agent-config/agent.yaml
- -metrics.wal-directory=/tmp/agent/wal
ports:
- "12345:12345"
networks:
- prusa
depends_on:
- exporter

17 changes: 17 additions & 0 deletions docs/examples/config/grafana_cloud/agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server:
log_level: info

metrics:
global:
scrape_interval: 15s
remote_write:
- url: <YOUR CLOUD METRICS URL>
basic_auth:
username: "<YOUR CLOUD METRICS USERNAME>"
password: "<YOUR CLOUD METRICS PASSWORD>"
configs:
- name: default
scrape_configs:
- job_name: "prusa"
static_configs:
- targets: ["exporter:10009"]
6 changes: 3 additions & 3 deletions docs/examples/config/grafana_cloud/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ scrape_configs:
- targets: ["node-exporter:9100"]

remote_write:
- url: https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push
- url: <YOUR CLOUD URL>
basic_auth:
username: "userName"
password: "apiKey"
username: "1273787"
password: "glc_eyJvIjoiOTgzNzQyIiwibiI6InN0YWNrLTc4Mjk0My1obS1yZWFkLXRlc3R0ZXN0IiwiayI6ImExOGJwczduUjFzVFIxdjN0MWRFMTQ5aCIsIm0iOnsiciI6InByb2QtZXUtd2VzdC0yIn19"
queue_config:
min_shards: 50
retry_on_http_429: true
Expand Down
14 changes: 3 additions & 11 deletions docs/examples/config/grafana_cloud/prusa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@ exporter:
log_level: info
printers:
buddy:
- address: <address_of_printer>
name: <your_printer_name>
type: mini
apikey: <your_printer_apikey>
- address: <address_of_printer>
username: maker # I'm not aware that there is posibility to change user name in XL or MK4 printers - default is maker
pass: <password>
name: <your_printer_name>
type: <mk4 or xl>
einsy:
- address: <address_of_printer>
apikey: <your_printer_apikey> # you need to generate api key in printer settings
name: <your_printer_name>
type: <mk2.5 or mk3>
legacy:
- address: <address_of_printer>
username: maker # I'm not aware that there is posibility to change user name in XL or MK4 printers - default is maker
pass: <password>
name: <your_printer_name>
type: mini
type: <mk4 or xl>
Binary file added docs/readme/rpiimager0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/readme/rpiimager7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/services/prusa-exporter-docker.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Prusa Exporter service
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker compose -f /opt/prusa_exporter/docker-compose.yaml up
ExecStop=/usr/bin/docker compose -f /opt/prusa_exporter/docker-compose.yaml down

[Install]
WantedBy=multi-user.target

0 comments on commit 9502bfd

Please sign in to comment.