From 9f6c929e45e96e79db439b98f42d39465b383a4a Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Wed, 1 Jul 2020 15:23:08 -0500 Subject: [PATCH 01/16] Fisrt draft on grafana --- grafana.sh | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 grafana.sh diff --git a/grafana.sh b/grafana.sh new file mode 100644 index 0000000..b7bb485 --- /dev/null +++ b/grafana.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# Grafana Installer +# Based on: +# https://community.jitsi.org/t/how-to-to-setup-grafana-dashboards-to-monitor-jitsi-my-comprehensive-tutorial-for-the-beginner/ +# by Woodworker_Life +# Woodworker_Life © - 2020 +# SwITNet Ltd © - 2020, https://switnet.net/ +# GPLv3 or later. + +MAIN_TEL="/etc/telegraf/telegraf.conf" +TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf" +PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" + +# +apt update && apt install -y gnupg2 curl wget +wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - +echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list +apt update && apt install influxdb -y +systemctl enable --now influxdb +systemctl status influxdb + +# +curl -s https://packages.grafana.com/gpg.key | sudo apt-key add - +add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" +apt update && apt install grafana -y +systemctl enable --now grafana-server +systemctl status grafana-server + +# +wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - +echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list +apt update && apt install telegraf -y +mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.original + +cat << TELEGRAF > $MAIN_TEL +[global_tags] + +############################################################################### +# GLOBAL # +############################################################################### + +[agent] + interval = "10s" + debug = false + hostname = "localhost" + round_interval = true + flush_interval = "10s" + flush_jitter = "0s" + collection_jitter = "0s" + metric_batch_size = 1000 + metric_buffer_limit = 10000 + quiet = false + logfile = "" + omit_hostname = false + +TELEGRAF + +cat << JITSI_TELEGRAF > $TEL_JIT +############################################################################### +# INPUTS # +############################################################################### + +[[inputs.http]] + name_override = "jitsi_stats" + urls = [ + "http://localhost:8080/colibri/stats" + ] + + data_format = "json" + +############################################################################### +# OUTPUTS # +############################################################################### + +[[outputs.influxdb]] + urls = ["http://localhost:8086"] + database = "jitsi" + timeout = "0s" + retention_policy = "" + +JITSI_TELEGRAF + +systemctl enable --now telegraf +systemctl status telegraf + + +sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"" /etc/jitsi/videobridge/config +sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties + +systemctl restart jitsi-videobridge2 + +# Create InfluxDB datasource +curl 'http://admin:admin@localhost:3000/api/datasources' -X \ +POST -H 'Content-Type: application/json;charset=UTF-8' \ +--data-binary \ +'{"name":"InfluxDB","type":"datasource","url":"http://localhost","access":"proxy","isDefault":true,"database":"jitsi"}' + +# Add Grafana Dashboard +### Please edit grafana_* variables to match your Grafana setup: +grafana_host="http://localhost:3000" +grafana_cred="admin:admin" +grafana_datasource="jitsi" +ds=(11969); +for d in "${ds[@]}"; do + echo -n "Processing $d: " + j=$(curl -s -k -u "$grafana_cred" $grafana_host/api/gnet/dashboards/$d | jq .json) + curl -s -k -u "$grafana_cred" -XPOST -H "Accept: application/json" \ + -H "Content-Type: application/json" \ + -d "{\"dashboard\":$j,\"overwrite\":true, \ + \"inputs\":[{\"name\":\"DS_INFLUXDB\",\"type\":\"datasource\", \ + \"pluginId\":\"influxdb\",\"value\":\"$grafana_datasource\"}]}" \ + $grafana_host/api/dashboards/import; echo "" +done From 022ecfeed7ad56855003cee57454e4112255ff0f Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Wed, 1 Jul 2020 16:53:42 -0500 Subject: [PATCH 02/16] Fix several small issues --- grafana.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/grafana.sh b/grafana.sh index b7bb485..d40a1dc 100644 --- a/grafana.sh +++ b/grafana.sh @@ -11,22 +11,24 @@ MAIN_TEL="/etc/telegraf/telegraf.conf" TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf" PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" -# -apt update && apt install -y gnupg2 curl wget +# Min requirements +apt update && apt install -y gnupg2 curl wget jq + +# InfluxDB Repo wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install influxdb -y systemctl enable --now influxdb systemctl status influxdb -# +# Grafana Repo curl -s https://packages.grafana.com/gpg.key | sudo apt-key add - add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" apt update && apt install grafana -y systemctl enable --now grafana-server systemctl status grafana-server -# +# Telegraf Repo wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install telegraf -y @@ -84,7 +86,7 @@ systemctl enable --now telegraf systemctl status telegraf -sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"" /etc/jitsi/videobridge/config +sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"|" /etc/jitsi/videobridge/config sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties systemctl restart jitsi-videobridge2 @@ -93,7 +95,7 @@ systemctl restart jitsi-videobridge2 curl 'http://admin:admin@localhost:3000/api/datasources' -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ -'{"name":"InfluxDB","type":"datasource","url":"http://localhost","access":"proxy","isDefault":true,"database":"jitsi"}' +'{"name":"InfluxDB","type":"influxdb","url":"http://localhost","access":"proxy","isDefault":true,"database":"jitsi"}' # Add Grafana Dashboard ### Please edit grafana_* variables to match your Grafana setup: From 4080043df08e78d8775ff496abc3428db517d7ae Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Wed, 1 Jul 2020 16:59:00 -0500 Subject: [PATCH 03/16] Add entry URL for Grafana --- grafana.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grafana.sh b/grafana.sh index d40a1dc..984caf9 100644 --- a/grafana.sh +++ b/grafana.sh @@ -113,3 +113,5 @@ for d in "${ds[@]}"; do \"pluginId\":\"influxdb\",\"value\":\"$grafana_datasource\"}]}" \ $grafana_host/api/dashboards/import; echo "" done + +echo "Go check on http://$PUBLIC_IP:3000 to review configuration and dashboards." From ce0b04a7ecabea919ec1a36adf5df4bc209fba92 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Wed, 1 Jul 2020 17:58:37 -0500 Subject: [PATCH 04/16] Jet again more small fixes --- grafana.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grafana.sh b/grafana.sh index 984caf9..2c3b57d 100644 --- a/grafana.sh +++ b/grafana.sh @@ -95,13 +95,13 @@ systemctl restart jitsi-videobridge2 curl 'http://admin:admin@localhost:3000/api/datasources' -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ -'{"name":"InfluxDB","type":"influxdb","url":"http://localhost","access":"proxy","isDefault":true,"database":"jitsi"}' +'{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' # Add Grafana Dashboard ### Please edit grafana_* variables to match your Grafana setup: grafana_host="http://localhost:3000" grafana_cred="admin:admin" -grafana_datasource="jitsi" +grafana_datasource="InfluxDB" ds=(11969); for d in "${ds[@]}"; do echo -n "Processing $d: " From 44364927d79f6c3bd37c876af081fba6c51603c1 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Thu, 2 Jul 2020 12:48:09 -0500 Subject: [PATCH 05/16] Testing securing admin passwd --- grafana.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/grafana.sh b/grafana.sh index 2c3b57d..1b7356b 100644 --- a/grafana.sh +++ b/grafana.sh @@ -4,11 +4,14 @@ # https://community.jitsi.org/t/how-to-to-setup-grafana-dashboards-to-monitor-jitsi-my-comprehensive-tutorial-for-the-beginner/ # by Woodworker_Life # Woodworker_Life © - 2020 +# Jitsi Metrics - Grafana dashboard by mephisto +# https://grafana.com/grafana/dashboards/11969 # SwITNet Ltd © - 2020, https://switnet.net/ # GPLv3 or later. MAIN_TEL="/etc/telegraf/telegraf.conf" TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf" +GRAFANA_PASS="$(tr -dc "a-zA-Z0-9#_*=" < /dev/urandom | fold -w 14 | head -n1)" PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" # Min requirements @@ -85,22 +88,28 @@ JITSI_TELEGRAF systemctl enable --now telegraf systemctl status telegraf - +# Setup videobridge options sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"|" /etc/jitsi/videobridge/config sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties - systemctl restart jitsi-videobridge2 +# Grafana Setup +# Reset Grafana admin password +curl -X PUT -H "Content-Type: application/json" -d '{ + "oldPassword": "admin", + "newPassword": "$GRAFANA_PASS", + "confirmNew": "$GRAFANA_PASS" +}' http://admin:admin@localhost:3000/api/user/password + # Create InfluxDB datasource -curl 'http://admin:admin@localhost:3000/api/datasources' -X \ +curl 'http://admin:$GRAFANA_PASS@localhost:3000/api/datasources' -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ '{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' # Add Grafana Dashboard -### Please edit grafana_* variables to match your Grafana setup: grafana_host="http://localhost:3000" -grafana_cred="admin:admin" +grafana_cred="admin:$GRAFANA_PASS" grafana_datasource="InfluxDB" ds=(11969); for d in "${ds[@]}"; do @@ -114,4 +123,6 @@ for d in "${ds[@]}"; do $grafana_host/api/dashboards/import; echo "" done -echo "Go check on http://$PUBLIC_IP:3000 to review configuration and dashboards." +echo " +Go check on http://$PUBLIC_IP:3000 to review configuration and dashboards. +" From c766cb2b54e242fd0f5eb686b7871df12f0b7f81 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 04:21:23 -0500 Subject: [PATCH 06/16] Avoid single quotes on variable --- grafana.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafana.sh b/grafana.sh index 1b7356b..f60a858 100644 --- a/grafana.sh +++ b/grafana.sh @@ -102,7 +102,7 @@ curl -X PUT -H "Content-Type: application/json" -d '{ }' http://admin:admin@localhost:3000/api/user/password # Create InfluxDB datasource -curl 'http://admin:$GRAFANA_PASS@localhost:3000/api/datasources' -X \ +curl "http://admin:$GRAFANA_PASS@localhost:3000/api/datasources" -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ '{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' From f69dbbf2e5216b6bd3cb9773c070c843eaf1262c Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 04:24:08 -0500 Subject: [PATCH 07/16] Show grafana credentials to finish script. --- grafana.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/grafana.sh b/grafana.sh index f60a858..e20f901 100644 --- a/grafana.sh +++ b/grafana.sh @@ -125,4 +125,8 @@ done echo " Go check on http://$PUBLIC_IP:3000 to review configuration and dashboards. +User: admin +Password: $GRAFANA_PASS + +Please save it somewhere safe. " From fb00d603e663442d1176d7c2995b2ac08aa0e188 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 04:27:15 -0500 Subject: [PATCH 08/16] Add comments on installer --- grafana.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/grafana.sh b/grafana.sh index e20f901..02c9a32 100644 --- a/grafana.sh +++ b/grafana.sh @@ -17,26 +17,27 @@ PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" # Min requirements apt update && apt install -y gnupg2 curl wget jq -# InfluxDB Repo +echo "# Setup InfluxDB Packages" wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install influxdb -y systemctl enable --now influxdb systemctl status influxdb -# Grafana Repo +echo "# Setup Grafana Packages" curl -s https://packages.grafana.com/gpg.key | sudo apt-key add - add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" apt update && apt install grafana -y systemctl enable --now grafana-server systemctl status grafana-server -# Telegraf Repo +echo "# Setup Telegraf Packages" wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install telegraf -y mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.original +echo "# Setup Telegraf config files" cat << TELEGRAF > $MAIN_TEL [global_tags] @@ -88,12 +89,12 @@ JITSI_TELEGRAF systemctl enable --now telegraf systemctl status telegraf -# Setup videobridge options +echo "# Setup videobridge options" sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"|" /etc/jitsi/videobridge/config sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties systemctl restart jitsi-videobridge2 -# Grafana Setup +echo "# Setup Grafana credentials." # Reset Grafana admin password curl -X PUT -H "Content-Type: application/json" -d '{ "oldPassword": "admin", @@ -101,13 +102,13 @@ curl -X PUT -H "Content-Type: application/json" -d '{ "confirmNew": "$GRAFANA_PASS" }' http://admin:admin@localhost:3000/api/user/password -# Create InfluxDB datasource +echo "# Create InfluxDB datasource" curl "http://admin:$GRAFANA_PASS@localhost:3000/api/datasources" -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ '{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' -# Add Grafana Dashboard +echo "# Add Grafana Dashboard" grafana_host="http://localhost:3000" grafana_cred="admin:$GRAFANA_PASS" grafana_datasource="InfluxDB" From 40f78f14772c2afe28876fd2d3f64ca0511546f7 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 05:05:59 -0500 Subject: [PATCH 09/16] Yet again double quotes variable issue --- grafana.sh | 48 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/grafana.sh b/grafana.sh index 02c9a32..05bf1fb 100644 --- a/grafana.sh +++ b/grafana.sh @@ -17,27 +17,35 @@ PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" # Min requirements apt update && apt install -y gnupg2 curl wget jq -echo "# Setup InfluxDB Packages" +echo " +# Setup InfluxDB Packages +" wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install influxdb -y systemctl enable --now influxdb systemctl status influxdb -echo "# Setup Grafana Packages" +echo " +# Setup Grafana Packages +" curl -s https://packages.grafana.com/gpg.key | sudo apt-key add - add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" apt update && apt install grafana -y systemctl enable --now grafana-server systemctl status grafana-server -echo "# Setup Telegraf Packages" +echo " +# Setup Telegraf Packages +" wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install telegraf -y mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.original -echo "# Setup Telegraf config files" +echo " +# Setup Telegraf config files +" cat << TELEGRAF > $MAIN_TEL [global_tags] @@ -86,29 +94,41 @@ cat << JITSI_TELEGRAF > $TEL_JIT JITSI_TELEGRAF -systemctl enable --now telegraf +systemctl enable telegraf +systemctl restart telegraf systemctl status telegraf -echo "# Setup videobridge options" +echo " +# Setup videobridge options +" sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"|" /etc/jitsi/videobridge/config sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties systemctl restart jitsi-videobridge2 -echo "# Setup Grafana credentials." +echo " +# Setup Grafana credentials. +" # Reset Grafana admin password -curl -X PUT -H "Content-Type: application/json" -d '{ - "oldPassword": "admin", - "newPassword": "$GRAFANA_PASS", - "confirmNew": "$GRAFANA_PASS" -}' http://admin:admin@localhost:3000/api/user/password +#grafana-cli admin reset-admin-password $GRAFANA_PASS +set -x +curl -X PUT -H "Content-Type: application/json" -d "{ + \"oldPassword\": \"admin\", + \"newPassword\": \"$GRAFANA_PASS\", + \"confirmNew\": \"$GRAFANA_PASS\" +}" http://admin:admin@localhost:3000/api/user/password +set +x -echo "# Create InfluxDB datasource" +echo " +# Create InfluxDB datasource +" curl "http://admin:$GRAFANA_PASS@localhost:3000/api/datasources" -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ '{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' -echo "# Add Grafana Dashboard" +echo " +# Add Grafana Dashboard +" grafana_host="http://localhost:3000" grafana_cred="admin:$GRAFANA_PASS" grafana_datasource="InfluxDB" From c2e50eebeeb8a3b7468ec5cb92f32d0b55faddd8 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 07:15:34 -0500 Subject: [PATCH 10/16] Secure grafana under jitsi SSL domain --- grafana.sh | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/grafana.sh b/grafana.sh index 05bf1fb..963ee8a 100644 --- a/grafana.sh +++ b/grafana.sh @@ -11,6 +11,9 @@ MAIN_TEL="/etc/telegraf/telegraf.conf" TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf" +GRAFANA_INI="/etc/grafana/grafana.ini" +DOMAIN=$(ls /etc/prosody/conf.d/ | grep -v localhost | awk -F'.cfg' '{print $1}' | awk '!NF || !seen[$0]++') +WS_CONF="/etc/nginx/sites-enabled/$DOMAIN.conf" GRAFANA_PASS="$(tr -dc "a-zA-Z0-9#_*=" < /dev/urandom | fold -w 14 | head -n1)" PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" @@ -105,18 +108,36 @@ sed -i "s|JVB_OPTS=\"--apis.*|JVB_OPTS=\"--apis=rest,xmpp\"|" /etc/jitsi/videobr sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties systemctl restart jitsi-videobridge2 +echo " +# Setup Grafana nginx domain +" +sed -i "s|;protocol =.*|protocol = http|" $GRAFANA_INI +sed -i "s|;http_addr =.*|http_addr = localhost|" $GRAFANA_INI +sed -i "s|;http_port =.*|http_port = 3000|" $GRAFANA_INI +sed -i "s|;domain =.*|domain = $DOMAIN|" $GRAFANA_INI +sed -i "s|;enforce_domain =.*|enforce_domain = true|" $GRAFANA_INI +sed -i "s|;root_url =.*|root_url = http://$DOMAIN:3000/grafana/|" $GRAFANA_INI +sed -i "s|;serve_from_sub_path =.*|serve_from_sub_path = true|" $GRAFANA_INI +systemctl restart grafana-server + +if [ -f $WS_CONF ]; then + sed -i "/Anything that didn't match above/i \ \ \ \ location \~ \^\/(grafana\/|grafana\/login) {" $WS_CONF + sed -i "/Anything that didn't match above/i \ \ \ \ \ \ \ \ proxy_pass http:\/\/localhost:3000;" $WS_CONF + sed -i "/Anything that didn't match above/i \ \ \ \ }" $WS_CONF + systemctl reload nginx +else + echo "No app configuration done to server file, please report to: + -> https://github.com/switnet-ltd/quick-jibri-installer/issues" +fi + echo " # Setup Grafana credentials. " -# Reset Grafana admin password -#grafana-cli admin reset-admin-password $GRAFANA_PASS -set -x curl -X PUT -H "Content-Type: application/json" -d "{ \"oldPassword\": \"admin\", \"newPassword\": \"$GRAFANA_PASS\", \"confirmNew\": \"$GRAFANA_PASS\" }" http://admin:admin@localhost:3000/api/user/password -set +x echo " # Create InfluxDB datasource @@ -145,9 +166,13 @@ for d in "${ds[@]}"; do done echo " -Go check on http://$PUBLIC_IP:3000 to review configuration and dashboards. +Go check: + http://$DOMAIN/grafana/ +(emphasis on the trailing \"/\") to review configuration and dashboards. + User: admin Password: $GRAFANA_PASS Please save it somewhere safe. " +read -n 1 -s -r -p "Press any key to continue..."$'\n' From 3f244ef9780071845aba2f26e19c3a2993fa07a9 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 07:17:15 -0500 Subject: [PATCH 11/16] Remove unused variable --- grafana.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/grafana.sh b/grafana.sh index 963ee8a..d0badb4 100644 --- a/grafana.sh +++ b/grafana.sh @@ -15,7 +15,6 @@ GRAFANA_INI="/etc/grafana/grafana.ini" DOMAIN=$(ls /etc/prosody/conf.d/ | grep -v localhost | awk -F'.cfg' '{print $1}' | awk '!NF || !seen[$0]++') WS_CONF="/etc/nginx/sites-enabled/$DOMAIN.conf" GRAFANA_PASS="$(tr -dc "a-zA-Z0-9#_*=" < /dev/urandom | fold -w 14 | head -n1)" -PUBLIC_IP="$(dig -4 @resolver1.opendns.com ANY myip.opendns.com +short)" # Min requirements apt update && apt install -y gnupg2 curl wget jq From 266d625dae415052cbc040b31972ae74d46c515f Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 07:23:24 -0500 Subject: [PATCH 12/16] Integrate Grafana Dashboard to Quick Jibri Installer --- quick_jibri_installer.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/quick_jibri_installer.sh b/quick_jibri_installer.sh index 1978850..d6a3abc 100644 --- a/quick_jibri_installer.sh +++ b/quick_jibri_installer.sh @@ -462,6 +462,17 @@ elif [ "$ENABLE_TRANSCRIPT" = "yes" ]; then echo "Jigasi Transcription will be enabled." fi done +#Grafana +while [[ "$ENABLE_GRAFANA_DSH" != "yes" && "$ENABLE_GRAFANA_DSH" != "no" ]] +do +read -p "> Do you want to setup Grafana Dashboard: (yes or no) +( Please check requirements at: https://github.com/switnet-ltd/quick-jibri-installer )"$'\n' -r ENABLE_GRAFANA_DSH +if [ "$ENABLE_GRAFANA_DSH" = "no" ]; then + echo "Grafana Dashboard won't be enabled." +elif [ "$ENABLE_GRAFANA_DSH" = "yes" ]; then + echo "Grafana Dashboard will be enabled." +fi +done #Start configuration echo ' ######################################################################## @@ -828,6 +839,11 @@ if [ "$ENABLE_TRANSCRIPT" = "yes" ]; then bash $PWD/jigasi.sh fi { +#Grafana Dashboard +if [ "$ENABLE_GRAFANA_DSH" = "yes" ]; then + echo "Grafana Dashboard will be enabled." + bash $PWD/grafana.sh +fi #Prevent Jibri conecction issue sed -i "/127.0.0.1/a \\ 127.0.0.1 $DOMAIN" /etc/hosts From 41ab33c5fe2bf5c6a3d2988f48bc24b311ef143b Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 07:56:42 -0500 Subject: [PATCH 13/16] Tune protocol on URL --- grafana.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/grafana.sh b/grafana.sh index d0badb4..6ab9491 100644 --- a/grafana.sh +++ b/grafana.sh @@ -114,7 +114,7 @@ sed -i "s|;protocol =.*|protocol = http|" $GRAFANA_INI sed -i "s|;http_addr =.*|http_addr = localhost|" $GRAFANA_INI sed -i "s|;http_port =.*|http_port = 3000|" $GRAFANA_INI sed -i "s|;domain =.*|domain = $DOMAIN|" $GRAFANA_INI -sed -i "s|;enforce_domain =.*|enforce_domain = true|" $GRAFANA_INI +sed -i "s|;enforce_domain =.*|enforce_domain = false|" $GRAFANA_INI sed -i "s|;root_url =.*|root_url = http://$DOMAIN:3000/grafana/|" $GRAFANA_INI sed -i "s|;serve_from_sub_path =.*|serve_from_sub_path = true|" $GRAFANA_INI systemctl restart grafana-server @@ -123,7 +123,8 @@ if [ -f $WS_CONF ]; then sed -i "/Anything that didn't match above/i \ \ \ \ location \~ \^\/(grafana\/|grafana\/login) {" $WS_CONF sed -i "/Anything that didn't match above/i \ \ \ \ \ \ \ \ proxy_pass http:\/\/localhost:3000;" $WS_CONF sed -i "/Anything that didn't match above/i \ \ \ \ }" $WS_CONF - systemctl reload nginx + sed -i "/Anything that didn't match above/i \\\n" $WS_CONF + systemctl restart nginx else echo "No app configuration done to server file, please report to: -> https://github.com/switnet-ltd/quick-jibri-installer/issues" @@ -136,12 +137,12 @@ curl -X PUT -H "Content-Type: application/json" -d "{ \"oldPassword\": \"admin\", \"newPassword\": \"$GRAFANA_PASS\", \"confirmNew\": \"$GRAFANA_PASS\" -}" http://admin:admin@localhost:3000/api/user/password +}" http://admin:admin@http://localhost:3000/api/user/password echo " # Create InfluxDB datasource " -curl "http://admin:$GRAFANA_PASS@localhost:3000/api/datasources" -X \ +curl "http://admin:$GRAFANA_PASS@http://localhost:3000/api/datasources" -X \ POST -H 'Content-Type: application/json;charset=UTF-8' \ --data-binary \ '{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' @@ -166,7 +167,9 @@ done echo " Go check: - http://$DOMAIN/grafana/ + +>> http://$DOMAIN/grafana/ + (emphasis on the trailing \"/\") to review configuration and dashboards. User: admin From a748bc8b7522bcb2cb0ef13300029baca012f984 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 08:53:15 -0500 Subject: [PATCH 14/16] Rearrange format --- grafana.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/grafana.sh b/grafana.sh index 6ab9491..d9751f5 100644 --- a/grafana.sh +++ b/grafana.sh @@ -14,7 +14,7 @@ TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf" GRAFANA_INI="/etc/grafana/grafana.ini" DOMAIN=$(ls /etc/prosody/conf.d/ | grep -v localhost | awk -F'.cfg' '{print $1}' | awk '!NF || !seen[$0]++') WS_CONF="/etc/nginx/sites-enabled/$DOMAIN.conf" -GRAFANA_PASS="$(tr -dc "a-zA-Z0-9#_*=" < /dev/urandom | fold -w 14 | head -n1)" +GRAFANA_PASS="$(tr -dc "a-zA-Z0-9#_*" < /dev/urandom | fold -w 14 | head -n1)" # Min requirements apt update && apt install -y gnupg2 curl wget jq @@ -25,7 +25,7 @@ echo " wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list apt update && apt install influxdb -y -systemctl enable --now influxdb +systemctl enable influxdb systemctl status influxdb echo " @@ -34,7 +34,7 @@ echo " curl -s https://packages.grafana.com/gpg.key | sudo apt-key add - add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" apt update && apt install grafana -y -systemctl enable --now grafana-server +systemctl enable grafana-server systemctl status grafana-server echo " @@ -137,15 +137,21 @@ curl -X PUT -H "Content-Type: application/json" -d "{ \"oldPassword\": \"admin\", \"newPassword\": \"$GRAFANA_PASS\", \"confirmNew\": \"$GRAFANA_PASS\" -}" http://admin:admin@http://localhost:3000/api/user/password +}" http://admin:admin@localhost:3000/api/user/password echo " # Create InfluxDB datasource " -curl "http://admin:$GRAFANA_PASS@http://localhost:3000/api/datasources" -X \ -POST -H 'Content-Type: application/json;charset=UTF-8' \ ---data-binary \ -'{"name":"InfluxDB","type":"influxdb","url":"http://localhost:8086","access":"proxy","isDefault":true,"database":"jitsi"}' +curl -X \ +POST -H 'Content-Type: application/json;charset=UTF-8' -d \ +'{ + "name":"InfluxDB", + "type":"influxdb", + "url":"http://localhost:8086", + "access":"proxy", + "isDefault":true, + "database":"jitsi" +}' http://admin:$GRAFANA_PASS@localhost:3000/api/datasources echo " # Add Grafana Dashboard From 457f75ecb195ccd69208b127064ee4d879d0db90 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 08:55:29 -0500 Subject: [PATCH 15/16] add debug mode --- grafana.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/grafana.sh b/grafana.sh index d9751f5..e281b67 100644 --- a/grafana.sh +++ b/grafana.sh @@ -9,6 +9,20 @@ # SwITNet Ltd © - 2020, https://switnet.net/ # GPLv3 or later. +while getopts m: option +do + case "${option}" + in + m) MODE=${OPTARG};; + \?) echo "Usage: sudo ./grafana.sh [-m debug]" && exit;; + esac +done + +#DEBUG +if [ "$MODE" = "debug" ]; then +set -x +fi + MAIN_TEL="/etc/telegraf/telegraf.conf" TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf" GRAFANA_INI="/etc/grafana/grafana.ini" @@ -138,6 +152,7 @@ curl -X PUT -H "Content-Type: application/json" -d "{ \"newPassword\": \"$GRAFANA_PASS\", \"confirmNew\": \"$GRAFANA_PASS\" }" http://admin:admin@localhost:3000/api/user/password +read -n 1 -s -r -p "Press any key to continue..."$'\n' echo " # Create InfluxDB datasource @@ -152,6 +167,7 @@ POST -H 'Content-Type: application/json;charset=UTF-8' -d \ "isDefault":true, "database":"jitsi" }' http://admin:$GRAFANA_PASS@localhost:3000/api/datasources +read -n 1 -s -r -p "Press any key to continue..."$'\n' echo " # Add Grafana Dashboard @@ -170,6 +186,7 @@ for d in "${ds[@]}"; do \"pluginId\":\"influxdb\",\"value\":\"$grafana_datasource\"}]}" \ $grafana_host/api/dashboards/import; echo "" done +read -n 1 -s -r -p "Press any key to continue..."$'\n' echo " Go check: From 107d98b37f1bd0d96aeacd0a8016b87dfdd84704 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 4 Jul 2020 09:14:07 -0500 Subject: [PATCH 16/16] Fix serve from sub_path Grafana option. Working! --- grafana.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/grafana.sh b/grafana.sh index e281b67..a52b098 100644 --- a/grafana.sh +++ b/grafana.sh @@ -151,8 +151,7 @@ curl -X PUT -H "Content-Type: application/json" -d "{ \"oldPassword\": \"admin\", \"newPassword\": \"$GRAFANA_PASS\", \"confirmNew\": \"$GRAFANA_PASS\" -}" http://admin:admin@localhost:3000/api/user/password -read -n 1 -s -r -p "Press any key to continue..."$'\n' +}" http://admin:admin@localhost:3000/grafana/api/user/password echo " # Create InfluxDB datasource @@ -166,13 +165,12 @@ POST -H 'Content-Type: application/json;charset=UTF-8' -d \ "access":"proxy", "isDefault":true, "database":"jitsi" -}' http://admin:$GRAFANA_PASS@localhost:3000/api/datasources -read -n 1 -s -r -p "Press any key to continue..."$'\n' +}' http://admin:$GRAFANA_PASS@localhost:3000/grafana/api/datasources echo " # Add Grafana Dashboard " -grafana_host="http://localhost:3000" +grafana_host="http://localhost:3000/grafana" grafana_cred="admin:$GRAFANA_PASS" grafana_datasource="InfluxDB" ds=(11969); @@ -186,7 +184,6 @@ for d in "${ds[@]}"; do \"pluginId\":\"influxdb\",\"value\":\"$grafana_datasource\"}]}" \ $grafana_host/api/dashboards/import; echo "" done -read -n 1 -s -r -p "Press any key to continue..."$'\n' echo " Go check: