Skip to content

Commit

Permalink
Updated ansible playbooks and fixed datasource/sample setup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlinaNova21 committed Jul 13, 2016
1 parent 2d53dbe commit ffd20d1
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 75 deletions.
22 changes: 7 additions & 15 deletions README.md
Expand Up @@ -16,13 +16,13 @@ cp docker-compose.env.example docker-compose.env
$EDITOR docker-compose.env
```

Run the docker thing:
Run the setup:

```
docker-compose up
bash setup.sh
```

Go to http://localhost:1337 in your browser, then see SETUP below.
Go to http://localhost:1337 in your browser, then see Usage below.

## Path 2: Robust but not easy

Expand Down Expand Up @@ -53,26 +53,17 @@ ansible-playbook \

If the run errors out, check your parameters and retry. It is common to see transient errors from Apt or GPG, which are both fixed by re-running.

You are now ready to Setup
You are now ready to use grafana!

## Setup
## Usage

Got to http://localhost:1337 or your own real-life server's IP. Login with the following default credentials:

```
username: admin
password: admin
```

*THIS NEXT STEP IS VERY IMPORTANT, AND IF YOU SKIP IT NOTHING WILL SEEM TO WORK*

Add graphite as a data source by going to Data Sources -> Add New, then entering the following Url under Http settings:

```
http://localhost:8000
```

Click Add. You are now ready to [create some dashboards](https://www.youtube.com/watch?v=OUvJamHeMpw).
You are now ready to [create some dashboards](https://www.youtube.com/watch?v=OUvJamHeMpw).

To send stats to the dashboard, simply write them to `Memory.stats`. For example:

Expand All @@ -81,6 +72,7 @@ Memory.stats["room." + room.name + ".energyAvailable"] = room.energyAvailable;
Memory.stats["room." + room.name + ".energyCapacityAvailable"] = room.energyCapacityAvailable;
Memory.stats["room." + room.name + ".controllerProgress"] = room.controller.progress;
```
A sample dashboard is already installed that displays these

All values on the `Memory.stats` object are forwarded to Grafana verbatim.

Expand Down
81 changes: 43 additions & 38 deletions docker-compose.yml
@@ -1,38 +1,43 @@
node:
build: .
links:
- statsd
environment:
GRAPHITE_PORT_8125_UDP_ADDR: "statsd"
env_file: docker-compose.env
statsd:
image: ennexa/statsd
links:
- graphite
graphite:
image: ennexa/graphite
volumes:
- /opt/graphite/conf
- /opt/graphite/storage/whisper
grafana:
image: grafana/grafana
volumes:
- /var/lib/grafana
links:
- graphite
ports:
- "3000:3000"
grafana_setup_datasource:
image: appropriate/curl
links:
- grafana
command: |
curl 'http://admin:admin@grafana:3000/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"localGraphite","type":"graphite","url":"http://graphite:8000","access":"proxy","isDefault":true,"database":""}'
grafana_setup_sampledashboard:
image: appropriate/curl
links:
- grafana
volumes:
- ./sampleDashboard.json:/sampleDashboard.json
command: |
curl 'http://admin:admin@grafana:3000/api/dashboards/db' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data @/sampleDashboard.json
version: "2"
services:
node:
image: kaen/screeps-statsd
restart: always
links:
- statsd
environment:
GRAPHITE_PORT_8125_UDP_ADDR: "statsd"
env_file: docker-compose.env
statsd:
image: ennexa/statsd
links:
- graphite
graphite:
image: ennexa/graphite
restart: always
volumes:
- /opt/graphite/conf
- /opt/graphite/storage/whisper
grafana:
image: grafana/grafana
restart: always
volumes:
- /var/lib/grafana
links:
- graphite
ports:
- "1337:3000"
# grafana_setup_datasource:
# image: appropriate/curl
# links:
# - grafana
# command: |
# curl 'http://admin:admin@grafana:3000/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"localGraphite","type":"graphite","url":"http://graphite:8000","access":"proxy","isDefault":true,"database":""}'
# grafana_setup_sampledashboard:
# image: appropriate/curl
# links:
# - grafana
# volumes:
# - ./sampleDashboard.json:/sampleDashboard.json
# command: |
# curl 'http://admin:admin@grafana:3000/api/dashboards/db' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data @/sampleDashboard.json
1 change: 1 addition & 0 deletions playbook.retry
@@ -0,0 +1 @@
192.168.122.5
2 changes: 1 addition & 1 deletion roles/screeps-statsd/defaults/main.yml
@@ -1,5 +1,5 @@
---
# defaults file for screeps-statsd
docker_engine_version: 1.9.1
docker_engine_version: latest
docker_keyserver: hkp://p80.pool.sks-keyservers.net:80
docker_repo_key: 58118E89F3A912897C070ADBF76221572C52609D
56 changes: 56 additions & 0 deletions roles/screeps-statsd/files/docker-compose
@@ -0,0 +1,56 @@
#!/bin/bash
#
# Run docker-compose in a container
#
# This script will attempt to mirror the host paths by using volumes for the
# following paths:
# * $(pwd)
# * $(dirname $COMPOSE_FILE) if it's set
# * $HOME if it's set
#
# You can add additional volumes (or any docker run options) using
# the $COMPOSE_OPTIONS environment variable.
#


set -e

VERSION="1.7.1"
IMAGE="docker/compose:$VERSION"


# Setup options for connecting to docker host
if [ -z "$DOCKER_HOST" ]; then
DOCKER_HOST="/var/run/docker.sock"
fi
if [ -S "$DOCKER_HOST" ]; then
DOCKER_ADDR="-v $DOCKER_HOST:$DOCKER_HOST -e DOCKER_HOST"
else
DOCKER_ADDR="-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH"
fi


# Setup volume mounts for compose config and context
if [ "$(pwd)" != '/' ]; then
VOLUMES="-v $(pwd):$(pwd)"
fi
if [ -n "$COMPOSE_FILE" ]; then
compose_dir=$(dirname $COMPOSE_FILE)
fi
# TODO: also check --file argument
if [ -n "$compose_dir" ]; then
VOLUMES="$VOLUMES -v $compose_dir:$compose_dir"
fi
if [ -n "$HOME" ]; then
VOLUMES="$VOLUMES -v $HOME:$HOME -v $HOME:/root" # mount $HOME in /root to share docker.config
fi

# Only allocate tty if we detect one
if [ -t 1 ]; then
DOCKER_RUN_OPTIONS="-t"
fi
if [ -t 0 ]; then
DOCKER_RUN_OPTIONS="$DOCKER_RUN_OPTIONS -i"
fi

exec docker run --rm $DOCKER_RUN_OPTIONS $DOCKER_ADDR $COMPOSE_OPTIONS $VOLUMES -w "$(pwd)" $IMAGE "$@"
65 changes: 44 additions & 21 deletions roles/screeps-statsd/tasks/main.yml
Expand Up @@ -10,7 +10,7 @@

- name: Install docker
when: ansible_distribution == 'Ubuntu'
apt: name=docker-engine={{ docker_engine_version }}-0~{{ansible_distribution_release}} update_cache=yes
apt: name=docker-engine update_cache=yes

- name: Install pip
when: ansible_distribution == 'Ubuntu'
Expand All @@ -19,6 +19,15 @@
- name: Install docker-py
pip: name=docker-py

- name: Install pyyaml
pip: name=pyyaml

- name: Install docker-compose
copy:
src: docker-compose
dest: /usr/local/bin/docker-compose
mode: 755

- name: Check for data volume
stat: path=/dev/xvdf
register: data_volume
Expand Down Expand Up @@ -49,24 +58,38 @@
- /data/data/grafana:/opt/grafana/data
when: data_volume.stat.exists

- name: copy docker-compose.yml
copy:
src: docker-compose.yml
dest: /root/

- name: create docker-compose.override.yml
copy:
content: |
version: "2"
services:
grafana:
ports:
- "80:3000"
dest: /root/docker-compose.override.yml

- name: copy sample dashboard
copy:
src: sampleDashboard.json
dest: /root/sampleDashboard.json

- name: copy setup script
copy:
src: setup.sh
dest: /root/setup.sh

- name: Write docker-compose.env
template:
src: docker-compose.env.j2
dest: /root/docker-compose.env

# tasks file for screeps-statsd
- name: graphite docker
docker:
name: graphite
image: kamon/grafana_graphite
ports:
- "80:80"
- "81:81"
state: restarted
volumes: "{{ docker_volume_options | default() }}"

- name: screeps-statsd docker
docker:
name: screeps-statsd
image: kaen/screeps-statsd
links:
- graphite
env:
SCREEPS_USERNAME: "{{ screeps_username }}"
SCREEPS_EMAIL: "{{ screeps_email }}"
SCREEPS_PASSWORD: "{{ screeps_password }}"
- name: docker containers
command: bash setup.sh
args:
chdir: /root
3 changes: 3 additions & 0 deletions roles/screeps-statsd/templates/docker-compose.env.j2
@@ -0,0 +1,3 @@
SCREEPS_USERNAME={{ screeps_username }}
SCREEPS_EMAIL={{ screeps_email }}
SCREEPS_PASSWORD={{ screeps_password }}
16 changes: 16 additions & 0 deletions setup.sh
@@ -0,0 +1,16 @@
#!/bin/bash
echo Starting containers...
docker-compose up -d
echo Waiting for grafana to start...
do
sleep 1
curl -X HEAD http://localhost:1337
while [[ $? != 0 ]]
echo Configuring Datasource...
curl -s 'http://admin:admin@localhost:1337/api/datasources' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data-binary '{"name":"localGraphite","type":"graphite","url":"http://graphite:8000","access":"proxy","isDefault":true,"database":""}' > /dev/null
sleep 2
echo Installing Sample...
curl -s 'http://admin:admin@localhost:1337/api/dashboards/db' -X POST -H 'Content-Type: application/json;charset=UTF-8' --data @sampleDashboard.json > /dev/null
echo All done!
echo You should be able connect to http://localhost:1337
echo with username \'admin\' and password \'admin\'

0 comments on commit ffd20d1

Please sign in to comment.