Skip to content

Instantly share code, notes, and snippets.

@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_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
@svet-b
svet-b / compile_plugin.sh
Created June 13, 2018 14:07
Compile Grafana plugin (e.g. status panel) on MacOS
#!/bin/bash
# Update npm to latest
npm i npm@latest -g
# Make sure Sass is installed (requires Ruby)
gem install sass
$SRCDIR="/opt/codebase/Grafana_Status_panel"
@svet-b
svet-b / make_ammp_moxa_image.md
Last active July 16, 2018 06:25
Making an AMMP edge image for Moxa

This works on the v3 firmware of the Moxa UC-8100(-LX)

Log into Moxa Edit /etc/network/interfaces to enable DHCP on LAN1

iface eth0 inet dhcp
#iface eth0 inet static
#        address 192.168.3.127
#        network 192.168.3.0
# netmask 255.255.255.0
#!/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 / edge_without_snapd.sh
Created July 30, 2018 21:56
Set up AMMP-edge without snapd
# Ensure that package dependencies are met (specifically python3, libsnmp-dev, and python3-netifaces)
# Create user under which software will be run.
# Enter user directory. In this example this is /opt/datalog
# Pull the codebade
git clone https://github.com/ammpio/ammp-edge.git
# Install python package
cd ammp-edge
@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]
@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
@svet-b
svet-b / grafana_pdf_via_snapshot.md
Last active December 27, 2022 09:01
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 June 13, 2024 08:43
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.