This guide won’t go into detail on how every setting in Grafana works, mainly because I don’t really know 🙂 This will mostly be about adding UPS stats to Grafana and calculating the cost of running your server 24/7.


There is an updated 2019 blog post on this subject!
Read more here:


Install the container and follow the instructions.


Note: A database called telegraf is created when you start the telegraf container for the first time. I will be using that for this guide.

I recommend not using the telegraf database and creating a new database purely for UPS data. Read more here

Create a new database with
docker exec -it Influxdb bash
influx -execute 'CREATE DATABASE <name>'

You can check existing databases with docker exec.
influx -execute 'SHOW DATABASES'

name: databases


User Scripts

To be able to have Grafana read the UPS metrics we need to send them to the UPS database in InfluxDB.
I’m doing that using this awesome script by Viaduct on the Unraid forums.


$command = "apcaccess";
$args = "status";
$tagsArray = array(

//do system call

$call = $command." ".$args;
$output = shell_exec($call);

//parse output for tag and value

foreach ($tagsArray as $tag) {

preg_match("/".$tag."\s*:\s([\d|\.]+)/si", $output, $match);

//send measurement, tag and value to influx

sendDB($match[1], $tag);

//end system call

//send to influxdb

function sendDB($val, $tagname) {

$curl = "curl -i -XPOST 'http://influxDBIP:8086/write?db=UPS' --data-binary 'APC,host=Tower,region=us-west "
$execsr = exec($curl);



(If you need to use SNMP scroll down to the bottom!)
By using the User Scripts plugin you can easily set up a cronjob every minute.
Click on Add New Script → Enter the name → Click on the name of the script and then Edit Script

Copy the script and add your ip address to InfluxDB, which database to write to, name of the data table, host name and region.

$curl = "curl -i -XPOST '' --data-binary 'APC,host=Nostromo,region=eu-west-3 " is the IP to InfluxDB
db=UPS: is the name of the database in InfluxDB.
APC: is the name of the data table
host: is the name of your host. In my case Nostromo.
region: is the region you live in.
Click Save Changes when you’re done.


Set the schedule to custom and add * * * * * for it to run every minute.

Click Run In Background and then Apply

The downside of using crontab is that it’s limited to only run every 1 minute. If you know of a smarter solution that will run the script more often please tell me in the comments!


Go to “Configuration” and click + Add data source.
Set it to type InfluxDB
Add your URL to InfluxDB
And add the database UPS
Click Save & Test

Create a new dashboard and add your panels.

Here is a link to the Dashboard ID so you can import the whole thing: 

And here is a link to my Unraid System Dashboard 

Final Notes

The reason yearly and or monthly/weekly (depending on when you read this) costs are the same is it hasn’t been a week/month/year yet after I set this up. These numbers will grow and stop depending on the time frame of the stats.

To be able to get the Last Month Power Consumptions/Cost panel to display correctly I have set the dashboard to previous month. And added a custom time range to the other panels.


Note 28.07.18: I’ve added some variables, so now you only need to select the kWh price and Max watt output on your UPS.  You will still need to edit the currency on the panels and probably edit the values on the kWh Price variable.

Note 27.12.18:
I’ve added a variable that lets you choose the datasource of your UPS data. Making it even easier to set up. No need to change the panels!

For it to show correct Wattage for your UPS you need to edit the math part.
For example on the Current UPS Load panel.

SELECT mean("LOADPCT") / 100*865 FROM "APC" WHERE $timeFilter GROUP BY time($__interval) fill(none)

The number 865 is my UPS max capacity of watt output.  So to calculate the watt load you take the load percentage and divide it with 100(%) and multiply it with the max output (865W)

If you want to show kWh load you divide that by 1000
And remember to change the currency!

If you have any comments on how I can do this smarter/better please do share!

– Thank you Samuel Hoyt, for letting me know my math was wrong! 🙂

If you have to use SNMP you can use this python script. Thanks ardaingeal!


from easysnmp import snmp_get, Session
from influxdb import InfluxDBClient

#Query UPS Load
snmpqueryload = snmp_get('.', hostname='IP/hostname', security_username='SNMP user', version=3)
resultload = str(snmpqueryload)
lpct =  (int(resultload[21:23]))

#Query Runtime remaining
snmpqueryruntime = snmp_get('.', hostname='hostname='IP/hostname', security_username='SNMP user', version=3)
resultruntime = str(snmpqueryruntime)
runtime = (int(resultruntime[21:27]))

#Query Battery Capacity
snmpquerycharge = snmp_get('.', hostname='hostname='IP/hostname', security_username='SNMP user', version=3)
resultcharge = str(snmpquerycharge)
capacity =  (int(resultcharge[21:24]))

#Insert into InfluxDB
client = InfluxDBClient(host='', port='8086', username='influxdbusername', password='influxdbpassword')
json_body = [
        "measurement": "APC",
        "tags": {
                "Model": "Smart-UPS2200",
                "Location": "Home"
        "fields": {
                "LOADPCT": lpct,
                "BCHARGE": capacity,
                "TIMELEFT": runtime

For any questions you can find me here: