aboutsummaryrefslogblamecommitdiffstats
path: root/prometheus.sh
blob: 23877dcdfdea45ec4d834afe05b60b8d1fb0a7ea (plain) (tree)
1
2
3
4
5
6
7
8
9








                 

                                       


                                     



                                                     


                               





                                                    

                        
                     




                                           

                                                        











                                                                                     






                                                                                  


                                  








                                                                                                                                                                  

           

                                                                                        
                                                                                                    





                                                                              
#!/usr/bin/env sh

set -e
#set -x

NAME=$1
DIST=archlinux
RELEASE=current
ARCH=amd64
PACKAGES="git sudo base-devel grafana \
	cronie erlang-nox make"

for f in ci.d/*; do source "$f"; done

# This or that may be required to keep the static IP:
kill $(cat /var/run/lxc/dnsmasq.pid)
systemctl restart lxc-net

lxc_destroy
lxc_create $DIST $RELEASE $ARCH
lxc_wait_for_ip

# Necessary because it's using a static IP address
# configured via dnsmasq and the network isn't ready
# when lxc_wait_for_ip returns. Oh well.
sleep 5

pacman_upgrade
pacman_install $PACKAGES
archlinux_enable_cron

echo "[auth.anonymous]" >> /etc/grafana.ini
echo "enabled = true" >> /etc/grafana.ini
echo "org_role = Admin" >> /etc/grafana.ini

lxc_do grafana-cli plugins install flant-statusmap-panel

lxc_do git clone https://aur.archlinux.org/prometheus-bin.git /tmp/prometheus-bin
lxc_do chown -R nobody:nobody /tmp/prometheus-bin
lxc_do sudo -u nobody bash -c 'cd /tmp/prometheus-bin && makepkg'
lxc_do bash -c 'pacman --noconfirm -U /tmp/prometheus-bin/prometheus-bin*.pkg.tar.xz'

lxc_do bash -c "printf \"%s\n\" \
	\"\" \
	\"  - job_name: 'grafana'\" \
	\"\" \
	\"    static_configs:\" \
	\"      - targets: ['localhost:3000']\" >> /etc/prometheus/prometheus.yml"

lxc_do bash -c "printf \"%s\n\" \
	\"\" \
	\"  - job_name: 'ranch_prometheus_example'\" \
	\"\" \
	\"    static_configs:\" \
	\"      - targets: ['localhost:8080']\" >> /etc/prometheus/prometheus.yml"

lxc_do systemctl enable grafana
lxc_do systemctl enable prometheus

lxc_do mkdir -p /home/ninenines
lxc_do git clone https://github.com/juhlig/prometheus_ranch_example /home/ninennes/prometheus_ranch_example
lxc_do make -C /home/ninenines/prometheus_ranch_example clean
lxc_do make -C /home/ninenines/prometheus_ranch_example

lxc_do sh -c 'echo "@reboot /home/ninenines/prometheus_ranch_example/_rel/prometheus_ranch_example_release/bin/prometheus_ranch_example_release start" >> tmpcron'
lxc_do sh -c 'crontab tmpcron'
lxc_do sh -c 'rm tmpcron'

lxc_restart

lxc_do /usr/bin/env sh -c "until curl http://localhost:8080/metrics ; do sleep 1 ; done"

lxc_do /usr/bin/env sh -c "until curl http://admin:admin@localhost:3000/api/org ; do sleep 1 ; done"

echo
<$( cd "$( dirname "$0" )" && pwd )/priv/grafana_prometheus_data_source.json \
	lxc_do curl -H "content-type: application/json" --data-binary @- \
		http://admin:admin@localhost:3000/api/datasources
echo