Last active
October 14, 2018 16:14
-
-
Save veve90/17d27eedef926f9de3a1f0d7b509946f to your computer and use it in GitHub Desktop.
TICK-rasbperryPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### SOURCES #######################################################################""" | |
# https://www.influxdata.com/blog/running-the-tick-stack-on-a-raspberry-pi/ | |
# https://makemypi.wordpress.com/2018/02/19/iot-with-influxdb-telegraph-and-grafana-on-the-raspberry-pi-3/ | |
# https://thingsmatic.com/2017/03/02/influxdb-and-grafana-for-sensor-time-series/ | |
# https://github.com/opendata-stuttgart/mqtt-stack/blob/master/howto_setup_tick_stack.md | |
# https://gist.github.com/fragolinux/c9b0025f831d1c9edcdf049d920d34ad | |
## https://bentek.fr/influxdb-grafana-raspberry-pi/ | |
## http://ticksurraspberrypi3.blogspot.com/ | |
## https://www.influxdata.com/integration/mqtt-monitoring/ | |
## https://github.com/fg2it/grafana-on-raspberry | |
### INSTALL EVERYTHING #######################################################################""" | |
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - | |
echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list | |
sudo apt-get update | |
sudo apt-get install telegraf influxdb chronograf kapacitor | |
# influxdb 1.6.3 | |
# telegraf 1.8.1 | |
# kapacitor 1.5.1 | |
sudo apt-get install apt-transport-https curl | |
# to remove old version of grafana (if necessary) | |
sudo dpkg -r grafana grafana-data | |
sudo apt-get -y autoremove | |
sudo rm -rf /etc/grafana /var/lib/grafana /var/log/grafana /etc/rc5.d/S02grafana /etc/rc6.d/K01grafana /etc/rc3.d/S02grafana /etc/rc2.d/S02grafana /etc/rc4.d/S02grafana /etc/rc1.d/K01grafana /etc/default/grafana /etc/init.d/grafana /etc/rc0.d/K01grafana /usr/lib/systemd/system/grafana-server.service /etc/systemd/system/grafana-server.service /etc/systemd/system/grafana.service /etc/systemd/system/multi-user.target.wants/grafana.service /etc/apt/sources.list.d/grafana.list /etc/default/grafana-server /etc/init.d/grafana-server /var/lib/systemd/deb-systemd-helper-enabled/grafana-server.service /var/lib/systemd/deb-systemd-helper-enabled/grafana.service.dsh-also /var/lib/systemd/deb-systemd-helper-enabled/multi-user.target.wants/grafana.service /var/lib/systemd/deb-systemd-helper-masked/grafana.service /home/pi/grafana_2.6.0+dfsg-3_armhf.deb /home/pi/grafana-data_2.6.0+dfsg-3_all.deb | |
# to install latest version f grafana | |
# (the sudo apt-get install grafana is giving a black screen due to missing dependencies on my raspberry pi) | |
curl https://bintray.com/user/downloadSubjectPublicKey?username=bintray | sudo apt-key add - | |
echo "deb https://dl.bintray.com/fg2it/deb jessie main" | sudo tee /etc/apt/sources.list.d/grafana.list | |
sudo apt-get -y update | |
sudo apt-get -y install grafana | |
sudo apt-get install vim | |
### CONFIGURE INFLUXDB #######################################################################""" | |
sudo systemctl enable influxdb | |
sudo systemctl start influxdb | |
# With this we create a user admin and show the later used database. | |
pi@raspberrypi:/etc/telegraf $ influx | |
Connected to http://localhost:8086 version 1.2.2 | |
InfluxDB shell version: 1.2.2 | |
> CREATE USER admin WITH PASSWORD 'veve' WITH ALL PRIVILEGES | |
> CREATE DATABASE telegraf | |
> CREATE DATABASE tm2i | |
> CREATE DATABASE csv2influx | |
> CREATE DATABASE science_is_cool | |
> USE tm2i | |
> SHOW RETENTION POLICIES ON tm2i | |
> exit | |
# be default the retention is 168hours = 7 days | |
# Through this customization in influxdb.conf, we enable authentication. | |
# These three parameters under [http] should be checked and adapted accordingly. | |
sudo vi /etc/influxdb/influxdb.conf | |
[http] | |
enabled = true | |
bind-address = ":8086" | |
auth-enabled = true | |
# Apply changes | |
sudo systemctl restart influxdb | |
influx -username admin -password veve | |
#send data to influxDB | |
curl -i -XPOST "http://localhost:8086/write?db=science_is_cool" --data-binary 'weather,location=us-midwest temperature=84' | |
# send data to influxDB with cli | |
influx | |
> INSERT weather,location=us-midwest temperature=82 1465839830100400200 | |
#create query: | |
http://192.168.1.4:8888/sources/1/chronograf/data-explorer | |
SELECT mean("temperature") AS "mean_temperature" FROM "science_is_cool"."autogen"."weather" WHERE time > :dashboardTime: AND "location"='us-midwest' GROUP BY time(:interval:), "location" FILL(null) | |
#General queries on InfluxDB | |
## queries for mqtt inputs | |
## example insert line from telegraf: | |
## mqtt_consumer,host=zapp,topic=dusti/esp8266-14426623/PPD42NS/P1 value=0.62 1470789545925980255 | |
SHOW MEASUREMENTS | |
SHOW TAG KEYS FROM "mqtt_consumer" | |
SHOW TAG VALUES FROM "mqtt_consumer" WITH KEY = "topic" | |
SHOW TAG VALUES FROM "mqtt_consumer" WITH KEY = "host" | |
SELECT * FROM "mqtt_consumer" | |
SELECT * FROM tm2i."default"."mqtt_consumer" | |
SELECT * FROM "mqtt_consumer" WHERE topic = 'dusti/esp8266-14426623/DHT22/temperature' | |
SELECT * FROM "mqtt_consumer" WHERE topic =~ /.*\/temperature/ | |
### CONFIGURE GRAFANA #######################################################################""" | |
# You can now reach your Grafana via http: // : 3000 . As login you use admin / admin. Then you should change your password under http: // : 3000 / profile / password . Then you have to specify your data source. | |
# The Grafana configuration file is /etc/grafana/grafana.ini. You need to enable http as protocol and set a port to use in this file. | |
sudo vim /etc/grafana/grafana.ini | |
> [server] | |
> # Protocol (http, https, socket) | |
> protocol = http | |
> | |
> # The ip address to bind to, empty will bind to all interfaces | |
> ;http_addr = | |
> | |
> # The http port to use | |
> http_port = 3000 | |
sudo service grafana-server restart | |
sudo systemctl enable grafana-server | |
sudo systemctl start grafana-server | |
#Check that Grafana is up (admin,admin) | |
http://192.168.1.4:3000/ | |
# Create a connection of type influxDB | |
> http://192.168.1.4:8086 | |
> | |
### CONFIGURE TELEGRAF #######################################################################""" | |
wget https://github.com/opendata-stuttgart/mqtt-stack/archive/master.zip | |
unzip master.zip | |
cp mqtt-stack-master/telegraf/mqtt2influx.conf . | |
vim mqtt2influx.conf | |
telegraf -config mqtt2influx.conf | |
### CONFIGURE CHRONOGRAF #######################################################################""" | |
sudo service chronograf start | |
http://192.168.1.4:8888/sources/1/chronograf/data-explorer | |
-- chronograf plotting queries for all sensors | |
SELECT value FROM tm2i."default".mqtt_consumer WHERE tmpltime() AND topic =~ /.*\/temperature/ GROUP BY topic | |
SELECT value FROM tm2i..mqtt_consumer WHERE tmpltime() AND topic =~ /.*\/humidity/ GROUP BY topic | |
SELECT value FROM tm2i..mqtt_consumer WHERE tmpltime() AND topic =~ /.*\/P.$/ GROUP BY topic | |
SELECT value FROM tm2i..mqtt_consumer WHERE tmpltime() AND topic =~ /.*\/P1$/ GROUP BY topic | |
SELECT value FROM tm2i..mqtt_consumer WHERE tmpltime() AND topic =~ /.*\/P2$/ GROUP BY topic | |
-- topic selection: | |
SELECT value FROM tm2i..mqtt_consumer WHERE tmpltime() AND topic = tmpltagvalue('topic', 'topic') | |
-- 5 min averaged data, select topic from dropdown | |
SELECT mean(value) FROM tm2i..mqtt_consumer WHERE tmpltime() AND topic = tmpltagvalue('topic', 'topic') GROUP BY time(5m), topic | |
### CHECK EVERYTHING #######################################################################""" | |
#Check that chronograf is up (monitoring for influxDB) | |
http://192.168.1.4:8888/ | |
#Check that Grafana is up (admin,admin) | |
http://192.168.1.4:3000/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment