Skip to content

Commit

Permalink
Local telegraf grafana user env. upgrade untested.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuongiornoTexas committed Oct 15, 2022
1 parent bcd5557 commit 4e799f8
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 38 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A non-animated version of the dashboard is also available using [dashboard-no-an
The host system will require:

* docker
* docker-compose
* docker-compose (works with docker compose (v2) as well)
* You should not need to run `sudo` to install this tool. See [Docker Errors](https://github.com/jasonacox/Powerwall-Dashboard#docker-errors) below for help.
* TCP ports: 8086 (InfluxDB), 8675 (pyPowerwall), and 9000 (Grafana)

Expand Down Expand Up @@ -52,6 +52,8 @@ Follow the **[Grafana Setup](https://github.com/jasonacox/Powerwall-Dashboard#gr

If you prefer, you can perform the same steps that `setup.sh` performs.

A Manual install is mandatory if you are running a non-standard docker installation (e.g. rootless), or if you want to monitor custom measurements.

You will want to set your local timezone by editing `pypowerwall.env`, `telegraf.conf`, `influxdb.sql` and `dashboard.json` or you can use this handy `tz.sh` update script. A list of timezones is available [here](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).

```bash
Expand All @@ -71,6 +73,10 @@ You will want to set your local timezone by editing `pypowerwall.env`, `telegraf
PW_DEBUG=no
```

* Copy `compose.env.sample` to `compose.env` - you do not need to edit these defaults unless you are running a non-standard install such as docker rootless.

* Copy `telegraf.local.sample` to `telegraf.local`. If you want to monitor custom measurements for your site (most users don't need this), add the required telegraf.conf TOML entries to this file. Once created, this file is not overwritten by upgrades or future runs of setup.sh.

* Copy `grafana.env.sample` to `grafana.env` - you do not need to edit these defaults. However, there are optional settings for alert notifications and HTTPS.

* Optional: If you want to pull in local weather data, copy `weather/weather411.conf.sample` to `weather/weather411.conf` and edit the file to include your location ([Latitude and Longitude](https://jasonacox.github.io/Powerwall-Dashboard/location.html)) and your OpenWeatherMap API Key. To get a Key, you need to set up a free account at [openweathermap.org](https://home.openweathermap.org/users/sign_up). Make sure you check your email to verify account. API keys can take a few hours to activate.
Expand All @@ -84,10 +90,10 @@ You will want to set your local timezone by editing `pypowerwall.env`, `telegraf
LON = yyy.yyyy
```

* Start the docker containers
* Start the docker containers with the utility docker-compose script

```bash
docker-compose -f powerwall.yml up -d
compose-dash.sh up -d
```

### InfluxDB
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.4
2.6.5
6 changes: 3 additions & 3 deletions backups/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ echo "Done"
Naturally, whatever backup plan you decide to do, make sure you test it. Copy the backup to another VM or box, install Powerwall-Dashboard and restore the backup to see if it all comes back up without any data loss.

1. Install a fresh instance of Powerwall-Dashboard per [Setup instructions](https://github.com/jasonacox/Powerwall-Dashboard#setup).
2. Stop containers
2. Stop containers using convenience script in Powerwall-Dashboard root folder
```bash
docker-compose -f powerwall.yml stop
compose-dash.sh stop
```
3. Restore backup files
```bash
Expand All @@ -61,5 +61,5 @@ Naturally, whatever backup plan you decide to do, make sure you test it. Copy th
```
4. Start containers
```bash
docker-compose -f powerwall.yml start
compose-dash.sh start
```
36 changes: 36 additions & 0 deletions compose-dash.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
#
# Convenience script for docker-compose
# Enables
# - docker-compose and docker compose (v1, v2)
# - moves multiple versions of unweildy compose invocation to one place
# - very convenient for starting and stopping containers when developing.
# Takes up to two arguments, typicallly "up -d", "start", and "stop"
# Always verifies docker and docker-compose, as it is run infrequently.
# by Jason Cox - 21 Jan 2022

# Stop on Errors
set -e

# Docker Dependency Check
if ! docker info > /dev/null 2>&1; then
echo "ERROR: docker is not available or not runnning."
echo "This script requires docker, please install and try again."
exit 1
fi

echo "Running Docker Compose..."
if docker-compose version > /dev/null 2>&1; then
# Build Docker (v1)
docker-compose --env-file ./compose.env -f powerwall.yml $1 $2
else
if docker compose version > /dev/null 2>&1; then
# Build Docker (v2)
docker compose --env-file ./compose.env -f powerwall.yml $1 $2
else
echo "ERROR: docker-compose/docker compose is not available or not runnning."
echo "This script requires docker-compose or docker compose."
echo "Please install and try again."
exit 1
fi
fi
6 changes: 6 additions & 0 deletions compose.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Environment variables for docker compose.
#
# GRAFANAUSER - may need to be adjusted for cases such as rootless docker.
# See issue #22,
# https://github.com/jasonacox/Powerwall-Dashboard/issues/22#issuecomment-1253076441)
GRAFANAUSER="1000:1000"
13 changes: 12 additions & 1 deletion powerwall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,22 @@ services:
hostname: telegraf
restart: always
user: "1000:1000"
command: [
"telegraf",
"--config",
"/etc/telegraf/telegraf.conf",
"--config-directory",
"/etc/telegraf/telegraf.d"
]
volumes:
- type: bind
source: ./telegraf.conf
target: /etc/telegraf/telegraf.conf
read_only: true
- type: bind
source: ./telegraf.local
target: /etc/telegraf/telegraf.d/local.conf
read_only: true
depends_on:
- influxdb
- pypowerwall
Expand All @@ -52,7 +63,7 @@ services:
container_name: grafana
hostname: grafana
restart: always
user: "1000:1000"
user: "${GRAFANAUSER}"
volumes:
- type: bind
source: ./grafana
Expand Down
29 changes: 15 additions & 14 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@ running() {
[[ $status == ${code} ]]
}

# Docker Dependency Check
if ! docker info > /dev/null 2>&1; then
echo "ERROR: docker is not available or not runnning."
echo "This script requires docker, please install and try again."
exit 1
fi
if ! docker-compose version > /dev/null 2>&1; then
echo "ERROR: docker-compose is not available or not runnning."
echo "This script requires docker-compose, please install and try again."
exit 1
fi
# Docker Dependency Check - moved to compose-dash.sh 14/10/2022

# Check for RPi Issue with Buster
if [[ -f "/etc/os-release" ]]; then
Expand All @@ -69,6 +59,8 @@ if [[ -f "/etc/os-release" ]]; then
fi

PW_ENV_FILE="pypowerwall.env"
COMPOSE_ENV_FILE="compose.env"
TELEGRAF_LOCAL="telegraf.local"
GF_ENV_FILE="grafana.env"
CURRENT=`cat tz`

Expand Down Expand Up @@ -108,6 +100,16 @@ if [ ! -f ${GF_ENV_FILE} ]; then
cp "${GF_ENV_FILE}.sample" "${GF_ENV_FILE}"
fi

# Create default docker compose env file if needed.
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
cp "${COMPOSE_ENV_FILE}.sample" "${COMPOSE_ENV_FILE}"
fi

# Create default telegraf local file if needed.
if [ ! -f ${TELEGRAF_LOCAL} ]; then
cp "${TELEGRAF_LOCAL}.sample" "${TELEGRAF_LOCAL}"
fi

echo ""
if [ -z "${TZ}" ]; then
echo "Using ${CURRENT} timezone...";
Expand All @@ -124,9 +126,8 @@ if [ -f weather.sh ]; then
./weather.sh setup
fi

# Build Docker
echo "Running Docker-Compose..."
docker-compose -f powerwall.yml up -d
# Build Docker in current environment
. compose-dash.sh up -d
echo "-----------------------------------------"

# Set up Influx
Expand Down
21 changes: 21 additions & 0 deletions telegraf.local.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Sample file for local telegraf configurations.
# Most users will not need to use this, but it can be used for development
# or monitoring non standard measurement data.
#
# The local configuration file should be named "telegraf.local".
# Upgrade.sh does not modify this file.
#
# The following sample adds some power and energy data from the solar meter
# as a measurement called "solarmeter" (used in a three phase monitoring example)

#[[inputs.http]]
# urls = [
# "http://pypowerwall:8675/api/meters/solar"
# ]
# name_override = "solarmeter"
# method = "GET"
# insecure_skip_verify = true
# timeout = "4s"
# data_format = "json"
# json_query = "0.Cached_readings"
# fieldpass = ["instant_power", "real_power_?", "energy_??ported"]
18 changes: 15 additions & 3 deletions upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
set -e

# Set Globals
VERSION="2.6.4"
VERSION="2.6.5"
CURRENT="Unknown"
COMPOSE_ENV_FILE="compose.env"
TELEGRAF_LOCAL="telegraf.local"
if [ -f VERSION ]; then
CURRENT=`cat VERSION`
fi
Expand Down Expand Up @@ -108,6 +110,16 @@ if ! grep -q "yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip" grafana.env; then
fi
fi

# Silently create default docker compose env file if needed.
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
cp "${COMPOSE_ENV_FILE}.sample" "${COMPOSE_ENV_FILE}"
fi

# Create default telegraf local file if needed.
if [ ! -f ${TELEGRAF_LOCAL} ]; then
cp "${TELEGRAF_LOCAL}.sample" "${TELEGRAF_LOCAL}"
fi

# Check to see if Weather Data is Available
if [ ! -f weather/weather411.conf ]; then
echo "This version (${VERSION}) allows you to add local weather data."
Expand All @@ -124,7 +136,7 @@ fi
# Make sure stack is running
echo ""
echo "Start Powerwall-Dashboard stack..."
docker-compose -f powerwall.yml up -d
. compose-dash.sh up -d

# Set Timezone
echo ""
Expand Down Expand Up @@ -168,7 +180,7 @@ docker images | grep weather411 | awk '{print $3}' | xargs docker rmi -f
# Restart Stack
echo ""
echo "Restarting Powerwall-Dashboard stack..."
docker-compose -f powerwall.yml up -d
. compose-dash.sh up -d

# Display Final Instructions
cat << EOF
Expand Down
16 changes: 3 additions & 13 deletions weather.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ if [ "$EUID" -eq 0 ]; then
exit 1
fi

# Docker Dependency Check
if ! docker info > /dev/null 2>&1; then
echo "ERROR: docker is not available or not runnning."
echo "This script requires docker, please install and try again."
exit 1
fi
if ! docker-compose version > /dev/null 2>&1; then
echo "ERROR: docker-compose is not available or not runnning."
echo "This script requires docker-compose, please install and try again."
exit 1
fi
# Docker Dependency Check - moved to compose-dash.sh, 14/10/22

# Setup Weather?
echo "Weather Data Setup"
Expand Down Expand Up @@ -152,8 +142,8 @@ if [[ "${1}" == "setup" ]]; then
echo "Weather Configuration Complete"
echo ""
else
echo "Running Docker-Compose..."
docker-compose -f powerwall.yml up -d
# run docker compose in current shell.
. compose-dash.sh up -d
echo "Weather Setup Complete"
echo ""
fi

0 comments on commit 4e799f8

Please sign in to comment.