Skip to content

Instantly share code, notes, and snippets.

brian@virtual1:~$ sudo dmesg | grep -3 pm-de1bd0da
[ 20.605599] drbd pm-4b8bd822/0 drbd1017: disk( Inconsistent -> UpToDate ) [resync-finished]
[ 20.605889] drbd pm-4b8bd822/0 drbd1017 virtual6: repl( SyncTarget -> Established ) [resync-finished]
[ 20.606178] drbd pm-4b8bd822/0 drbd1017 virtual5: resync-susp( connection dependency -> no ) [resync-finished]
[ 20.606721] drbd pm-de1bd0da: Starting worker thread (node-id 0)
[ 20.607009] drbd pm-4b8bd822/0 drbd1017 virtual6: helper command: /sbin/drbdadm after-resync-target
[ 20.607535] drbd pm-9711fa32: Preparing cluster-wide state change 443404339: 0->2 role( Secondary ) conn( Connected )
[ 20.609164] drbd pm-de1bd0da virtual5: Starting sender thread (peer-node-id 1)
[ 20.609344] drbd pm-4b8bd822/0 drbd1017 virtual6: helper command: /sbin/drbdadm after-resync-target exit code 0
[ 20.610543] drbd pm-de1bd0da virtual6: Starting sender thread (peer-node-id 2)
@candlerb
candlerb / gist:ce5d5dd7d904773bf53cea8ec9f6a4f9
Created October 12, 2026 06:38
kernel logs from drbd volume going out of sync
# resource pm-4b8bd822 is primary on virtual6, secondary on virtual1 and virtual5
#### virtual5 was rebooted ####
# Messages on virtual6 (primary)
brian@virtual6:~$ sudo dmesg | grep pm-4b8bd822
...
[202760.993742] drbd pm-4b8bd822: Preparing remote state change 2516108491: 1->2 conn( Disconnecting ) disk( Outdated )
[202760.998377] drbd pm-4b8bd822 virtual5: Committing remote state change 2516108491 (primary_nodes=4)
[202760.998624] drbd pm-4b8bd822 virtual5: conn( Connected -> TearDown ) peer( Secondary -> Unknown ) [remote]
@candlerb
candlerb / pmacct_prometheus.md
Last active November 7, 2025 10:34
Hooking up pmacct / nfacctd to prometheus

Hooking up pmacct to prometheus

This is a quick hack to get prometheus to read pmacct flow data. Rather than writing a proper exporter, I used exporter_exporter to spawn a python script for each scrape.

NOTE: each pmacct aggregate will end up as a distinct timeseries, so you need to make sure you don't have a cardinality explosion.

@candlerb
candlerb / melcloud_exporter.py
Last active June 30, 2025 13:29
Wrapper around pymelcloud to generate prometheus metrics from Mitsubishi Ecodan ATW heat pump
#!/usr/bin/python3
"""
Copyright 2025 Brian Candler
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@candlerb
candlerb / go-project-layout.md
Last active December 27, 2025 05:36
Suggestions for go project layout

If someone asked me the question "what layout should I use for my Go code repository?", I'd start by asking back "what are you building: an executable, or a library?"

Single executable

Stage 1: single source file

Create a directory named however you want your final executable to be called (e.g. "mycommand"), change into that directory, and create the following files:

@candlerb
candlerb / vault.py
Last active February 23, 2022 10:17
python-social-auth plugin for Hashicorp Vault OIDC Provider. See also https://github.com/python-social-auth/social-core/pull/668
"""
Backend for Hashicorp Vault OIDC Identity Provider in Vault 1.9+
https://www.vaultproject.io/docs/secrets/identity/oidc-provider
"""
import base64
from social_core.backends.open_id_connect import OpenIdConnectAuth
from social_core.utils import cache
@candlerb
candlerb / redirector.go
Created February 10, 2022 17:02
Tiny standalone daemon to accept HTTP requests on port 80 and redirect client to HTTPS
package main
import (
"fmt"
"net/http"
"os"
"strings"
)
func redirect(w http.ResponseWriter, req *http.Request) {
@candlerb
candlerb / gist:572ec8c87055942a77e329942b8724f6
Created September 21, 2021 09:38
Backtrace for vector issue with loki
Sep 21 09:35:24 loki systemd[1]: Starting Vector...
Sep 21 09:35:24 loki vector[24928]: √ Loaded ["/etc/vector/vector.toml"]
Sep 21 09:35:24 loki vector[24928]: √ Component configuration
Sep 21 09:35:24 loki vector[24928]: √ Health check "loki"
Sep 21 09:35:24 loki vector[24928]: ------------------------------------
Sep 21 09:35:24 loki vector[24928]: Validated
Sep 21 09:35:24 loki systemd[1]: Started Vector.
Sep 21 09:35:24 loki vector[24932]: Sep 21 09:35:24.385 INFO vector::app: Log level is enabled. level="vector=trace,codec=trace,vrl=trace,file_source=trace,tower_limit=trace,rdkafka=trace" enable_datadog_tracing=false
Sep 21 09:35:24 loki vector[24932]: Sep 21 09:35:24.386 INFO vector::app: Loading configs. paths=["/etc/vector/vector.toml"]
Sep 21 09:35:24 loki vector[24932]: Sep 21 09:35:24.417 DEBUG vector::tls::settings: Fetching system root certs.
@candlerb
candlerb / gf-run.py
Created July 12, 2021 17:28
Simplified gf-run.py
#!/usr/bin/python3
import os
import shutil
import subprocess
import sys
index = int(sys.argv[1])
num_disks = int(sys.argv[2])
base = os.path.abspath("mybase.img")
@candlerb
candlerb / err.txt
Created July 12, 2021 16:33
Debug output from guestfs when not starting correctly
libguestfs: create: flags = 0, handle = 0x55be3d261850, program = guestfish
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=/home/nsrc/nsrc-gns3/scripts/mybase.img,compat=1.1
libguestfs: command: run: \ /tmp/gf-run.20461/node0.qcow2
Formatting '/tmp/gf-run.20461/node0.qcow2', fmt=qcow2 size=1474560 compat=1.1 backing_file=/home/nsrc/nsrc-gns3/scripts/mybase.img cluster_size=65536 lazy_refcounts=off refcount_bits=16
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2