Skip to content
This repository was archived by the owner on Jan 8, 2019. It is now read-only.

Commit 835ba65

Browse files
authored
Merge pull request #1258 from leochen4891/graphite_set_variables_in_recipe
set the variables in recipe
2 parents 402b01f + 742975f commit 835ba65

File tree

4 files changed

+48
-34
lines changed

4 files changed

+48
-34
lines changed

cookbooks/bcpc/recipes/graphite.rb

+22-8
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,24 @@
124124
end
125125
end
126126

127-
use_whitelist_str = node['bcpc']['graphite']['use_whitelist'] ? 'True' : 'False'
128-
129127
template '/opt/graphite/conf/carbon.conf' do
130128
source 'carbon/carbon.conf.erb'
131129
owner 'root'
132130
group 'root'
133131
mode 0o0644
134132
variables(
135-
'servers' => get_static_head_node_local_ip_list,
133+
'local_data_dir' => node['bcpc']['graphite']['local_data_dir'],
134+
'log_dir' => node['bcpc']['graphite']['local_log_dir'],
135+
'relay_recv_nic' => node[:bcpc][:graphite][:ip],
136+
'relay_idle_timeout' => node[:bcpc][:graphite][:carbon][:relay][:idle_timeout],
137+
'relay_dests' => get_static_head_node_local_ip_list.map { |host| host + ':2024' }.sort.join(','),
138+
'aggr_recv_nic' => node[:bcpc][:floating][:ip],
139+
'aggr_dests' => node[:bcpc][:floating][:ip] + ':2004',
140+
'cache_recv_nic' => node[:bcpc][:floating][:ip],
141+
'cache_query_nic' => node[:bcpc][:floating][:ip],
142+
'cache_max_updates_per_sec' => node['bcpc']['graphite']['carbon']['cache']['MAX_UPDATES_PER_SECOND'],
136143
'min_quorum' => get_static_head_nodes_count / 2 + 1,
137-
'use_whitelist' => use_whitelist_str
144+
'use_whitelist' => node['bcpc']['graphite']['use_whitelist'] ? 'True' : 'False'
138145
)
139146
notifies :restart, 'service[carbon-cache]', :delayed
140147
notifies :restart, 'service[carbon-aggregator]', :delayed
@@ -162,7 +169,7 @@
162169
owner 'root'
163170
group 'root'
164171
mode 0o0644
165-
variables('servers' => get_static_head_node_local_ip_list)
172+
variables('relay_rules_dests' => get_static_head_node_local_ip_list.map { |host| host + ':2004' }.sort.join(','))
166173
notifies :restart, 'service[carbon-relay]', :delayed
167174
end
168175

@@ -234,9 +241,16 @@
234241
group 'www-data'
235242
mode 0o0440
236243
variables(
237-
'web_port' => node['bcpc']['graphite']['web_port'],
238-
'servers' => get_static_head_node_local_ip_list,
239-
'min_quorum' => get_static_head_nodes_count / 2 + 1
244+
'timezone' => node['bcpc']['graphite']['timezone'],
245+
'memcache_hosts' => node['bcpc']['graphite']['ip'],
246+
'whisper_dir' => node['bcpc']['graphite']['local_data_dir'],
247+
'graphite_dbname' => node['bcpc']['graphite_dbname'],
248+
'graphite_dbuser' => graphite_user,
249+
'graphite_dbpassword' => graphite_password,
250+
'graphite_nic' => node['bcpc']['graphite']['ip'],
251+
'cluster_servers' => get_static_head_node_local_ip_list.map { |host| "\"#{host}:#{node['bcpc']['graphite']['web_port']}\"" }.sort.join(', '),
252+
'intracluster_https' => node['bcpc']['graphite']['web_https'] ? 'True' : 'False',
253+
'carbonlink_hosts' => node['bcpc']['floating']['ip']
240254
)
241255
notifies :restart, 'service[apache2]', :delayed
242256
end

cookbooks/bcpc/templates/default/carbon/carbon.conf.erb

+15-15
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
# PID_DIR = /var/run/
3535
#
3636
# LOCAL_DATA_DIR = /opt/graphite/storage/whisper/
37-
LOCAL_DATA_DIR = <%= node['bcpc']['graphite']['local_data_dir'] %>
38-
LOG_DIR = <%= node['bcpc']['graphite']['local_log_dir'] %>
37+
LOCAL_DATA_DIR = <%= @local_data_dir %>
38+
LOG_DIR = <%= @log_dir %>
3939

4040
# Specify the database library used to store metric data on disk. Each database
4141
# may have configurable options to change the behaviour of how it writes to
@@ -70,7 +70,7 @@ MAX_CACHE_SIZE = inf
7070
# When the rate of required updates exceeds this, then carbon's caching will
7171
# take effect and increase the overall throughput accordingly.
7272
# MAX_UPDATES_PER_SECOND = 500
73-
MAX_UPDATES_PER_SECOND = <%= node['bcpc']['graphite']['carbon']['cache']['MAX_UPDATES_PER_SECOND'] %>
73+
MAX_UPDATES_PER_SECOND = <%= @cache_max_updates_per_sec %>
7474

7575
# If defined, this changes the MAX_UPDATES_PER_SECOND in Carbon when a
7676
# stop/shutdown is initiated. This helps when MAX_UPDATES_PER_SECOND is
@@ -105,22 +105,22 @@ MIN_TIMESTAMP_RESOLUTION = 1
105105
# interface to 0.0.0.0 listens on all interfaces. Port can be set to 0 to
106106
# disable this listener if it is not required.
107107
# LINE_RECEIVER_INTERFACE = 0.0.0.0
108-
LINE_RECEIVER_INTERFACE = <%="#{node[:bcpc][:management][:ip]}"%>
108+
LINE_RECEIVER_INTERFACE = <%= @cache_recv_nic %>
109109
LINE_RECEIVER_PORT = 2003
110110

111111
# Set this to True to enable the UDP listener. By default this is off
112112
# because it is very common to run multiple carbon daemons and managing
113113
# another (rarely used) port for every carbon instance is not fun.
114114
ENABLE_UDP_LISTENER = False
115115
# UDP_RECEIVER_INTERFACE = 0.0.0.0
116-
UDP_RECEIVER_INTERFACE = <%="#{node[:bcpc][:management][:ip]}"%>
116+
UDP_RECEIVER_INTERFACE = <%= @cache_recv_nic %>
117117
UDP_RECEIVER_PORT = 2003
118118

119119
# Set the interface and port for the pickle listener. Setting the interface to
120120
# 0.0.0.0 listens on all interfaces. Port can be set to 0 to disable this
121121
# listener if it is not required.
122122
# PICKLE_RECEIVER_INTERFACE = 0.0.0.0
123-
PICKLE_RECEIVER_INTERFACE = <%="#{node[:bcpc][:management][:ip]}"%>
123+
PICKLE_RECEIVER_INTERFACE = <%= @cache_recv_nic %>
124124
PICKLE_RECEIVER_PORT = 2004
125125

126126
# Set the interface and port for the protobuf listener. Setting the interface to
@@ -141,7 +141,7 @@ PICKLE_RECEIVER_PORT = 2004
141141
USE_INSECURE_UNPICKLER = False
142142

143143
# CACHE_QUERY_INTERFACE = 0.0.0.0
144-
CACHE_QUERY_INTERFACE = <%="#{node[:bcpc][:management][:ip]}"%>
144+
CACHE_QUERY_INTERFACE = <%= @cache_query_nic %>
145145
CACHE_QUERY_PORT = 7002
146146

147147
# Set this to False to drop datapoints received after the cache
@@ -352,11 +352,11 @@ ENABLE_TAGS = False
352352

353353
[relay]
354354
# LINE_RECEIVER_INTERFACE = 0.0.0.0
355-
LINE_RECEIVER_INTERFACE = <%="#{node[:bcpc][:graphite][:ip]}"%>
355+
LINE_RECEIVER_INTERFACE = <%= @relay_recv_nic %>
356356
# LINE_RECEIVER_PORT = 2013
357357
LINE_RECEIVER_PORT = 2013
358358
# PICKLE_RECEIVER_INTERFACE = 0.0.0.0
359-
PICKLE_RECEIVER_INTERFACE = <%="#{node[:bcpc][:graphite][:ip]}"%>
359+
PICKLE_RECEIVER_INTERFACE = <%= @relay_recv_nic %>
360360
PICKLE_RECEIVER_PORT = 2014
361361

362362
# Carbon-relay has several options for metric routing controlled by RELAY_METHOD
@@ -384,7 +384,7 @@ RELAY_METHOD = consistent-hashing
384384
# datapoint to more than one machine.
385385
# REPLICATION_FACTOR = 1
386386
# TODO: set REPLICATION_FACTOR to min_quorum if > 2 is needed.
387-
# REPLICATION_FACTOR = <%="#{@min_quorum}"%>
387+
# REPLICATION_FACTOR = <%= @min_quorum %>
388388
REPLICATION_FACTOR = 2
389389

390390
# For REPLICATION_FACTOR >=2, set DIVERSE_REPLICAS to True to guarantee replicas
@@ -412,7 +412,7 @@ REPLICATION_FACTOR = 2
412412
# If using RELAY_METHOD = rules, all destinations used in relay-rules.conf
413413
# must be defined in this list
414414
# DESTINATIONS = 127.0.0.1:2004
415-
DESTINATIONS = <%= "#{@servers.map{|hst| "#{hst}:2024"}.sort.join(', ')}" %>
415+
DESTINATIONS = <%= @relay_dests %>
416416

417417
# This define the protocol to use to contact the destination. It can be
418418
# set to one of "line", "pickle", "udp" and "protobuf". This list can be
@@ -475,7 +475,7 @@ USE_FLOW_CONTROL = True
475475
# If enabled this setting is used to timeout metric client connection if no
476476
# metrics have been sent in specified time in seconds
477477
#METRIC_CLIENT_IDLE_TIMEOUT = None
478-
METRIC_CLIENT_IDLE_TIMEOUT = <%="#{node[:bcpc][:graphite][:carbon][:relay][:idle_timeout]}"%>
478+
METRIC_CLIENT_IDLE_TIMEOUT = <%= @relay_idle_timeout %>
479479

480480
# Set this to True to enable whitelisting and blacklisting of metrics in
481481
# CONF_DIR/whitelist.conf and CONF_DIR/blacklist.conf. If the whitelist is
@@ -528,12 +528,12 @@ MIN_RESET_INTERVAL=121
528528

529529
[aggregator]
530530
# LINE_RECEIVER_INTERFACE = 0.0.0.0
531-
LINE_RECEIVER_INTERFACE = <%="#{node[:bcpc][:management][:ip]}"%>
531+
LINE_RECEIVER_INTERFACE = <%= @aggr_recv_nic %>
532532
# LINE_RECEIVER_PORT = 2023
533533
LINE_RECEIVER_PORT = 2023
534534

535535
# PICKLE_RECEIVER_INTERFACE = 0.0.0.0
536-
PICKLE_RECEIVER_INTERFACE = <%="#{node[:bcpc][:management][:ip]}"%>
536+
PICKLE_RECEIVER_INTERFACE = <%= @aggr_recv_nic %>
537537
PICKLE_RECEIVER_PORT = 2024
538538

539539
# If set true, metric received will be forwarded to DESTINATIONS in addition to
@@ -561,7 +561,7 @@ FORWARD_ALL = True
561561
# exactly match the webapp's CARBONLINK_HOSTS setting in terms of
562562
# instances listed (order matters!).
563563
# DESTINATIONS = 127.0.0.1:2004
564-
DESTINATIONS = <%="#{node[:bcpc][:management][:ip]+':2004'}"%>
564+
DESTINATIONS = <%= @aggr_dests %>
565565

566566
# If you want to add redundancy to your data by replicating every
567567
# datapoint to more than one machine, increase this.

cookbooks/bcpc/templates/default/carbon/relay-rules.conf.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
[default]
88
default = true
9-
destinations = <%= "#{@servers.map{|hst| "#{hst}:2004"}.join(', ')}" %>
9+
destinations = <%= @relay_rules_dests %>

cookbooks/bcpc/templates/default/graphite/local_settings.py.erb

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ALLOWED_HOSTS = [ '*' ]
2626
# Set your local timezone (Django's default is America/Chicago)
2727
# If your graphs appear to be offset by a couple hours then this probably
2828
# needs to be explicitly set to your local timezone.
29-
TIME_ZONE = <%= node['bcpc']['graphite']['timezone'] %>
29+
TIME_ZONE = <%= @timezone %>
3030

3131
# Override this to provide documentation specific to your Graphite deployment
3232
#DOCUMENTATION_URL = "http://graphite.readthedocs.org/"
@@ -55,7 +55,7 @@ LOG_CACHE_PERFORMANCE = True
5555
# You should not use the loopback address (127.0.0.1) here if using clustering
5656
# as every webapp in the cluster should use the exact same values to prevent
5757
# unneeded cache misses. Set to [] to disable caching of images and fetched data
58-
MEMCACHE_HOSTS = ['<%="#{node[:bcpc][:graphite][:ip]}"%>:11211']
58+
MEMCACHE_HOSTS = ['<%= @memcache_hosts %>:11211']
5959
#DEFAULT_CACHE_DURATION = 60 # Cache images and data for 1 minute
6060
#MEMCACHE_KEY_PREFIX = 'graphite'
6161

@@ -84,7 +84,7 @@ MEMCACHE_HOSTS = ['<%="#{node[:bcpc][:graphite][:ip]}"%>:11211']
8484
## Data directories
8585
# NOTE: If any directory is unreadable in DATA_DIRS it will break metric browsing
8686
#CERES_DIR = '/opt/graphite/storage/ceres'
87-
WHISPER_DIR = '<%= node['bcpc']['graphite']['local_data_dir'] %>'
87+
WHISPER_DIR = '<%= @whisper_dir %>'
8888
#RRD_DIR = '/opt/graphite/storage/rrd'
8989
#STANDARD_DIRS = [WHISPER_DIR, RRD_DIR] # Default: set from the above variables
9090
#LOG_DIR = '/opt/graphite/storage/log/webapp'
@@ -151,10 +151,10 @@ WHISPER_DIR = '<%= node['bcpc']['graphite']['local_data_dir'] %>'
151151
DATABASES = {
152152
'default': {
153153
'ENGINE': 'django.db.backends.mysql',
154-
'NAME': '<%="#{node['bcpc']['graphite_dbname']}"%>',
155-
'USER': '<%="#{get_config('mysql-graphite-user')}"%>',
156-
'PASSWORD': '<%="#{get_config!('password', 'mysql-graphite','os')}"%>',
157-
'HOST': '<%="#{node[:bcpc][:graphite][:ip]}"%>',
154+
'NAME': '<%= @graphite_dbname %>',
155+
'USER': '<%= @graphite_dbuser %>',
156+
'PASSWORD': '<%= @graphite_dbpassword %>',
157+
'HOST': '<%= @graphite_nic %>',
158158
'default-character-set': 'utf8'
159159
},
160160
}
@@ -169,8 +169,8 @@ DATABASES = {
169169
# remote server in the cluster. These servers must each have local access to
170170
# metric data. Note that the first server to return a match for a query will be
171171
# used.
172-
CLUSTER_SERVERS = [ <%="#{@servers.map{|hst| "\"#{hst}:#{@web_port}\""}.sort.join(', ')}"%> ]
173-
INTRACLUSTER_HTTPS = <%="#{node['bcpc']['graphite']['web_https'] == true ? 'True' : 'False'}" %>
172+
CLUSTER_SERVERS = [ <%= @cluster_servers %> ]
173+
INTRACLUSTER_HTTPS = <%= @intracluster_https %>
174174
## These are timeout values (in seconds) for requests to remote webapps
175175
REMOTE_FIND_TIMEOUT = 6.0 # Timeout for metric find requests
176176
REMOTE_FETCH_TIMEOUT = 10.0 # Timeout to fetch series data
@@ -199,7 +199,7 @@ REMOTE_FETCH_TIMEOUT = 10.0 # Timeout to fetch series data
199199
# and a common scheme is to use 7102 for instance b, 7202 for instance c, etc.
200200
#
201201
# You *should* use 127.0.0.1 here in most cases
202-
CARBONLINK_HOSTS = ['<%="#{node[:bcpc][:management][:ip]}"%>:7002']
202+
CARBONLINK_HOSTS = ['<%= @carbonlink_hosts %>:7002']
203203
#CARBONLINK_TIMEOUT = 1.0
204204
#CARBONLINK_RETRY_DELAY = 15 # Seconds to blacklist a failed remote server
205205

0 commit comments

Comments
 (0)