Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
data
.idea
*.bak
*.bak
deploy.sh
52 changes: 42 additions & 10 deletions armv6-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
#!/bin/bash
# shellcheck disable=SC2086
# https://wiki.bash-hackers.org/howto/getopts_tutorial 🍻

usage() {
echo " -i install telelgraf on the remote machine"
echo " -u username to use for ssh connection"
echo " -t target host or ip address for ssh connection"
echo " -r remote influx master node/hub ip address or hostname"
}

while getopts ":hiu:t:r:" opt; do
case $opt in
i ) INSTALL=1;;
t ) PI_HOST=$OPTARG;;
u ) PI_USER=$OPTARG;;
h ) usage; exit 0;;
r ) HUB_IP_OR_HOST=$OPTARG;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument. " >&2
exit 1
;;
esac
done

if [ -z ${PI_HOST} ] && [ -z ${PI_USER} ]; then echo "neither host nor username is set" && exit 1; fi
if [ -z ${PI_HOST} ] || [ -z ${PI_USER} ]; then echo "both host and username need to be set" && exit 1; fi
if [ -z ${HUB_IP_OR_HOST} ]; then echo "you need to use the -r flag, see -h for more info" && exit 1; fi
if [ -n "$INSTALL" ]; then echo "going to install telelgraf"; fi

PI_USER=$1
PI_HOST=$2
HUB_IP_OR_HOST=$3
PI_USER_AT_HOST="${PI_USER}@${PI_HOST}"

scp armv6/telegraf.conf "${PI_USER_AT_HOST}:/home/${PI_USER}/telegraf.conf"

ssh "${PI_USER_AT_HOST}" /bin/bash <<EOF

#echo "initial install"
#curl -sL 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
#sudo apt-get update && sudo apt-get install telegraf -y
### comment out the next line if you do not run docker on this machine
#sudo usermod -aG docker telegraf && echo 'usermod'
if [ -n "$INSTALL" ];
then
echo "initial install"
curl -sL 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
sudo apt-get update && sudo apt-get install telegraf -y
## comment out the next line if you do not run docker on this machine
sudo usermod -aG docker telegraf && echo 'usermod'
fi

echo "deployment"
sudo systemctl stop telegraf && echo 'stop'
cat /home/$PI_USER/telegraf.conf | sudo tee /etc/telegraf/telegraf.conf
export INFLUX_URL="http://$HUB_IP_OR_HOST:8086"
# remove variables are escaped, .e.g \$INFLUX_URL
# remote variables are escaped, e.g. \$INFLUX_URL
echo "INFLUX_URL=\"\$INFLUX_URL\"" | sudo tee /etc/default/telegraf

sudo systemctl daemon-reload && echo 'reload'
Expand Down
1 change: 0 additions & 1 deletion configs/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
## The full HTTP or UDP URL for your InfluxDB instance.
#urls = ["http://192.168.0.28:8086"]
urls = ["http://influxdb:8086"]

## The target database for metrics; will be created as needed.
Expand Down
29 changes: 18 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,44 @@ https://www.influxdata.com/time-series-platform/ for raspberry pi with docker.
* running raspian
* with [docker](https://docs.docker.com/engine/install/debian/#install-using-the-convenience-script) and [docker-compose](https://docs.docker.com/compose/install/) installed
- (optional) some other Pi's to connect to the hub
* running raspian with ssh enables (to use automation scripts)
* running raspian with ssh enabled (to use automation scripts)

## Installing the Hub

1. Log in to your Pi
2. clone this repository and `cd` into it
3. (optional) to have this Pi's hostname show up in metrics, run: `export TELEGRAF_HOST="$(hostname)"`
4. (optional) `docker-compose config` to output the compose file with the actual env vars set.
5. `docker-compose up`
5. `docker-compose up` (to see logs) or `docker-compose up -d` to run detached/in background.

Visit http://localhost:5000/sources/0/hosts if running locally, or
`http://<your-pi-hostname.local-or-ip>:5000/sources/0/hosts` to check your metrics are coming through.
`http://<your-pi-hostname.local-or-ip>:5000/sources/0/hosts` to check your metrics are coming through for the "hub".

## Installing Telegraf on Nodes (Arm v6)

The official telegraf image won't work on Arm v6 Pi's.
Instead, we need to install telegraf on the host with `apt`.

There is a file ([armv6-deploy.sh](armv6/telegraf.conf)) included which can install telegraf on your pi and start it up with a
config file, see [armv6/telegraf.conf](armv6/telegraf.conf). Run the file with three bits of info:
* username
* hostname or IP address of the pi you want to install telegraf on
* the hostname or IP address of the pi (hub) which is running the TICK stack
There is a file ([armv6-deploy.sh](armv6-deploy.sh) included which can install telegraf on your pi and start it up with a
config file, see [armv6/telegraf.conf](armv6/telegraf.conf).

If you usually SSH into your pi like: `ssh pi@pi2.local` and the hub running the TICK stack is `192.168.0.2`,
then you'd run the script like this:
```
./armv6-deploy.sh -h
-i install telelgraf on the remote machine
-u username to use for ssh connection
-t target host or ip address for ssh connection
-r remote influx master node/hub ip address or hostname
```

If you usually SSH into your pi like: `ssh pi@pi2.local` and the hub running the TICK stack is `192.168.0.2`, **and** you
want to install `telegraf`, then you'd run the script like this:

```
./armv6-deploy.sh pi pi2.local 192.168.0.2
./armv6-deploy.sh -i -u pi -t pi2.local -r 192.168.0.2
```

Once you have installed telegraf on a given machine, you shouldn't use the `-i` flag again.

Do look at the script and try to understand what it does before running it 😜

### TODO
Expand Down