2020-07-01 20:23:08 +00:00
|
|
|
#!/bin/bash
|
2020-07-06 20:39:49 +00:00
|
|
|
# Grafana Installer for Jitsi Meet
|
|
|
|
#
|
2020-07-01 20:23:08 +00:00
|
|
|
# Based on:
|
2020-07-06 20:39:49 +00:00
|
|
|
# - https://community.jitsi.org/t/38696
|
|
|
|
# by Igor Kerstges
|
|
|
|
# - https://grafana.com/grafana/dashboards/11969
|
|
|
|
# by "mephisto"
|
|
|
|
#
|
2021-05-04 05:37:08 +00:00
|
|
|
# Igor Kerstges © - 2021
|
|
|
|
# SwITNet Ltd © - 2021, https://switnet.net/
|
2020-07-06 20:39:49 +00:00
|
|
|
#
|
2020-07-01 20:23:08 +00:00
|
|
|
# GPLv3 or later.
|
|
|
|
|
2020-07-04 13:55:29 +00:00
|
|
|
while getopts m: option
|
|
|
|
do
|
2021-04-12 02:34:14 +00:00
|
|
|
case "${option}"
|
|
|
|
in
|
|
|
|
m) MODE=${OPTARG};;
|
|
|
|
\?) echo "Usage: sudo ./grafana.sh [-m debug]" && exit;;
|
|
|
|
esac
|
2020-07-04 13:55:29 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
#DEBUG
|
|
|
|
if [ "$MODE" = "debug" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2022-05-12 04:53:51 +00:00
|
|
|
if ! [ "$(id -u)" = 0 ]; then
|
2020-07-04 19:57:37 +00:00
|
|
|
echo "You need to be root or have sudo privileges!"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
clear
|
|
|
|
echo '
|
|
|
|
########################################################################
|
|
|
|
Grafana Dashboard addon
|
|
|
|
########################################################################
|
|
|
|
by Software, IT & Networks Ltd
|
|
|
|
'
|
2020-07-04 18:26:33 +00:00
|
|
|
run_service() {
|
2022-05-12 04:53:51 +00:00
|
|
|
systemctl enable "$1"
|
|
|
|
systemctl restart "$1"
|
|
|
|
systemctl status "$1"
|
2020-07-04 18:26:33 +00:00
|
|
|
}
|
2020-07-01 20:23:08 +00:00
|
|
|
MAIN_TEL="/etc/telegraf/telegraf.conf"
|
|
|
|
TEL_JIT="/etc/telegraf/telegraf.d/jitsi.conf"
|
2020-07-04 12:15:34 +00:00
|
|
|
GRAFANA_INI="/etc/grafana/grafana.ini"
|
2022-05-12 04:53:51 +00:00
|
|
|
DOMAIN="$(find /etc/prosody/conf.d/ -name \*.lua|awk -F'.cfg' '!/localhost/{print $1}'|xargs basename)"
|
2022-04-13 04:11:59 +00:00
|
|
|
WS_CONF="/etc/nginx/sites-available/$DOMAIN.conf"
|
2020-07-04 19:57:37 +00:00
|
|
|
GRAFANA_PASS="$(tr -dc "a-zA-Z0-9#_*=" < /dev/urandom | fold -w 14 | head -n1)"
|
2020-07-01 20:23:08 +00:00
|
|
|
|
2020-07-01 21:53:42 +00:00
|
|
|
# Min requirements
|
2021-04-12 02:34:14 +00:00
|
|
|
apt-get update && \
|
|
|
|
apt-get install -y gnupg2 \
|
|
|
|
curl \
|
|
|
|
wget \
|
|
|
|
jq
|
2020-07-01 21:53:42 +00:00
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Setup InfluxDB Packages
|
|
|
|
"
|
2020-07-01 20:23:08 +00:00
|
|
|
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
|
2021-04-12 02:34:14 +00:00
|
|
|
apt-get update && apt-get install influxdb -y
|
2020-07-04 18:26:33 +00:00
|
|
|
run_service influxdb
|
2020-07-01 20:23:08 +00:00
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Setup Grafana Packages
|
|
|
|
"
|
2020-07-01 20:23:08 +00:00
|
|
|
curl -s https://packages.grafana.com/gpg.key | sudo apt-key add -
|
|
|
|
add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
|
2021-04-12 02:34:14 +00:00
|
|
|
apt-get update && apt-get install grafana -y
|
2020-07-04 18:26:33 +00:00
|
|
|
run_service grafana-server
|
2020-07-01 20:23:08 +00:00
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Setup Telegraf Packages
|
|
|
|
"
|
2020-07-01 20:23:08 +00:00
|
|
|
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
|
2021-04-12 02:34:14 +00:00
|
|
|
apt-get update && apt-get install telegraf -y
|
2020-07-01 20:23:08 +00:00
|
|
|
mv /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.original
|
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Setup Telegraf config files
|
|
|
|
"
|
2020-07-01 20:23:08 +00:00
|
|
|
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
|
|
|
|
|
2020-07-04 18:26:33 +00:00
|
|
|
run_service telegraf
|
2020-07-01 20:23:08 +00:00
|
|
|
|
2022-05-20 23:14:00 +00:00
|
|
|
echo -n "\n# Setup videobridge options\n"
|
|
|
|
echo '
|
|
|
|
# extra options to pass to the JVB daemon
|
|
|
|
JVB_OPTS="--apis=rest,xmpp"' >> /etc/jitsi/videobridge/config
|
2020-07-01 20:23:08 +00:00
|
|
|
sed -i "s|TRANSPORT=muc|TRANSPORT=muc,colibri|" /etc/jitsi/videobridge/sip-communicator.properties
|
|
|
|
systemctl restart jitsi-videobridge2
|
|
|
|
|
2022-05-20 23:14:00 +00:00
|
|
|
echo -e "\n# Setup Grafana nginx domain\n"
|
2020-07-04 12:15:34 +00:00
|
|
|
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
|
2020-07-04 12:56:42 +00:00
|
|
|
sed -i "s|;enforce_domain =.*|enforce_domain = false|" $GRAFANA_INI
|
2020-07-04 12:15:34 +00:00
|
|
|
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
|
2020-07-06 20:37:02 +00:00
|
|
|
sed -i "s|;allow_sign_up =.*|allow_sign_up = false|" $GRAFANA_INI
|
2020-07-04 20:32:11 +00:00
|
|
|
|
2020-07-04 12:15:34 +00:00
|
|
|
systemctl restart grafana-server
|
2020-07-04 20:32:11 +00:00
|
|
|
echo "Waiting for Grafana to load..."
|
|
|
|
secs=$((10))
|
|
|
|
while [ $secs -gt 0 ]; do
|
|
|
|
echo -ne "$secs\033[0K\r"
|
|
|
|
sleep 1
|
|
|
|
: $((secs--))
|
|
|
|
done
|
2020-07-04 12:15:34 +00:00
|
|
|
|
2022-05-12 04:53:51 +00:00
|
|
|
if [ -f "$WS_CONF" ]; then
|
|
|
|
sed -i "/# ensure all static content can always be found first/i \ \ \ \ location \~ \^\/(grafana\/|grafana\/login) {" "$WS_CONF"
|
|
|
|
sed -i "/# ensure all static content can always be found first/i \ \ \ \ \ \ \ \ proxy_pass http:\/\/localhost:3000;" "$WS_CONF"
|
|
|
|
sed -i "/# ensure all static content can always be found first/i \ \ \ \ }" "$WS_CONF"
|
|
|
|
sed -i "/# ensure all static content can always be found first/i \\\n" "$WS_CONF"
|
2021-04-12 02:34:14 +00:00
|
|
|
systemctl restart nginx
|
2020-07-04 12:15:34 +00:00
|
|
|
else
|
2021-04-12 02:34:14 +00:00
|
|
|
echo "No app configuration done to server file, please report to:
|
2020-07-04 12:15:34 +00:00
|
|
|
-> https://github.com/switnet-ltd/quick-jibri-installer/issues"
|
|
|
|
fi
|
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Setup Grafana credentials.
|
|
|
|
"
|
2020-07-06 20:37:02 +00:00
|
|
|
curl -s -k -u "admin:admin" -X \
|
2020-07-04 20:17:05 +00:00
|
|
|
PUT -H "Content-Type: application/json;charset=UTF-8" -d \
|
2020-07-04 19:26:10 +00:00
|
|
|
"{
|
2020-07-04 10:05:59 +00:00
|
|
|
\"oldPassword\": \"admin\",
|
|
|
|
\"newPassword\": \"$GRAFANA_PASS\",
|
|
|
|
\"confirmNew\": \"$GRAFANA_PASS\"
|
2020-07-04 20:17:05 +00:00
|
|
|
}" http://localhost:3000/api/user/password; echo ""
|
2020-07-02 17:48:09 +00:00
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Create InfluxDB datasource
|
|
|
|
"
|
2020-07-06 20:37:02 +00:00
|
|
|
curl -s -k -u "admin:$GRAFANA_PASS" -X \
|
2020-07-04 13:53:15 +00:00
|
|
|
POST -H 'Content-Type: application/json;charset=UTF-8' -d \
|
|
|
|
'{
|
2021-04-12 02:34:14 +00:00
|
|
|
"name": "InfluxDB",
|
|
|
|
"type": "influxdb",
|
|
|
|
"url": "http://localhost:8086",
|
|
|
|
"access": "proxy",
|
|
|
|
"isDefault": true,
|
|
|
|
"database": "jitsi"
|
2020-07-04 19:57:37 +00:00
|
|
|
}' http://localhost:3000/api/datasources; echo ""
|
2020-07-01 20:23:08 +00:00
|
|
|
|
2020-07-04 10:05:59 +00:00
|
|
|
echo "
|
|
|
|
# Add Grafana Dashboard
|
|
|
|
"
|
2020-07-04 18:26:33 +00:00
|
|
|
grafana_host="http://localhost:3000"
|
2020-07-02 17:48:09 +00:00
|
|
|
grafana_cred="admin:$GRAFANA_PASS"
|
2020-07-01 22:58:37 +00:00
|
|
|
grafana_datasource="InfluxDB"
|
2020-07-01 20:23:08 +00:00
|
|
|
ds=(11969);
|
|
|
|
for d in "${ds[@]}"; do
|
2022-05-12 04:53:51 +00:00
|
|
|
echo "Processing $d: "
|
|
|
|
j="$(curl -s -k -u "$grafana_cred" "$grafana_host"/api/gnet/dashboards/"$d" | jq .json)"
|
2020-07-06 20:37:02 +00:00
|
|
|
curl -s -k -u "$grafana_cred" -XPOST -H "Accept: application/json" \
|
2020-07-01 20:23:08 +00:00
|
|
|
-H "Content-Type: application/json" \
|
2020-07-04 19:26:10 +00:00
|
|
|
-d "{
|
|
|
|
\"dashboard\": $j,
|
|
|
|
\"overwrite\": true,
|
|
|
|
\"inputs\": [{
|
|
|
|
\"name\": \"DS_INFLUXDB\",
|
|
|
|
\"type\": \"datasource\",
|
|
|
|
\"pluginId\": \"influxdb\",
|
|
|
|
\"value\": \"$grafana_datasource\"
|
|
|
|
}]
|
|
|
|
}" $grafana_host/api/dashboards/import; echo ""
|
2020-07-01 20:23:08 +00:00
|
|
|
done
|
2020-07-01 21:59:00 +00:00
|
|
|
|
2020-07-02 17:48:09 +00:00
|
|
|
echo "
|
2020-07-04 12:15:34 +00:00
|
|
|
Go check:
|
2020-07-04 12:56:42 +00:00
|
|
|
|
|
|
|
>> http://$DOMAIN/grafana/
|
|
|
|
|
2020-07-04 12:15:34 +00:00
|
|
|
(emphasis on the trailing \"/\") to review configuration and dashboards.
|
|
|
|
|
2020-07-04 09:24:08 +00:00
|
|
|
User: admin
|
|
|
|
Password: $GRAFANA_PASS
|
|
|
|
|
|
|
|
Please save it somewhere safe.
|
2020-07-02 17:48:09 +00:00
|
|
|
"
|
2020-07-04 12:15:34 +00:00
|
|
|
read -n 1 -s -r -p "Press any key to continue..."$'\n'
|