Skip to content

Instantly share code, notes, and snippets.

@indrekj
Created January 1, 2023 13:47
Show Gist options
  • Save indrekj/00715e8dac33ebe1023f6b36771fa765 to your computer and use it in GitHub Desktop.
Save indrekj/00715e8dac33ebe1023f6b36771fa765 to your computer and use it in GitHub Desktop.

TrueNAS Scale - Custom Prometheus metrics (for Bitcoin Node)

Install basics

Using TrueCharts, install prometheus and grafana.

In Grafana, add prometheus source:

You should see node metrics in Grafana.

Exporter

Let's say you have some application running and you want to add a prometheus exporter. I wanted to add bitcoin-prometheus-exporter. In TrueNAS I used Apps -> Launch Docker Image and configured it as needed.

Connecting the dots

Now we have prometheus running and we have the exporter running, but the prometheus does not know about the exporter. For that we need to create a ServiceMonitor manifest. For the bitcoin node I created bitcoin-service-monitor.yaml:

apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app.kubernetes.io/instance: bitcoin-prometheus-exporter
    app.kubernetes.io/name: ix-chart
  name: bitcoin-prometheus-exporter
  namespace: ix-bitcoin-prometheus-exporter
spec:
  endpoints:
    - path: /
      port: ix-bitcoin-prometheus-exporter-9332-0
  namespaceSelector:
    matchNames:
      - ix-bitcoin-prometheus-exporter
  selector:
    matchLabels:
      app.kubernetes.io/instance: bitcoin-prometheus-exporter
      app.kubernetes.io/name: ix-chart

The important parts are in the spec:. The port has to match the port which exposes the metrics. The matchNames defines the Kubernetes namespace where the application is running and finally matchLabels is used to find correct Kuberentes Service.

Apply this using kubectl --context=homelab -n ix-bitcoin-prometheus-exporter apply -f bitcoin-service-monitor.yaml.

NOTE: To use kubectl like I do, please read How to acccess TrueNAS kubectl remotely from your local computer? first.

Final thoughts

I know this is not a step by step guide. I'm assuming you can already install applications and do basic configuration. This is more the help to connect the dots and for myself if I have to do it again in a year or two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment