Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto provision InfluxDB data source in Grafana #512

Merged
merged 9 commits into from
Sep 1, 2024
7 changes: 7 additions & 0 deletions grafana/sunandmoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1

datasources:
- name: Sun and Moon
type: grafana-sunandmoon-datasource
longzheng marked this conversation as resolved.
Show resolved Hide resolved
latitude: zzLAT
longitude: zzLONG
33 changes: 25 additions & 8 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ running() {
[[ $status == ${code} ]]
}

# Get latitude and longitude
LAT="0.0"
LONG="0.0"
PYTHON=$(command -v python3 || command -v python)
if [ -n "${PYTHON}" ]; then
LAT=$(curl -s https://freeipapi.com/api/json | "${PYTHON}" -c "import sys, json; print(json.load(sys.stdin)['latitude'])")
LONG=$(curl -s https://freeipapi.com/api/json | "${PYTHON}" -c "import sys, json; print(json.load(sys.stdin)['longitude'])")
longzheng marked this conversation as resolved.
Show resolved Hide resolved
fi

# Docker Dependency Check
if ! docker info > /dev/null 2>&1; then
echo "ERROR: docker is not available or not running."
Expand Down Expand Up @@ -437,6 +446,13 @@ if [ -f weather.sh ]; then
./weather.sh setup
fi

# Set up Sun and Moon data provider
if [ -f grafana/sunandmoon.yml ]; then
sed -i.bak "s@zzLAT@${LAT}@g" grafana/sunandmoon.yml
sed -i.bak "s@zzLONG@${LONG}@g" grafana/sunandmoon.yml
cp grafana/sunandmoon.yml grafana/provisioning/datasources/sunandmoon.yml
fi

longzheng marked this conversation as resolved.
Show resolved Hide resolved
# Build Docker in current environment
./compose-dash.sh up -d
echo "-----------------------------------------"
Expand Down Expand Up @@ -521,21 +537,22 @@ cat << EOF

Open Grafana at http://localhost:9000/ ... use admin/admin for login.

Follow these instructions for *Grafana Setup*:
To complete *Grafana Setup*:

* From 'Configuration\Data Sources' add 'InfluxDB' database with:
- Name: 'InfluxDB'
* From 'Dashboard\Browse', select 'New/Import', browse to ${PWD}/dashboards
and upload ${DASHBOARD}.

NOTE: The datasources for InfluxDB and SunAndMoon are already configured.
If you need to modify them via Configuration\Data Sources:

* InfluxDB
- URL: 'http://influxdb:8086'
- Database: 'powerwall'
- Min time interval: '5s'
- Click "Save & test" button

* From 'Configuration\Data Sources' add 'Sun and Moon' database with:
- Name: 'Sun and Moon'
* Sun and Moon
- Enter your latitude and longitude (tool here: https://bit.ly/3wYNaI1 )
- Click "Save & test" button

* From 'Dashboard\Browse', select 'New/Import', browse to ${PWD}/dashboards
and upload ${DASHBOARD}.

jasonacox marked this conversation as resolved.
Show resolved Hide resolved
EOF
31 changes: 22 additions & 9 deletions weather.sh
longzheng marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ fi

# Docker Dependency Check - moved to compose-dash.sh, 14/10/22

# Get latitude and longitude
LAT="0.0"
LONG="0.0"
PYTHON=$(command -v python3 || command -v python)
if [ -n "${PYTHON}" ]; then
LAT=$(curl -s https://freeipapi.com/api/json | "${PYTHON}" -c "import sys, json; print(json.load(sys.stdin)['latitude'])")
LON=$(curl -s https://freeipapi.com/api/json | "${PYTHON}" -c "import sys, json; print(json.load(sys.stdin)['longitude'])")
fi

# Setup Weather?
echo "Weather Data Setup"
echo "-----------------------------------------"
Expand Down Expand Up @@ -98,17 +107,21 @@ if [ ! -f ${CONF_FILE} ]; then
fi
echo ""
echo "Enter your location coordinates to determine weather in your location."
echo " For help go to https://jasonacox.github.io/Powerwall-Dashboard/location.html"
# check to see if LAT and LONG are not 0.0
if [ "${LAT}" == "0.0" ] || [ "${LONG}" == "0.0" ]; then
echo " Your current location could not be automatically determined."
echo " For help go to https://jasonacox.github.io/Powerwall-Dashboard/location.html"
else
echo " Your current location appears to be Latitude: ${LAT}, Longitude: ${LONG}"
fi
echo ""
read -p 'Enter Latitude: ' LAT
if [ -z "${LAT}" ]; then
echo "ERROR: Valid coordinates are required. Exiting now."
exit 0
read -p 'Enter Latitude (default: '${LAT}'): ' USER_LAT
if [ -n "${USER_LAT}" ]; then
LAT="${USER_LAT}"
fi
read -p 'Enter Longitude: ' LON
if [ -z "${LON}" ]; then
echo "ERROR: Valid coordinates are required. Exiting now."
exit 0
read -p 'Enter Longitude (default '${LON}'): ' USER_LONG
if [ -n "${USER_LONG}" ]; then
LON="${USER_LONG}"
fi
while :
do
Expand Down