forked from intel/pcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
56 lines (44 loc) · 1.96 KB
/
start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
if [ "$#" -ne 1 ];
then
echo
echo "Usage: $0 http(s)://target_address:port"
echo
echo "target_address is the hostname or IP address of the system that runs pcm-sensor-server"
exit 1
fi
# check if argument is file, create the telegraf.conf accordingly
if [ -f "$1" ]; then
echo "creating telegraf.conf for hosts in targets file";
head -n -7 "telegraf.conf.template" > telegraf.conf
while IFS='' read -r line || [[ -n "$line" ]]; do
# Split the line at the : character to get the IP and port
ip=$(echo "$line" | cut -d ':' -f 1)
port=$(echo "$line" | cut -d ':' -f 2)
# Append the transformed line to the output file, separated by a comma
echo -n "\"http://$ip:$port/persecond/\"," >> telegraf.conf
done < $1
sed -i '$ s/,$//' telegraf.conf
tail -n -6 "telegraf.conf.template" >> telegraf.conf
echo Downloading PCM dashboard
curl -o grafana_volume/dashboards/pcm-dashboard.json $(head -1 $1)/dashboard
else
echo "creating telegraf.conf for $1 ";
sed "s#PCMSENSORSERVER#$1#g" telegraf.conf.template > telegraf.conf
echo Downloading PCM dashboard
curl -o grafana_volume/dashboards/pcm-dashboard.json $1/dashboard
fi
mkdir -p grafana_volume/dashboards
mkdir -p influxdb_volume
chmod -R 777 *_volume
mkdir -p provisioning/datasources
cp automatic_influxdb.yml provisioning/datasources/automatic.yml
echo Downloading PCM dashboard
curl -o grafana_volume/dashboards/pcm-dashboard.json $1/dashboard
echo Starting influxdb
docker run -d --name influxdb -p 8083:8083 -p 8086:8086 -v $PWD/influxdb_volume:/var/lib/influxdb influxdb:1.8.0-alpine
echo Starting telegraf
docker run -d --name telegraf --link=influxdb -v $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf
echo Starting grafana
docker run -d --link=influxdb --name grafana -p 3000:3000 -v $PWD/provisioning:/etc/grafana/provisioning -v $PWD/grafana_volume:/var/lib/grafana grafana/grafana
echo Start browser at http://localhost:3000/ and login with admin user, password admin