Using TrueCharts, install prometheus
and grafana
.
In Grafana, add prometheus source:
- Configuration -> Data Sources -> Add Data Source
- Name: Prometheus
- URL: http://prometheus-operated.ix-prometheus.svc.cluster.local:9090
- Save & Test
You should see node metrics in Grafana.
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.
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.
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.