From 12f4aca8db2a2adea3ca3cb18185a8d0b369ce6a Mon Sep 17 00:00:00 2001 From: Kambiz Aghaiepour Date: Sat, 5 Mar 2016 20:51:27 -0500 Subject: [PATCH] ansible deployment for graphite and grafana * ensure you define [graphite] and [grafana] in your hosts file. * The grafana service is lightweight and can live on the same host as the graphite host. However, it can also be separated to run on its own server if desired. * Once the graphite-web services are deployed (which also sets up the carbon-cache service), and the grafana service is deployed, you will need to define the data source for your graphite host in the grafana instance. * The grafana service runs on port 3000, and has the default user/pass of admin/admin. * username / password for graphite is set in install/group_vars/all * firewalld is disabled on the grafana and graphite hosts If firewalls are needed, iptables-service is suggested but left us to deployment team. * Added gen_hostfile.sh updates for the needed hosts entries, with comments to the user on what needs to be in 'hosts' file. graphite db sets up Change-Id: I27660b6ecbf019699c124b02b4b4fd6185547a54 --- ansible/README.md | 13 + ansible/gen_hostfile.sh | 13 + ansible/install/grafana.yml | 9 + ansible/install/graphite.yml | 9 + ansible/install/group_vars/all | 4 + ansible/install/roles/grafana/tasks/main.yml | 35 ++ .../install/roles/graphite/files/carbon.conf | 370 ++++++++++++++++++ .../roles/graphite/files/graphite-web.conf | 39 ++ .../graphite/files/setup-graphite-db.exp | 32 ++ .../graphite/files/storage-aggregation.conf | 0 .../roles/graphite/files/storage-schemas.conf | 17 + ansible/install/roles/graphite/tasks/main.yml | 122 ++++++ 12 files changed, 663 insertions(+) create mode 100644 ansible/install/grafana.yml create mode 100644 ansible/install/graphite.yml create mode 100644 ansible/install/roles/grafana/tasks/main.yml create mode 100644 ansible/install/roles/graphite/files/carbon.conf create mode 100644 ansible/install/roles/graphite/files/graphite-web.conf create mode 100644 ansible/install/roles/graphite/files/setup-graphite-db.exp create mode 100644 ansible/install/roles/graphite/files/storage-aggregation.conf create mode 100644 ansible/install/roles/graphite/files/storage-schemas.conf create mode 100644 ansible/install/roles/graphite/tasks/main.yml diff --git a/ansible/README.md b/ansible/README.md index e0fb4de04..d30101d3f 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -6,6 +6,8 @@ Playbooks for: * Install Browbeat * Install collectd * Install connmon +* Install graphite service +* Install grafana service * Install grafana dashboards * Install shaker * Check overcloud for performance issues @@ -50,6 +52,17 @@ Install Connmon # ansible-playbook -i hosts install/connmon.yml ``` +Install graphite service +``` +# ansible-playbook -i hosts install/graphite.yml +``` + +Install grafana service +* Default user is admin/admin and the graphite data source will need to be defined. +``` +# ansible-playbook -i hosts install/grafana.yml +``` + Install Grafana Dashboards (Requires a Grafana Server) * Review install/group_vars/all before deploying the grafana dashboards ``` diff --git a/ansible/gen_hostfile.sh b/ansible/gen_hostfile.sh index 5a36bac04..b8df1216e 100755 --- a/ansible/gen_hostfile.sh +++ b/ansible/gen_hostfile.sh @@ -114,6 +114,19 @@ if [[ ${#ceph_hn} -gt 0 ]]; then echo "${ceph}" | tee -a ${ansible_inventory_file} done fi +echo "" | tee -a ${ansible_inventory_file} +echo "[graphite]" | tee -a ${ansible_inventory_file} +echo "## example host entry." | tee -a ${ansible_inventory_file} +echo "#host-01" | tee -a ${ansible_inventory_file} +echo "" | tee -a ${ansible_inventory_file} +echo "[grafana]" | tee -a ${ansible_inventory_file} +echo "## example host entry." | tee -a ${ansible_inventory_file} +echo "#host-02" | tee -a ${ansible_inventory_file} + +echo "---------------------------" +echo "IMPORTANT: If you plan on deploying graphite and grafana, update hosts and make sure" +echo " the [graphite] and [grafana] hosts entries are updated with valid hosts." +echo " You will need to have passwordless access to root on these hosts." echo "---------------------------" # Before referencing a host in ~/.ssh/config, ensure correct permissions on ssh config file diff --git a/ansible/install/grafana.yml b/ansible/install/grafana.yml new file mode 100644 index 000000000..b56039101 --- /dev/null +++ b/ansible/install/grafana.yml @@ -0,0 +1,9 @@ +--- +# +# Playbook to install grafana +# + +- hosts: grafana + remote_user: root + roles: + - { role: grafana } diff --git a/ansible/install/graphite.yml b/ansible/install/graphite.yml new file mode 100644 index 000000000..c2ae35ab4 --- /dev/null +++ b/ansible/install/graphite.yml @@ -0,0 +1,9 @@ +--- +# +# Playbook to install graphite-web +# + +- hosts: graphite + remote_user: root + roles: + - { role: graphite } diff --git a/ansible/install/group_vars/all b/ansible/install/group_vars/all index 1a1ea738e..76cd9703a 100644 --- a/ansible/install/group_vars/all +++ b/ansible/install/group_vars/all @@ -30,6 +30,10 @@ grafana_api_key: (Your Grafana API Key) # Grafana Server IP Address (Can be hosted on the Graphite server) grafana_host: 1.1.1.1 +# Graphite username and password for login on the dashboard +graphite_username: root +graphite_password: calvin + # Dashboards - Batch number of hosts per row for all-{cpu, memory, disk, network} dashboards dashboards_batch: 20 diff --git a/ansible/install/roles/grafana/tasks/main.yml b/ansible/install/roles/grafana/tasks/main.yml new file mode 100644 index 000000000..694ea4892 --- /dev/null +++ b/ansible/install/roles/grafana/tasks/main.yml @@ -0,0 +1,35 @@ +--- +# +# Install/run grafana-server for browbeat +# + +- name: Check for epel + shell: rpm -qa | grep -q epel-release + ignore_errors: true + register: epel_installed + +- name: Install epel repo + command: rpm -ivh {{ epel_repo }} + become: true + when: epel_installed.rc != 0 + +- name: Install grafana rpms + yum: name={{ item }} state=present + become: true + with_items: + - https://grafanarel.s3.amazonaws.com/builds/grafana-2.6.0-1.x86_64.rpm + +# disable firewalld (might need to create specific firewall rules or leave it to admin to do via iptables) + +- name: disable firewalld + service: name=firewalld state=stopped enabled=false + become: true + +# +# setup the grafana-server service +# + +- name: Setup grafana-server service + service: name=grafana-server state=started enabled=true + become: true + diff --git a/ansible/install/roles/graphite/files/carbon.conf b/ansible/install/roles/graphite/files/carbon.conf new file mode 100644 index 000000000..3d38902df --- /dev/null +++ b/ansible/install/roles/graphite/files/carbon.conf @@ -0,0 +1,370 @@ +[cache] +# Configure carbon directories. +# +# OS environment variables can be used to tell carbon where graphite is +# installed, where to read configuration from and where to write data. +# +# GRAPHITE_ROOT - Root directory of the graphite installation. +# Defaults to ../ +# GRAPHITE_CONF_DIR - Configuration directory (where this file lives). +# Defaults to $GRAPHITE_ROOT/conf/ +# GRAPHITE_STORAGE_DIR - Storage directory for whipser/rrd/log/pid files. +# Defaults to $GRAPHITE_ROOT/storage/ +# +# To change other directory paths, add settings to this file. The following +# configuration variables are available with these default values: +# +# STORAGE_DIR = $GRAPHITE_STORAGE_DIR +# LOCAL_DATA_DIR = STORAGE_DIR/whisper/ +# WHITELISTS_DIR = STORAGE_DIR/lists/ +# CONF_DIR = STORAGE_DIR/conf/ +# LOG_DIR = STORAGE_DIR/log/ +# PID_DIR = STORAGE_DIR/ +# +# For FHS style directory structures, use: +# +# STORAGE_DIR = /var/lib/carbon/ +# CONF_DIR = /etc/carbon/ +# LOG_DIR = /var/log/carbon/ +# PID_DIR = /var/run/ +# +#LOCAL_DATA_DIR = /opt/graphite/storage/whisper/ + +STORAGE_DIR = /var/lib/carbon/ +LOCAL_DATA_DIR = /var/lib/carbon/whisper/ +WHITELISTS_DIR = /var/lib/carbon/lists/ +CONF_DIR = /etc/carbon/ +LOG_DIR = /var/log/carbon/ +PID_DIR = /var/run/ + +# Enable daily log rotation. If disabled, a kill -HUP can be used after a manual rotate + +ENABLE_LOGROTATION = True + +# Specify the user to drop privileges to +# If this is blank carbon runs as the user that invokes it +# This user must have write access to the local data directory +USER = carbon + +# +# NOTE: The above settings must be set under [relay] and [aggregator] +# to take effect for those daemons as well + +# Limit the size of the cache to avoid swapping or becoming CPU bound. +# Sorts and serving cache queries gets more expensive as the cache grows. +# Use the value "inf" (infinity) for an unlimited cache size. +MAX_CACHE_SIZE = inf + +# Limits the number of whisper update_many() calls per second, which effectively +# means the number of write requests sent to the disk. This is intended to +# prevent over-utilizing the disk and thus starving the rest of the system. +# When the rate of required updates exceeds this, then carbon's caching will +# take effect and increase the overall throughput accordingly. +MAX_UPDATES_PER_SECOND = 2000 + +# If defined, this changes the MAX_UPDATES_PER_SECOND in Carbon when a +# stop/shutdown is initiated. This helps when MAX_UPDATES_PER_SECOND is +# relatively low and carbon has cached a lot of updates; it enables the carbon +# daemon to shutdown more quickly. +# MAX_UPDATES_PER_SECOND_ON_SHUTDOWN = 1000 + +# Softly limits the number of whisper files that get created each minute. +# Setting this value low (like at 50) is a good way to ensure your graphite +# system will not be adversely impacted when a bunch of new metrics are +# sent to it. The trade off is that it will take much longer for those metrics' +# database files to all get created and thus longer until the data becomes usable. +# Setting this value high (like "inf" for infinity) will cause graphite to create +# the files quickly but at the risk of slowing I/O down considerably for a while. +MAX_CREATES_PER_MINUTE = 200 + +LINE_RECEIVER_INTERFACE = 0.0.0.0 +LINE_RECEIVER_PORT = 2003 + +# Set this to True to enable the UDP listener. By default this is off +# because it is very common to run multiple carbon daemons and managing +# another (rarely used) port for every carbon instance is not fun. +ENABLE_UDP_LISTENER = False +UDP_RECEIVER_INTERFACE = 0.0.0.0 +UDP_RECEIVER_PORT = 2003 + +PICKLE_RECEIVER_INTERFACE = 0.0.0.0 +PICKLE_RECEIVER_PORT = 2004 + +# Set to false to disable logging of successful connections +LOG_LISTENER_CONNECTIONS = True + +# Per security concerns outlined in Bug #817247 the pickle receiver +# will use a more secure and slightly less efficient unpickler. +# Set this to True to revert to the old-fashioned insecure unpickler. +USE_INSECURE_UNPICKLER = False + +CACHE_QUERY_INTERFACE = 0.0.0.0 +CACHE_QUERY_PORT = 7002 + +# Set this to False to drop datapoints received after the cache +# reaches MAX_CACHE_SIZE. If this is True (the default) then sockets +# over which metrics are received will temporarily stop accepting +# data until the cache size falls below 95% MAX_CACHE_SIZE. +USE_FLOW_CONTROL = True + +# By default, carbon-cache will log every whisper update and cache hit. This can be excessive and +# degrade performance if logging on the same volume as the whisper data is stored. +LOG_UPDATES = False +LOG_CACHE_HITS = False +LOG_CACHE_QUEUE_SORTS = True + +# The thread that writes metrics to disk can use on of the following strategies +# determining the order in which metrics are removed from cache and flushed to +# disk. The default option preserves the same behavior as has been historically +# available in version 0.9.10. +# +# sorted - All metrics in the cache will be counted and an ordered list of +# them will be sorted according to the number of datapoints in the cache at the +# moment of the list's creation. Metrics will then be flushed from the cache to +# disk in that order. +# +# max - The writer thread will always pop and flush the metric from cache +# that has the most datapoints. This will give a strong flush preference to +# frequently updated metrics and will also reduce random file-io. Infrequently +# updated metrics may only ever be persisted to disk at daemon shutdown if +# there are a large number of metrics which receive very frequent updates OR if +# disk i/o is very slow. +# +# naive - Metrics will be flushed from the cache to disk in an unordered +# fashion. This strategy may be desirable in situations where the storage for +# whisper files is solid state, CPU resources are very limited or deference to +# the OS's i/o scheduler is expected to compensate for the random write +# pattern. +# +CACHE_WRITE_STRATEGY = sorted + +# On some systems it is desirable for whisper to write synchronously. +# Set this option to True if you'd like to try this. Basically it will +# shift the onus of buffering writes from the kernel into carbon's cache. +WHISPER_AUTOFLUSH = False + +# By default new Whisper files are created pre-allocated with the data region +# filled with zeros to prevent fragmentation and speed up contiguous reads and +# writes (which are common). Enabling this option will cause Whisper to create +# the file sparsely instead. Enabling this option may allow a large increase of +# MAX_CREATES_PER_MINUTE but may have longer term performance implications +# depending on the underlying storage configuration. +# WHISPER_SPARSE_CREATE = False + +# Only beneficial on linux filesystems that support the fallocate system call. +# It maintains the benefits of contiguous reads/writes, but with a potentially +# much faster creation speed, by allowing the kernel to handle the block +# allocation and zero-ing. Enabling this option may allow a large increase of +# MAX_CREATES_PER_MINUTE. If enabled on an OS or filesystem that is unsupported +# this option will gracefully fallback to standard POSIX file access methods. +WHISPER_FALLOCATE_CREATE = True + +# Enabling this option will cause Whisper to lock each Whisper file it writes +# to with an exclusive lock (LOCK_EX, see: man 2 flock). This is useful when +# multiple carbon-cache daemons are writing to the same files +# WHISPER_LOCK_WRITES = False + +# Set this to True to enable whitelisting and blacklisting of metrics in +# CONF_DIR/whitelist and CONF_DIR/blacklist. If the whitelist is missing or +# empty, all metrics will pass through +# USE_WHITELIST = False + +# By default, carbon itself will log statistics (such as a count, +# metricsReceived) with the top level prefix of 'carbon' at an interval of 60 +# seconds. Set CARBON_METRIC_INTERVAL to 0 to disable instrumentation +# CARBON_METRIC_PREFIX = carbon +# CARBON_METRIC_INTERVAL = 60 + +# Enable AMQP if you want to receve metrics using an amqp broker +# ENABLE_AMQP = False + +# Verbose means a line will be logged for every metric received +# useful for testing +# AMQP_VERBOSE = False + +# AMQP_HOST = localhost +# AMQP_PORT = 5672 +# AMQP_VHOST = / +# AMQP_USER = guest +# AMQP_PASSWORD = guest +# AMQP_EXCHANGE = graphite +# AMQP_METRIC_NAME_IN_BODY = False + +# The manhole interface allows you to SSH into the carbon daemon +# and get a python interpreter. BE CAREFUL WITH THIS! If you do +# something like time.sleep() in the interpreter, the whole process +# will sleep! This is *extremely* helpful in debugging, assuming +# you are familiar with the code. If you are not, please don't +# mess with this, you are asking for trouble :) +# +# ENABLE_MANHOLE = False +# MANHOLE_INTERFACE = 127.0.0.1 +# MANHOLE_PORT = 7222 +# MANHOLE_USER = admin +# MANHOLE_PUBLIC_KEY = ssh-rsa AAAAB3NzaC1yc2EAAAABiwAaAIEAoxN0sv/e4eZCPpi3N3KYvyzRaBaMeS2RsOQ/cDuKv11dlNzVeiyc3RFmCv5Rjwn/lQ79y0zyHxw67qLyhQ/kDzINc4cY41ivuQXm2tPmgvexdrBv5nsfEpjs3gLZfJnyvlcVyWK/lId8WUvEWSWHTzsbtmXAF2raJMdgLTbQ8wE= + +# Patterns for all of the metrics this machine will store. Read more at +# http://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol#Bindings +# +# Example: store all sales, linux servers, and utilization metrics +# BIND_PATTERNS = sales.#, servers.linux.#, #.utilization +# +# Example: store everything +# BIND_PATTERNS = # + +# To configure special settings for the carbon-cache instance 'b', uncomment this: +#[cache:b] +#LINE_RECEIVER_PORT = 2103 +#PICKLE_RECEIVER_PORT = 2104 +#CACHE_QUERY_PORT = 7102 +# and any other settings you want to customize, defaults are inherited +# from [carbon] section. +# You can then specify the --instance=b option to manage this instance + + + +[relay] +USER = carbon +LINE_RECEIVER_INTERFACE = 0.0.0.0 +LINE_RECEIVER_PORT = 2013 +PICKLE_RECEIVER_INTERFACE = 0.0.0.0 +PICKLE_RECEIVER_PORT = 2014 + +# Set to false to disable logging of successful connections +LOG_LISTENER_CONNECTIONS = True + +# Carbon-relay has several options for metric routing controlled by RELAY_METHOD +# +# Use relay-rules.conf to route metrics to destinations based on pattern rules +#RELAY_METHOD = rules +# +# Use consistent-hashing for even distribution of metrics between destinations +#RELAY_METHOD = consistent-hashing +# +# Use consistent-hashing but take into account an aggregation-rules.conf shared +# by downstream carbon-aggregator daemons. This will ensure that all metrics +# that map to a given aggregation rule are sent to the same carbon-aggregator +# instance. +# Enable this for carbon-relays that send to a group of carbon-aggregators +#RELAY_METHOD = aggregated-consistent-hashing +RELAY_METHOD = rules + +# If you use consistent-hashing you can add redundancy by replicating every +# datapoint to more than one machine. +REPLICATION_FACTOR = 1 + +# This is a list of carbon daemons we will send any relayed or +# generated metrics to. The default provided would send to a single +# carbon-cache instance on the default port. However if you +# use multiple carbon-cache instances then it would look like this: +# +# DESTINATIONS = 127.0.0.1:2004:a, 127.0.0.1:2104:b +# +# The general form is IP:PORT:INSTANCE where the :INSTANCE part is +# optional and refers to the "None" instance if omitted. +# +# Note that if the destinations are all carbon-caches then this should +# exactly match the webapp's CARBONLINK_HOSTS setting in terms of +# instances listed (order matters!). +# +# If using RELAY_METHOD = rules, all destinations used in relay-rules.conf +# must be defined in this list +DESTINATIONS = 127.0.0.1:2004 + +# This defines the maximum "message size" between carbon daemons. +# You shouldn't need to tune this unless you really know what you're doing. +MAX_DATAPOINTS_PER_MESSAGE = 2000 +MAX_QUEUE_SIZE = 400000 + +# Set this to False to drop datapoints when any send queue (sending datapoints +# to a downstream carbon daemon) hits MAX_QUEUE_SIZE. If this is True (the +# default) then sockets over which metrics are received will temporarily stop accepting +# data until the send queues fall below 80% MAX_QUEUE_SIZE. +USE_FLOW_CONTROL = True + +# Set this to True to enable whitelisting and blacklisting of metrics in +# CONF_DIR/whitelist and CONF_DIR/blacklist. If the whitelist is missing or +# empty, all metrics will pass through +# USE_WHITELIST = False + +# By default, carbon itself will log statistics (such as a count, +# metricsReceived) with the top level prefix of 'carbon' at an interval of 60 +# seconds. Set CARBON_METRIC_INTERVAL to 0 to disable instrumentation +# CARBON_METRIC_PREFIX = carbon +# CARBON_METRIC_INTERVAL = 60 + + +[aggregator] +USER = carbon +LINE_RECEIVER_INTERFACE = 0.0.0.0 +LINE_RECEIVER_PORT = 2023 + +PICKLE_RECEIVER_INTERFACE = 0.0.0.0 +PICKLE_RECEIVER_PORT = 2024 + +# Set to false to disable logging of successful connections +LOG_LISTENER_CONNECTIONS = True + +# If set true, metric received will be forwarded to DESTINATIONS in addition to +# the output of the aggregation rules. If set false the carbon-aggregator will +# only ever send the output of aggregation. +FORWARD_ALL = True + +# This is a list of carbon daemons we will send any relayed or +# generated metrics to. The default provided would send to a single +# carbon-cache instance on the default port. However if you +# use multiple carbon-cache instances then it would look like this: +# +# DESTINATIONS = 127.0.0.1:2004:a, 127.0.0.1:2104:b +# +# The format is comma-delimited IP:PORT:INSTANCE where the :INSTANCE part is +# optional and refers to the "None" instance if omitted. +# +# Note that if the destinations are all carbon-caches then this should +# exactly match the webapp's CARBONLINK_HOSTS setting in terms of +# instances listed (order matters!). +DESTINATIONS = 127.0.0.1:2004 + +# If you want to add redundancy to your data by replicating every +# datapoint to more than one machine, increase this. +REPLICATION_FACTOR = 1 + +# This is the maximum number of datapoints that can be queued up +# for a single destination. Once this limit is hit, we will +# stop accepting new data if USE_FLOW_CONTROL is True, otherwise +# we will drop any subsequently received datapoints. +MAX_QUEUE_SIZE = 10000 + +# Set this to False to drop datapoints when any send queue (sending datapoints +# to a downstream carbon daemon) hits MAX_QUEUE_SIZE. If this is True (the +# default) then sockets over which metrics are received will temporarily stop accepting +# data until the send queues fall below 80% MAX_QUEUE_SIZE. +USE_FLOW_CONTROL = True + +# This defines the maximum "message size" between carbon daemons. +# You shouldn't need to tune this unless you really know what you're doing. +MAX_DATAPOINTS_PER_MESSAGE = 500 + +# This defines how many datapoints the aggregator remembers for +# each metric. Aggregation only happens for datapoints that fall in +# the past MAX_AGGREGATION_INTERVALS * intervalSize seconds. +MAX_AGGREGATION_INTERVALS = 5 + +# By default (WRITE_BACK_FREQUENCY = 0), carbon-aggregator will write back +# aggregated data points once every rule.frequency seconds, on a per-rule basis. +# Set this (WRITE_BACK_FREQUENCY = N) to write back all aggregated data points +# every N seconds, independent of rule frequency. This is useful, for example, +# to be able to query partially aggregated metrics from carbon-cache without +# having to first wait rule.frequency seconds. +# WRITE_BACK_FREQUENCY = 0 + +# Set this to True to enable whitelisting and blacklisting of metrics in +# CONF_DIR/whitelist and CONF_DIR/blacklist. If the whitelist is missing or +# empty, all metrics will pass through +# USE_WHITELIST = False + +# By default, carbon itself will log statistics (such as a count, +# metricsReceived) with the top level prefix of 'carbon' at an interval of 60 +# seconds. Set CARBON_METRIC_INTERVAL to 0 to disable instrumentation +# CARBON_METRIC_PREFIX = carbon +# CARBON_METRIC_INTERVAL = 60 diff --git a/ansible/install/roles/graphite/files/graphite-web.conf b/ansible/install/roles/graphite/files/graphite-web.conf new file mode 100644 index 000000000..9ddc4f2b5 --- /dev/null +++ b/ansible/install/roles/graphite/files/graphite-web.conf @@ -0,0 +1,39 @@ +# Graphite Web Basic mod_wsgi vhost + + + DocumentRoot "/usr/share/graphite/webapp" + ErrorLog /var/log/httpd/graphite-web-error.log + CustomLog /var/log/httpd/graphite-web-access.log common + + # Header set Access-Control-Allow-Origin "*" + # Header set Access-Control-Allow-Methods "GET, OPTIONS" + # Header set Access-Control-Allow-Headers "origin, authorization, accept" + # Header set Access-Control-Allow-Credentials true + + WSGIScriptAlias / /usr/share/graphite/graphite-web.wsgi + WSGIImportScript /usr/share/graphite/graphite-web.wsgi process-group=%{GLOBAL} application-group=%{GLOBAL} + + + SetHandler None + + + Alias /media/ "/usr/lib/python2.7/site-packages/django/contrib/admin/media/" + + SetHandler None + + + + + # Apache 2.4 + Require all granted + Require local + + + # Apache 2.2 + Order Deny,Allow + Deny from all + Allow from 127.0.0.1 + Allow from ::1 + + + diff --git a/ansible/install/roles/graphite/files/setup-graphite-db.exp b/ansible/install/roles/graphite/files/setup-graphite-db.exp new file mode 100644 index 000000000..bcea30863 --- /dev/null +++ b/ansible/install/roles/graphite/files/setup-graphite-db.exp @@ -0,0 +1,32 @@ +#!/usr/bin/expect +# +# non-interactive setup of the initial graphite.db sqlite3 database +# +# if run manually, the following is the expected output. +# Would you like to create one now? (yes/no): yes +# Username (leave blank to use 'root'): +# Email address: +# Password: +# Password (again): +# Superuser created successfully. +# Installing custom SQL ... +# Installing indexes ... +# Installed 0 object(s) from 0 fixture(s) + +set timeout 20 +set superuser [lindex $argv 0] +set password [lindex $argv 1] +spawn /usr/lib/python2.7/site-packages/graphite/manage.py syncdb +expect "Would you like to create one now? (yes/no):" +send "yes\r"; +expect "Username (leave blank to use 'root'):" +send "$superuser\r"; +expect "Email address:" +send "\r"; +expect "Password:" +send "$password\r"; +expect "Password (again):" +send "$password\r"; + +interact + diff --git a/ansible/install/roles/graphite/files/storage-aggregation.conf b/ansible/install/roles/graphite/files/storage-aggregation.conf new file mode 100644 index 000000000..e69de29bb diff --git a/ansible/install/roles/graphite/files/storage-schemas.conf b/ansible/install/roles/graphite/files/storage-schemas.conf new file mode 100644 index 000000000..6d1ce049f --- /dev/null +++ b/ansible/install/roles/graphite/files/storage-schemas.conf @@ -0,0 +1,17 @@ +# Schema definitions for Whisper files. Entries are scanned in order, +# and first match wins. This file is scanned for changes every 60 seconds. +# +# [name] +# pattern = regex +# retentions = timePerPoint:timeToStore, timePerPoint:timeToStore, ... +# +# Carbon's internal metrics. This entry should match what is specified in +# CARBON_METRIC_PREFIX and CARBON_METRIC_INTERVAL settings +[carbon] +pattern = ^carbon\. +retentions = 60:90d + +[default] +pattern = .* +retentions = 10s:7d,60s:90d,1h:180d + diff --git a/ansible/install/roles/graphite/tasks/main.yml b/ansible/install/roles/graphite/tasks/main.yml new file mode 100644 index 000000000..b6a9689ac --- /dev/null +++ b/ansible/install/roles/graphite/tasks/main.yml @@ -0,0 +1,122 @@ +--- +# +# Install/run graphite-web for browbeat +# + +- name: Check for epel + shell: rpm -qa | grep -q epel-release + ignore_errors: true + register: epel_installed + +- name: Install epel repo + command: rpm -ivh {{ epel_repo }} + become: true + when: epel_installed.rc != 0 + +- name: Install graphite rpms + yum: name={{ item }} state=present + become: true + with_items: + - graphite-web + - python-carbon + - expect + +# moved to grafana specific playbook +# - https://grafanarel.s3.amazonaws.com/builds/grafana-2.6.0-1.x86_64.rpm + +- name: Check for graphite.db sqlite + shell: ls /var/lib/graphite-web/graphite.db + ignore_errors: true + register: graphite_db_installed + +- name: Copy setup-graphite-db.exp + copy: + src=setup-graphite-db.exp + dest=/root/setup-graphite-db.exp + owner=root + group=root + mode=0755 + become: true + +- name: Create initial graphite db + shell: /root/setup-graphite-db.exp {{ graphite_username }} {{ graphite_password }} && chown apache:apache /var/lib/graphite-web/graphite.db + become: true + when: graphite_db_installed.rc != 0 + register: apache_needs_restart + +- name: copy httpd graphite-web config + copy: + src=graphite-web.conf + dest=/etc/httpd/conf.d/graphite-web.conf + owner=root + group=root + mode=0644 + become: true + register: apache_needs_restart + + +# Start graphite-web service + +- name: Setup httpd service + service: name=httpd state=started enabled=true + become: true + +# disable firewalld (might need to create specific firewall rules or leave it to admin to do via iptables) + +- name: disable firewalld + service: name=firewalld state=stopped enabled=false + become: true + +# remove silly welcome from apache (if it exists) +- name: Remove httpd welcome config + become: true + file: path=/etc/httpd/conf.d/welcome.conf state=absent + register: apache_needs_restart + +- name: Bounce Apache + service: name=httpd state=restarted enabled=true + become: true + when: apache_needs_restart.changed + +# +# setup the python-carbon service +# + +- name: Setup carbon-cache service + service: name=carbon-cache state=started enabled=true + become: true + +- name: copy carbon storage schema config + copy: + src=storage-schemas.conf + dest=/etc/carbon/storage-schemas.conf + owner=root + group=root + mode=0644 + become: true + register: carbon_cache_needs_restart + +- name: copy carbon storage aggregation config + copy: + src=storage-aggregation.conf + dest=/etc/carbon/storage-aggregation.conf + owner=root + group=root + mode=0644 + become: true + register: carbon_cache_needs_restart + +- name: copy carbon config + copy: + src=carbon.conf + dest=/etc/carbon/carbon.conf + owner=root + group=root + mode=0644 + become: true + register: carbon_cache_needs_restart + +- name: bounce carbon cache + service: name=carbon-cache state=restarted enabled=true + become: true + when: carbon_cache_needs_restart.changed