1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/grafana_ynh.git synced 2024-09-03 20:36:29 +02:00

Update install to include influxdb2

This is a WIP and it requires support... I'm not skilled enough, notably for the configuration of the data base, and the change from "data base" (influxDB 1) to "bucket" (influxdb2)
This commit is contained in:
biva 2022-02-07 16:35:47 +01:00 committed by GitHub
parent 8fdf9516ba
commit 3a84b98241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,6 +58,16 @@ ynh_script_progression --message="Finding an available port..." --weight=1
port=$(ynh_find_port --port=3000) port=$(ynh_find_port --port=3000)
ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app=$app --key=port --value=$port
#=================================================
# ADD INFLUXDATA REPOSITORY
#=================================================
wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null
export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null
apt update
#================================================= #=================================================
# INSTALL DEPENDENCIES # INSTALL DEPENDENCIES
#================================================= #=================================================
@ -92,35 +102,38 @@ ynh_add_nginx_config
ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=30 ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=30
# If NetData is installed, configure it to feed InfluxDB # If NetData is installed, configure it to feed InfluxDB
netdata_conf="/opt/netdata/etc/netdata/exporting.conf" # as a first version for influxdb2, netdata is not configured (### are added in the removed lines)
if [ -f "$netdata_conf" ] ; then #netdata_conf="/opt/netdata/etc/netdata/exporting.conf"
sed -i '/^\[exporting:global\]$/,/^\[/ { ###if [ -f "$netdata_conf" ] ; then
s/enabled = no/enabled = yes/ ### sed -i '/^\[exporting:global\]$/,/^\[/ {
s/# update every = 10/update every = 60/ ### s/enabled = no/enabled = yes/
}' $netdata_conf ### s/# update every = 10/update every = 60/
if [ -z "$(grep "yunohost" $netdata_conf)" ] ; then ### }' $netdata_conf
cat >> $netdata_conf <<EOF ### if [ -z "$(grep "yunohost" $netdata_conf)" ] ; then
[opentsdb:yunohost] ### cat >> $netdata_conf <<EOF
enabled = yes ###[opentsdb:yunohost]
destination = localhost:4242 ### enabled = yes
# data source = average ### destination = localhost:4242
# prefix = netdata ### # data source = average
# hostname = my_hostname ### # prefix = netdata
update every = 60 ### # hostname = my_hostname
### update every = 60
# buffer on failures = 10 # buffer on failures = 10
# timeout ms = 20000 # timeout ms = 20000
# send names instead of ids = yes # send names instead of ids = yes
# send charts matching = * # send charts matching = *
# send hosts matching = localhost * # send hosts matching = localhost *
EOF ###EOF
fi ### fi
# Restart NetData # Restart NetData
ynh_systemd_action --service_name=netdata --action="restart" ### ynh_systemd_action --service_name=netdata --action="restart"
fi ###fi
# Configure InfluxDB # Configure InfluxDB
### Biva: I'm not sure if this should be kept or not for influxdb2?
if [ -f /etc/influxdb/influxdb.conf ] ; then if [ -f /etc/influxdb/influxdb.conf ] ; then
sed -i '/^\[\[opentsdb\]\]$/,/^\[/ s/enabled = false/enabled = true/' /etc/influxdb/influxdb.conf sed -i '/^\[\[opentsdb\]\]$/,/^\[/ s/enabled = false/enabled = true/' /etc/influxdb/influxdb.conf
else else
[ -d /etc/influxdb ] || mkdir /etc/influxdb [ -d /etc/influxdb ] || mkdir /etc/influxdb
cp ../conf/influxdb.conf /etc/influxdb cp ../conf/influxdb.conf /etc/influxdb
@ -184,17 +197,17 @@ ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<<
# Import default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701) # Import default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
# Remove new lines # Remove new lines
tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json ###tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json
# Fill the template with the defined data source # Fill the template with the defined data source
sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json ###sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
# Escape the dashboard definition for MySQL query (source: https://stackoverflow.com/a/4383994) # Escape the dashboard definition for MySQL query (source: https://stackoverflow.com/a/4383994)
dashboard=$(cat dashboard.json) ###dashboard=$(cat dashboard.json)
printf -v escaped_dashboard "%q" "$dashboard" ###printf -v escaped_dashboard "%q" "$dashboard"
# Import dashboard into MySQL # Import dashboard into MySQL
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard (id, version, slug, title, data, org_id, created, updated, uid) VALUES ###ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard (id, version, slug, title, data, org_id, created, updated, uid) VALUES
(99999, 0, 'NetData', 'NetData', \"$escaped_dashboard\", 1, '2020-05-16 14:36:50', '2020-05-16 14:36:50', 'yunohost');" ###(99999, 0, 'NetData', 'NetData', \"$escaped_dashboard\", 1, '2020-05-16 14:36:50', '2020-05-16 14:36:50', 'yunohost');"
# Add dashboard version # Add dashboard version
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");" ###ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");"
# Enable the systemd service so that InfluxDB and Grafana start at boot # Enable the systemd service so that InfluxDB and Grafana start at boot
systemctl enable influxdb.service --quiet systemctl enable influxdb.service --quiet