Last active
August 29, 2015 14:09
-
-
Save wolfdancer/898a217126aa3644e266 to your computer and use it in GitHub Desktop.
heat-grafana-cloudmetrics.yaml
This file contains 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
heat_template_version: 2013-05-23 | |
description: > | |
Puts together a server that will run Grafana using Cloud Metrics data. | |
parameter_groups: | |
- label: 'Server Settings' | |
parameters: | |
- flavor | |
- image | |
- host_name | |
- es_version | |
- gr_version | |
- rax_tenant | |
- rax_username | |
- rax_apikey | |
- label: 'Apache Settings' | |
parameters: | |
- apache_auth_user | |
parameters: | |
image: | |
default: 'Ubuntu 14.04 LTS (Trusty Tahr)' | |
label: 'Operating System' | |
type: string | |
description: 'Server image that will be used' | |
constraints: | |
- description: 'supported os versions' | |
allowed_values: | |
- 'Ubuntu 12.04 LTS (Precise Pangolin)' | |
- 'Ubuntu 14.04 LTS (Trusty Tahr)' | |
flavor: | |
default: '2GB Standard Instance' | |
label: 'Server Size' | |
type: string | |
description: 'Cloud Server flavor (size) to use' | |
constraints: | |
- description: 'supported server sizes. should have at least 2G RAM' | |
allowed_values: | |
- '2 GB Performance' | |
- '4 GB Performance' | |
- '8 GB Performance' | |
- '15 GB Performance' | |
- '30 GB Performance' | |
- '2GB Standard Instance' | |
- '4GB Standard Instance' | |
- '8GB Standard Instance' | |
- '15GB Standard Instance' | |
- '30GB Standard Instance' | |
host_name: | |
default: grafana | |
type: string | |
description: 'Server hostname' | |
label: 'Server hostname' | |
apache_auth_user: | |
default: grafana | |
type: string | |
description: 'User name used to authenticate into Apache (which serves Grafana).' | |
label: 'Username' | |
es_version: | |
default: '1.3.4' | |
type: string | |
description: 'Elasticsearch version' | |
label: 'Elasticsearch version' | |
gr_version: | |
default: '1.8.1' | |
type: string | |
description: 'Grafana version' | |
label: 'Grafana version' | |
rax_tenant: | |
default: 'notavalidtenantdkw93ddkwl' | |
type: string | |
description: 'Rackspace tenant ID' | |
label: 'tenant ID' | |
rax_username: | |
default: 'notavaliduserskldk2e' | |
type: string | |
description: 'Rackspace user name' | |
label: 'username' | |
rax_apikey: | |
default: 'notavalidapikeykslkdjlkj2' | |
type: string | |
description: 'Rackspace account API key' | |
label: 'API key' | |
outputs: | |
private_key: | |
description: 'SSH private key' | |
value: { get_attr: [ssh_key, private_key ] } | |
apache_auth_user: | |
description: 'Grafana auth user.' | |
value: | |
get_param: apache_auth_user | |
apache_auth_password: | |
description: 'Grafana auth password.' | |
value: { get_attr: [apache_auth_password, value ] } | |
public_ip: | |
description: IP Address | |
value: { get_attr: [cloud_server, accessIPv4] } | |
resources: | |
cloud_server: | |
type: 'Rackspace::Cloud::Server' | |
depends_on: [ apache_auth_password ] | |
properties: | |
key_name: { get_resource: ssh_key } | |
flavor: { get_param: flavor } | |
name: { get_param: [host_name, value] } | |
image: { get_param: image } | |
user_data_format: RAW | |
config_drive: true | |
user_data: | |
str_replace: | |
template: | | |
#!/bin/bash -x | |
exec 2>&1 | |
exec 1>/tmp/bash-debug.log | |
ps auxwwef | |
sleep 60 | |
echo after sleep | |
ps auxwwef | |
export DEBIAN_FRONTEND=noninteractive | |
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections | |
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections | |
add-apt-repository -y ppa:webupd8team/java | |
apt-get update -y --force-yes | |
sleep 5 | |
echo installing packages now, one at a time. | |
for i in wget oracle-java7-installer vim git nginx nginx-extras apache2-utils python-dev python-setuptools python-pip build-essential libcairo2-dev libffi-dev python-virtualenv python-dateutil ; do | |
echo installing "$i" | |
apt-get install -y $i --force-yes 2>&1 | tee /tmp/$i.install.log | |
done | |
curl -o /tmp/elasticsearch-es_version.deb https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-es_version.deb | |
dpkg -i /tmp/elasticsearch-es_version.deb | |
update-rc.d elasticsearch defaults 95 10 | |
mv /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch-default.yml | |
echo cluster.name: es_grafana > /etc/elasticsearch/elasticsearch.yml | |
echo network.host: 127.0.0.1 >> /etc/elasticsearch/elasticsearch.yml | |
/etc/init.d/elasticsearch start | |
htpasswd -b -c /etc/nginx/.htpasswd apache_auth_user apache_auth_password | |
curl -o /tmp/grafana-gr_version.tar.gz http://grafanarel.s3.amazonaws.com/grafana-gr_version.tar.gz | |
tar -xzf /tmp/grafana-gr_version.tar.gz -C /usr/share/nginx/ | |
ln -s /usr/share/nginx/grafana-gr_version /usr/share/nginx/grafana | |
chown -R root:root /usr/share/nginx/grafana-gr_version | |
rm /etc/nginx/sites-enabled/default | |
echo "upstream graphite { " >> /etc/nginx/sites-available/grafana | |
echo " server 127.0.0.1:8888; " >> /etc/nginx/sites-available/grafana | |
echo "} " >> /etc/nginx/sites-available/grafana | |
echo "upstream elasticsearch { " >> /etc/nginx/sites-available/grafana | |
echo " server 127.0.0.1:9200; " >> /etc/nginx/sites-available/grafana | |
echo "} " >> /etc/nginx/sites-available/grafana | |
echo "server { " >> /etc/nginx/sites-available/grafana | |
echo " listen 80; " >> /etc/nginx/sites-available/grafana | |
echo " auth_basic 'Restricted'; " >> /etc/nginx/sites-available/grafana | |
echo " auth_basic_user_file /etc/nginx/.htpasswd; " >> /etc/nginx/sites-available/grafana | |
echo " location /graphite/ { " >> /etc/nginx/sites-available/grafana | |
echo " rewrite /graphite/(.*) /\$1 break; " >> /etc/nginx/sites-available/grafana | |
echo " proxy_pass http://graphite; " >> /etc/nginx/sites-available/grafana | |
echo " proxy_redirect off; " >> /etc/nginx/sites-available/grafana | |
echo " proxy_set_header Host \$host; " >> /etc/nginx/sites-available/grafana | |
echo " } " >> /etc/nginx/sites-available/grafana | |
echo " location /elasticsearch/ { " >> /etc/nginx/sites-available/grafana | |
echo " rewrite /elasticsearch/(.*) /\$1 break; " >> /etc/nginx/sites-available/grafana | |
echo " proxy_pass http://elasticsearch; " >> /etc/nginx/sites-available/grafana | |
echo " proxy_redirect off; " >> /etc/nginx/sites-available/grafana | |
echo " proxy_set_header Host \$host; " >> /etc/nginx/sites-available/grafana | |
echo " } " >> /etc/nginx/sites-available/grafana | |
echo " location / { " >> /etc/nginx/sites-available/grafana | |
echo " root /usr/share/nginx/grafana; " >> /etc/nginx/sites-available/grafana | |
echo " } " >> /etc/nginx/sites-available/grafana | |
echo "} " >> /etc/nginx/sites-available/grafana | |
ln -s /etc/nginx/sites-available/grafana /etc/nginx/sites-enabled/grafana | |
/etc/init.d/nginx restart | |
pip install graphite-api gunicorn | |
git -C /tmp clone https://github.com/gdusbabek/blueflood.git | |
git -C /tmp/blueflood checkout graphite_compat | |
cd /tmp/blueflood/contrib/graphite | |
python setup.py install | |
echo "search_index: /dev/null " >> /etc/graphite-api.yaml | |
echo "finders: " >> /etc/graphite-api.yaml | |
echo " - blueflood.TenantBluefloodFinder " >> /etc/graphite-api.yaml | |
echo "functions: " >> /etc/graphite-api.yaml | |
echo " - graphite_api.functions.SeriesFunctions " >> /etc/graphite-api.yaml | |
echo " - graphite_api.functions.PieFunctions " >> /etc/graphite-api.yaml | |
echo "time_zone: UTC " >> /etc/graphite-api.yaml | |
echo "blueflood: " >> /etc/graphite-api.yaml | |
echo " tenant: rax_tenant " >> /etc/graphite-api.yaml | |
echo " username: rax_username " >> /etc/graphite-api.yaml | |
echo " apikey: rax_apikey " >> /etc/graphite-api.yaml | |
echo " urls: " >> /etc/graphite-api.yaml | |
echo " - http://iad.metrics.api.rackspacecloud.com " >> /etc/graphite-api.yaml | |
echo "define(['settings'], " >> /usr/share/nginx/grafana/config.js | |
echo "function (Settings) { " >> /usr/share/nginx/grafana/config.js | |
echo " return new Settings({ " >> /usr/share/nginx/grafana/config.js | |
echo " datasources: { " >> /usr/share/nginx/grafana/config.js | |
echo " graphite: { " >> /usr/share/nginx/grafana/config.js | |
echo " type: 'graphite', " >> /usr/share/nginx/grafana/config.js | |
echo " url: 'http://'+window.location.hostname+'/graphite', " >> /usr/share/nginx/grafana/config.js | |
echo " }, " >> /usr/share/nginx/grafana/config.js | |
echo " elasticsearch: { " >> /usr/share/nginx/grafana/config.js | |
echo " type: 'elasticsearch', " >> /usr/share/nginx/grafana/config.js | |
echo " url: 'http://'+window.location.hostname+'/elasticsearch', " >> /usr/share/nginx/grafana/config.js | |
echo " index: 'grafana-dash', " >> /usr/share/nginx/grafana/config.js | |
echo " grafanaDB: true, " >> /usr/share/nginx/grafana/config.js | |
echo " } " >> /usr/share/nginx/grafana/config.js | |
echo " }, " >> /usr/share/nginx/grafana/config.js | |
echo " search: { " >> /usr/share/nginx/grafana/config.js | |
echo " max_results: 20 " >> /usr/share/nginx/grafana/config.js | |
echo " }, " >> /usr/share/nginx/grafana/config.js | |
echo " default_route: '/dashboard/file/default.json', " >> /usr/share/nginx/grafana/config.js | |
echo " unsaved_changes_warning: true, " >> /usr/share/nginx/grafana/config.js | |
echo " playlist_timespan: '1m', " >> /usr/share/nginx/grafana/config.js | |
echo " admin: { " >> /usr/share/nginx/grafana/config.js | |
echo " password: '' " >> /usr/share/nginx/grafana/config.js | |
echo " }, " >> /usr/share/nginx/grafana/config.js | |
echo " plugins: { " >> /usr/share/nginx/grafana/config.js | |
echo " panels: [] " >> /usr/share/nginx/grafana/config.js | |
echo " } " >> /usr/share/nginx/grafana/config.js | |
echo " }); " >> /usr/share/nginx/grafana/config.js | |
echo "}); " >> /usr/share/nginx/grafana/config.js | |
echo rax_tenant > ~/tenant_id | |
echo "description \"Graphite-API server\" " >> /etc/init/graphite-api.conf | |
echo "start on runlevel [2345] " >> /etc/init/graphite-api.conf | |
echo "stop on runlevel [!2345] " >> /etc/init/graphite-api.conf | |
echo "console log " >> /etc/init/graphite-api.conf | |
echo "respawn " >> /etc/init/graphite-api.conf | |
echo "exec gunicorn -b 127.0.0.1:8888 -w 4 graphite_api.app:app " >> /etc/init/graphite-api.conf | |
start graphite-api | |
params: | |
es_version: { get_param: es_version } | |
gr_version: { get_param: gr_version } | |
apache_auth_user: { get_param: apache_auth_user } | |
apache_auth_password: { get_attr: [apache_auth_password, value ] } | |
rax_tenant: { get_param: rax_tenant } | |
rax_username: { get_param: rax_username } | |
rax_apikey: { get_param: rax_apikey } | |
ssh_key: | |
type: 'OS::Nova::KeyPair' | |
properties: | |
name: | |
get_param: 'OS::stack_id' | |
save_private_key: true | |
apache_auth_password: | |
type: 'OS::Heat::RandomString' | |
properties: | |
length: 16 | |
sequence: lettersdigits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment