Skip to content

Instantly share code, notes, and snippets.

@svet-b
svet-b / grafana_pdf_via_snapshot.md
Last active March 7, 2026 22:02
PDF export of Grafana dashboard via snapshot

Get PDF export of Grafana dashboard

Note

As currently described, this approach does not work. The reason for that is that creating a snapshot via the API does not actually populate any data, as described in e.g. https://community.grafana.com/t/snapshot-using-http-api-does-nothing/. An alternative approach which does work described in https://gist.github.com/svet-b/1ad0656cd3ce0e1a633e16eb20f66425.

Prerequisites

Packages:

  • The jq JSON processing command line tool, which is available for most distributions (https://stedolan.github.io/jq/, sudo apt install jq)
  • NodeJS, and the puppeteer package (npm install puppeteer), which is used to run headless Chrome
@svet-b
svet-b / bigdashboard_output.pdf
Last active April 23, 2025 03:06
PDF export of Grafana dashboard using puppeteer
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@svet-b
svet-b / ext4_mac_docker.md
Created May 10, 2021 19:33
Mount and edit SD card image with ext4 partitions on Mac using Docker

Go to the directory with the image you want to work with. Run a Docker container with that directory mounted:

docker run -it --privileged -v /dev:/dev -v (pwd):/tmp --workdir /tmp ubuntu bash

(replace (pwd) with "$PWD" if using bash instead of fish)

See this thread for an explanation of why --privileged and -v /dev:/dev are required. The need for the latter can be avoided with this alrternative workaround.

In the container, assuming that $IMAGE_FILE is the name of your image file:

@svet-b
svet-b / snapd_on_moxa.md
Last active October 7, 2022 05:36
Running snapd and snaps on a Moxa UC-8100 board

The Moxa UC-8100 line of "industrial IoT gateways", such as the Moxa UC-8112-LX, can be a good solution for on-site data acquisition. To get the most out of them we want to enable them to run snaps, like https://snapcraft.io/ammp-edge. Unfortunately, as of writing, the latest v2.0 firmware provided with these devices does not support this, for two main reasons:

  1. The pre-installed OS is Debian 8, while snapd requires at least Debian 9.
  2. The stock kernel does not include SquashFS support, and does not have the required CONFIG_DEVPTS_MULTIPLE_INSTANCES option set.

The steps for rectifying these shortcomings are roughly as follows:

Compiling and installing a custom kernel

The following commands assume you're doing this on the Moxa device itself, though for more expedient results you'll want to cross-compile on something more powerful. Also note that in order to build the kernel you'll need a couple of GB of free space, which is more

@svet-b
svet-b / grafana_search_replace.md
Last active September 9, 2022 08:32
Search-and-replace on Grafana dashboards by manipulating database

It's possible to do search-and-replace on Grafana dashboard definitions by directly manipulating the SQLite database. The key steps after logging into the server are as follows:

cd /var/lib/grafana
# Make backup copy; preserve old backup copies
sudo cp --backup=numbered grafana.db grafana.db.bak

# Stop Grafana
sudo systemctl stop grafana-server
#!/bin/bash
# Version of pishrink (https://github.com/Drewsif/PiShrink) to work on Moxa UC-8100 series image
function cleanup() {
if losetup $loopback &>/dev/null; then
losetup -d "$loopback"
fi
}
@svet-b
svet-b / wireguard_userspace.sh
Last active July 30, 2020 09:04
Install WireGuard userspace on Linux
sudo apt update && sudo apt upgrade
sudo apt install golang
sudo apt-get install libmnl-dev libelf-dev build-essential pkg-config
git clone https://git.zx2c4.com/wireguard-go
cd wireguard-go/
git checkout 0.0.20181001 # Get the desired release tag from `git tag`
make
sudo make install
@svet-b
svet-b / _make_ammp_raspbian_img.md
Last active July 22, 2020 13:58
Making a Raspbian-based AMMP edge image to run on Raspberry Pi

Create Raspbian SD card with image from https://www.raspberrypi.org/downloads/raspbian/

Create file named ssh in boot partition, so that ssh is enabled on boot.

Log into Raspberry Pi (user pi, password raspberry).

Set strong password on pi user. (passwd) (optional) Copy SSH key

ssh-copy-id -i id_ed25519_ammpedge pi@[raspberry_IP]
sudo apt install npm
sudo npm install -g npm@latest
sudo npm install bower -g

git clone https://github.com/sabhiram/raspberry-wifi-conf.git
cd raspberry-wifi-conf
npm update
bower install
sudo npm run-script provision
@svet-b
svet-b / grafana_set_up.sh
Last active September 1, 2018 23:21
Setting up Grafana environment
#!/bin/bash
export CODEDIR="/opt/codebase"
export DEVGROUP="devs"
export GH_ORIG="github.com/grafana"
export GH_FORK="github.com/ammpio"
export REPONAME="grafana"
export GOROOT=/usr/local/go
export GOPATH=$CODEDIR