diy solar

diy solar

Grafana Configuration

  • Views Views: 919
  • Last updated Last updated:
  • Introduction​

    Now that we have Debian or a derivative running on either a real machine, a VM or a Raspberry Pi, we can configure the system to actually do something. This section will provide the configuration basics to start talking to devices such as inverters, charge controllers and BMS. We go into the data format expected for Grafana, but won't detail every single device - that will be available in a list with links to repositories of scripts to do this part.

    Grafana Configuration​

    Let's make sure everything is where it's supposed to be. We will be using the 'nano' editor to edit files. You only need two shortcuts:

    - ctrl+o enter to save the file
    - ctrl+x to exit the file

    Ramdisk​

    First of all, let's start with creating a ramdisk where the data will be stored temporarily before they are pushed to the Prometheus database. This directory sees lots of writes, so by making it a ramdisk we're not stressing the SSD (or SD Card). Edit the /etc/fstab file:

    sudo nano /etc/fstab

    And add this at the end of the file on its own line:

    tmpfs /ramdisk tmpfs nodev,nosuid,size=5M 0 0

    Save with ctrl-o enter, and then exit with ctrl-x. This will ultimately create a ramdisk, 5M in size, and will be mounted under /ramdisk. This directory does not exist yet, so let's create it:

    sudo mkdir /ramdisk

    We can now right away mount this ramdisk:

    sudo mount /ramdisk

    Plugins​

    Grafana has a bunch of possible plug-ins. Let's install some commonly used ones.

    sudo grafana-cli plugins install grafana-clock-panel
    sudo grafana-cli plugins install briangann-gauge-panel
    sudo grafana-cli plugins install dalvany-image-panel
    sudo grafana-cli plugins install innius-video-panel

    After installing these plug-ins, you can restart Grafana with:

    sudo systemctl restart grafana-server

    Retention time​

    By default, data retention time is set to 15 days. For our purposes we'd like to increase this to a year at least, maybe even more. To do this, we have to edit the /etc/default/prometheus file:

    sudo nano /etc/default/prometheus

    Make sure the line that states ARGS="" looks like this:

    ARGS="--storage.tsdb.retention.time=1y"

    Restart Prometheus with:

    sudo systemctl restart prometheus

    Node Exporter​

    We have to tell Node Exporter where to find the data it needs to put into Prometheus, namely /ramdisk. Edit the /etc/default/prometheus-node-exporter file:

    sudo nano /etc/default/prometheus-node-exporter

    Make sure the line that states ARGS="" looks like this:

    ARGS="--no-collector.mdadm --no-collector.pressure --no-collector.rapl --collector.textfile.directory=/ramdisk"

    Here, pressure and rapl collector get disabled because they generate a bunch of error messages on systems that don't have it enabled, like the Raspberry Pi. The textfile collector is the one we need to process our data.

    Restart Node Exporter with:

    sudo systemctl restart prometheus-node-exporter

    We can check Prometheus at:

    http://192.168.0.11:9090/

    Let's test if this all works. Create a file in /ramdisk called MUST_INV.prom. This is a sample data file for a MUST inverter, with a couple of datapoints:

    sudo nano /ramdisk/MUST_INV.prom

    Add these lines:

    MUST_INV{mode="batVolts"} 52.0
    MUST_INV{mode="batAmps"} 50.0
    MUST_INV{mode="loadPercent"} 25
    MUST_INV{mode="outputW"} 800
    MUST_INV{mode="outputVA"} 1200
    MUST_INV{mode="tempInt"} 60

    Save with ctrl+o enter again, and exit with ctrl+x. Now wait a few seconds (15 or so) and then go back to the Prometheus URL:

    http://192.168.0.11:9090/

    When you enter 'MUST_INV' in the query entry field and press execute, you should see something like this:

    prometheus.png
    This means Node Exporter is successfully running, and pushing data from the /ramdisk files to the Prometheus database.

    Grafana Dashboard​

    We can now add a first dashboard to Grafana itself. Since we have only the above MUST inverter as a sample, let's use that for now. We start by adding a new dashboard: got to the Grafana URL (http://192.168.0.11:3000/, remember to use your IP address), log in (user: admin, password: admin unless you changed it) and add a new data source in configuration:

    datasource_1.png

    Select a Prometheus data source (should be near the top) and create it. The default settings should all be fine, just enter http://localhost:9090 in the "URL" field (the default is just a placeholder):

    datasource_2.png
    Click "Save and Test" at the bottom, and it should respond with "Data source is working". Next, let's add a dashboard:

    dashboard_1.png

    Add a new panel to the dashboard:

    dashboard_2.png

    You should now see something like this:

    dashboard_3.png

    If you enter the following in the "Metrics Browser", you should be able to see your first graph:

    MUST_INV{mode="batVolts"}

    dashboard_4.png

    Congratulations, you're up and running! Of course, you don't have to build all these panels from scratch. You can find several demo's for example here, which you can directly import:

    https://github.com/PurpleAlien/jk-bms_grafana

    https://github.com/BarkinSpider/SolarShed/

    Serial Comms​

    Most devices communicate through some form of serial communication, be it TTL, RS232, RS485 with or without ModBus, etc. Individual scripts will be responsible to talk to the device itself and format the data, but we need to put the infrastructure in place to do so. The easiest way and most widely used method to do this for all those different devices is likely the Python programming language, so we have to make sure we have everything set to run those Python scripts.

    Run the following commands to get the core needed packages:

    sudo apt install -y python3-pip
    sudo pip3 install pyserial
    sudo pip3 install minimalmodbus

    That should get you all set to start communicating with your solar equipment, and graphing data! The links mentioned at the end of the previous section have some scripts available to read data if you want to give it a go. I will go into detail in the next entry.
  • Loading…
Back
Top