blob: 8ce9fb4928da5954bd0921cfd50e752421cf49fd [file] [log] [blame]
John H. Tran93361642012-07-26 11:22:05 -07001# lib/ceilometer
Dean Troyer6d04fd72012-12-21 11:03:37 -06002# Install and start **Ceilometer** service
3
Eoghan Glynn8d137032013-07-30 14:14:55 +00004# To enable a minimal set of Ceilometer services, add the following to localrc:
Adam Spierscb961592013-10-05 12:11:07 +01005#
Gordon Chung1c402282013-11-26 13:30:11 -05006# enable_service ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api
Eoghan Glynn8d137032013-07-30 14:14:55 +00007#
8# To ensure Ceilometer alarming services are enabled also, further add to the localrc:
Adam Spierscb961592013-10-05 12:11:07 +01009#
Eoghan Glynn19eed742013-09-20 21:11:25 +000010# enable_service ceilometer-alarm-notifier ceilometer-alarm-evaluator
Surya Prabhakar31d31852012-09-17 20:25:41 +053011
John H. Tran93361642012-07-26 11:22:05 -070012# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013#
John H. Tran93361642012-07-26 11:22:05 -070014# - functions
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040015# - OS_AUTH_URL for auth in api
Eoghan Glynnad80ead2012-09-27 09:36:33 +010016# - DEST set to the destination directory
Doug Hellmann4a2b1c62012-11-01 16:23:52 -040017# - SERVICE_PASSWORD, SERVICE_TENANT_NAME for auth in api
Attila Fazekas91b8d132013-01-06 22:40:09 +010018# - STACK_USER service user
John H. Tran93361642012-07-26 11:22:05 -070019
20# stack.sh
21# ---------
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010022# - install_ceilometer
23# - configure_ceilometer
24# - init_ceilometer
25# - start_ceilometer
26# - stop_ceilometer
27# - cleanup_ceilometer
John H. Tran93361642012-07-26 11:22:05 -070028
Dean Troyer7903b792012-09-13 17:16:12 -050029# Save trace setting
30XTRACE=$(set +o | grep xtrace)
31set +o xtrace
John H. Tran93361642012-07-26 11:22:05 -070032
33
34# Defaults
35# --------
36
Dean Troyer6d04fd72012-12-21 11:03:37 -060037# Set up default directories
John H. Tran93361642012-07-26 11:22:05 -070038CEILOMETER_DIR=$DEST/ceilometer
Yunhong, Jiange583d9b2013-01-09 09:33:07 +080039CEILOMETERCLIENT_DIR=$DEST/python-ceilometerclient
Dean Troyer6d04fd72012-12-21 11:03:37 -060040CEILOMETER_CONF_DIR=/etc/ceilometer
41CEILOMETER_CONF=$CEILOMETER_CONF_DIR/ceilometer.conf
42CEILOMETER_API_LOG_DIR=/var/log/ceilometer-api
Lianhao Lu8c548492013-01-09 10:41:54 +080043CEILOMETER_AUTH_CACHE_DIR=${CEILOMETER_AUTH_CACHE_DIR:-/var/cache/ceilometer}
Dean Troyer6d04fd72012-12-21 11:03:37 -060044
Monty Taylor9fbeedd2012-08-17 12:52:27 -040045# Support potential entry-points console scripts
Guangyu Suo9778b3c2013-07-17 15:22:21 +080046CEILOMETER_BIN_DIR=$(get_python_exec_prefix)
John H. Tran93361642012-07-26 11:22:05 -070047
Guangyu Suo9778b3c2013-07-17 15:22:21 +080048# Set up database backend
Julien Danjou69f74572013-08-27 11:43:53 +020049CEILOMETER_BACKEND=${CEILOMETER_BACKEND:-mysql}
Dean Troyercc6b4432013-04-08 15:38:03 -050050
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010051# Ceilometer connection info.
52CEILOMETER_SERVICE_PROTOCOL=http
53CEILOMETER_SERVICE_HOST=$SERVICE_HOST
54CEILOMETER_SERVICE_PORT=${CEILOMETER_SERVICE_PORT:-8777}
Dean Troyer4237f592014-01-29 16:22:11 -060055
Boris Pavlovic46e1aba2014-07-01 14:15:52 +040056# To enable OSprofiler change value of this variable to "notifications,profiler"
57CEILOMETER_NOTIFICATION_TOPICS=${CEILOMETER_NOTIFICATION_TOPICS:-notifications}
58
Dean Troyer4237f592014-01-29 16:22:11 -060059# Tell Tempest this project is present
60TEMPEST_SERVICES+=,ceilometer
61
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010062
Dean Troyercc6b4432013-04-08 15:38:03 -050063# Functions
64# ---------
Dean Troyere4fa7212014-01-15 15:04:49 -060065
66# Test if any Ceilometer services are enabled
67# is_ceilometer_enabled
68function is_ceilometer_enabled {
69 [[ ,${ENABLED_SERVICES} =~ ,"ceilometer-" ]] && return 0
70 return 1
71}
72
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010073# create_ceilometer_accounts() - Set up common required ceilometer accounts
74
Dean Troyer42a59c22014-03-03 14:31:29 -060075# Project User Roles
76# ------------------------------------------------------------------
77# SERVICE_TENANT_NAME ceilometer admin
78# SERVICE_TENANT_NAME ceilometer ResellerAdmin (if Swift is enabled)
79
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010080create_ceilometer_accounts() {
81
Steve Martinelli19685422014-01-24 13:02:26 -060082 SERVICE_TENANT=$(openstack project list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
83 ADMIN_ROLE=$(openstack role list | awk "/ admin / { print \$2 }")
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010084
85 # Ceilometer
86 if [[ "$ENABLED_SERVICES" =~ "ceilometer-api" ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -060087 CEILOMETER_USER=$(openstack user create \
88 ceilometer \
89 --password "$SERVICE_PASSWORD" \
90 --project $SERVICE_TENANT \
91 --email ceilometer@example.com \
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010092 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -060093 openstack role add \
94 $ADMIN_ROLE \
95 --project $SERVICE_TENANT \
96 --user $CEILOMETER_USER
Dirk Muellerfa5ccff2014-01-09 13:27:35 +010097 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
Steve Martinelli19685422014-01-24 13:02:26 -060098 CEILOMETER_SERVICE=$(openstack service create \
99 ceilometer \
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100100 --type=metering \
101 --description="OpenStack Telemetry Service" \
102 | grep " id " | get_field 2)
Steve Martinelli19685422014-01-24 13:02:26 -0600103 openstack endpoint create \
104 $CEILOMETER_SERVICE \
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100105 --region RegionOne \
Steve Martinelli19685422014-01-24 13:02:26 -0600106 --publicurl "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
107 --adminurl "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/" \
108 --internalurl "$CEILOMETER_SERVICE_PROTOCOL://$CEILOMETER_SERVICE_HOST:$CEILOMETER_SERVICE_PORT/"
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100109 fi
Dean Troyer42a59c22014-03-03 14:31:29 -0600110 if is_service_enabled swift; then
111 # Ceilometer needs ResellerAdmin role to access swift account stats.
112 openstack role add \
113 --project $SERVICE_TENANT_NAME \
114 --user ceilometer \
115 ResellerAdmin
116 fi
Dirk Muellerfa5ccff2014-01-09 13:27:35 +0100117 fi
118}
119
Dean Troyercc6b4432013-04-08 15:38:03 -0500120
John H. Tran93361642012-07-26 11:22:05 -0700121# cleanup_ceilometer() - Remove residual data files, anything left over from previous
122# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +1100123function cleanup_ceilometer {
Ian Wienand936284b2014-03-11 09:35:55 +1100124 if [ "$CEILOMETER_BACKEND" != 'mysql' ] && [ "$CEILOMETER_BACKEND" != 'postgresql' ] ; then
125 mongo ceilometer --eval "db.dropDatabase();"
126 fi
John H. Tran93361642012-07-26 11:22:05 -0700127}
128
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800129# configure_ceilometerclient() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100130function configure_ceilometerclient {
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800131 setup_develop $CEILOMETERCLIENT_DIR
Attila Fazekas8664ca52014-02-02 10:07:39 +0100132 sudo install -D -m 0644 -o $STACK_USER {$CEILOMETERCLIENT_DIR/tools/,/etc/bash_completion.d/}ceilometer.bash_completion
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800133}
134
John H. Tran93361642012-07-26 11:22:05 -0700135# configure_ceilometer() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +1100136function configure_ceilometer {
John H. Tran93361642012-07-26 11:22:05 -0700137 setup_develop $CEILOMETER_DIR
Surya Prabhakar31d31852012-09-17 20:25:41 +0530138
Doug Hellmannc5259b42012-09-22 10:52:31 -0400139 [ ! -d $CEILOMETER_CONF_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_CONF_DIR
Stephan Renatuse578eff2013-11-19 13:31:04 +0100140 sudo chown $STACK_USER $CEILOMETER_CONF_DIR
Surya Prabhakar31d31852012-09-17 20:25:41 +0530141
Doug Hellmannc5259b42012-09-22 10:52:31 -0400142 [ ! -d $CEILOMETER_API_LOG_DIR ] && sudo mkdir -m 755 -p $CEILOMETER_API_LOG_DIR
Stephan Renatuse578eff2013-11-19 13:31:04 +0100143 sudo chown $STACK_USER $CEILOMETER_API_LOG_DIR
John H. Tran93361642012-07-26 11:22:05 -0700144
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000145 iniset_rpc_backend ceilometer $CEILOMETER_CONF DEFAULT
Eoghan Glynnd36268a2013-02-22 21:59:52 +0000146
Boris Pavlovic46e1aba2014-07-01 14:15:52 +0400147 iniset $CEILOMETER_CONF DEFAULT notification_topics "$CEILOMETER_NOTIFICATION_TOPICS"
Julien Danjou4b3e4e52012-10-24 16:32:01 +0200148 iniset $CEILOMETER_CONF DEFAULT verbose True
Nadya Privalova423d7902014-03-06 15:14:59 +0400149 iniset $CEILOMETER_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
Doug Hellmann53a5f422012-10-02 17:29:23 -0400150
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400151 # Install the policy file for the API server
152 cp $CEILOMETER_DIR/etc/ceilometer/policy.json $CEILOMETER_CONF_DIR
153 iniset $CEILOMETER_CONF DEFAULT policy_file $CEILOMETER_CONF_DIR/policy.json
154
ZhiQiang Fan95053cf2014-05-16 16:27:41 +0800155 cp $CEILOMETER_DIR/etc/ceilometer/pipeline.yaml $CEILOMETER_CONF_DIR
156 cp $CEILOMETER_DIR/etc/ceilometer/api_paste.ini $CEILOMETER_CONF_DIR
157 cp $CEILOMETER_DIR/etc/ceilometer/event_definitions.yaml $CEILOMETER_CONF_DIR
158
Mehdi Abaakouk8ceb7942013-10-23 09:26:25 +0200159 if [ "$CEILOMETER_PIPELINE_INTERVAL" ]; then
160 sed -i "s/interval:.*/interval: ${CEILOMETER_PIPELINE_INTERVAL}/" $CEILOMETER_CONF_DIR/pipeline.yaml
161 fi
162
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000163 # the compute and central agents need these credentials in order to
ZhiQiang Fan1af4afb2014-04-16 14:52:12 +0800164 # call out to other services' public APIs
165 # the alarm evaluator needs these options to call ceilometer APIs
166 iniset $CEILOMETER_CONF service_credentials os_username ceilometer
167 iniset $CEILOMETER_CONF service_credentials os_password $SERVICE_PASSWORD
168 iniset $CEILOMETER_CONF service_credentials os_tenant_name $SERVICE_TENANT_NAME
Longgeek524bbed2014-06-01 23:44:21 +0800169 iniset $CEILOMETER_CONF service_credentials os_auth_url $OS_AUTH_URL
Eoghan Glynn14246ac2012-11-14 16:23:04 +0000170
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000171 iniset $CEILOMETER_CONF keystone_authtoken identity_uri $KEYSTONE_AUTH_URI
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400172 iniset $CEILOMETER_CONF keystone_authtoken admin_user ceilometer
173 iniset $CEILOMETER_CONF keystone_authtoken admin_password $SERVICE_PASSWORD
174 iniset $CEILOMETER_CONF keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
Lianhao Lu8c548492013-01-09 10:41:54 +0800175 iniset $CEILOMETER_CONF keystone_authtoken signing_dir $CEILOMETER_AUTH_CACHE_DIR
Doug Hellmann4a2b1c62012-11-01 16:23:52 -0400176
Thomas Maddox246d9bb2013-10-24 18:57:40 +0000177 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800178 iniset $CEILOMETER_CONF database connection `database_connection_url ceilometer`
179 else
180 iniset $CEILOMETER_CONF database connection mongodb://localhost:27017/ceilometer
181 configure_mongodb
182 cleanup_ceilometer
183 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530184
185 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
186 iniset $CEILOMETER_CONF DEFAULT hypervisor_inspector vsphere
187 iniset $CEILOMETER_CONF vmware host_ip "$VMWAREAPI_IP"
188 iniset $CEILOMETER_CONF vmware host_username "$VMWAREAPI_USER"
189 iniset $CEILOMETER_CONF vmware host_password "$VMWAREAPI_PASSWORD"
190 fi
John H. Tran93361642012-07-26 11:22:05 -0700191}
192
Ian Wienandaee18c72014-02-21 15:35:08 +1100193function configure_mongodb {
Ian Wienand936284b2014-03-11 09:35:55 +1100194 # server package is the same on all
195 local packages=mongodb-server
196
Dean Troyercc6b4432013-04-08 15:38:03 -0500197 if is_fedora; then
Ian Wienand936284b2014-03-11 09:35:55 +1100198 # mongodb client + python bindings
199 packages="${packages} mongodb pymongo"
200 else
201 packages="${packages} python-pymongo"
202 fi
203
204 install_package ${packages}
205
206 if is_fedora; then
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500207 # ensure smallfiles selected to minimize freespace requirements
208 sudo sed -i '/--smallfiles/!s/OPTIONS=\"/OPTIONS=\"--smallfiles /' /etc/sysconfig/mongod
209
210 restart_service mongod
211 fi
Ian Wienand936284b2014-03-11 09:35:55 +1100212
213 # give mongodb time to start-up
214 sleep 5
Eoghan Glynn285c75e2013-03-04 13:13:03 -0500215}
216
Lianhao Lu8c548492013-01-09 10:41:54 +0800217# init_ceilometer() - Initialize etc.
Ian Wienandaee18c72014-02-21 15:35:08 +1100218function init_ceilometer {
Lianhao Lu8c548492013-01-09 10:41:54 +0800219 # Create cache dir
220 sudo mkdir -p $CEILOMETER_AUTH_CACHE_DIR
Attila Fazekas91b8d132013-01-06 22:40:09 +0100221 sudo chown $STACK_USER $CEILOMETER_AUTH_CACHE_DIR
Lianhao Lu8c548492013-01-09 10:41:54 +0800222 rm -f $CEILOMETER_AUTH_CACHE_DIR/*
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800223
Sean Daguec921a952014-02-28 21:09:33 -0500224 if is_service_enabled mysql postgresql; then
225 if [ "$CEILOMETER_BACKEND" = 'mysql' ] || [ "$CEILOMETER_BACKEND" = 'postgresql' ] ; then
226 recreate_database ceilometer utf8
227 $CEILOMETER_BIN_DIR/ceilometer-dbsync
228 fi
Guangyu Suo9778b3c2013-07-17 15:22:21 +0800229 fi
Lianhao Lu8c548492013-01-09 10:41:54 +0800230}
231
John H. Tran93361642012-07-26 11:22:05 -0700232# install_ceilometer() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100233function install_ceilometer {
John H. Tran93361642012-07-26 11:22:05 -0700234 git_clone $CEILOMETER_REPO $CEILOMETER_DIR $CEILOMETER_BRANCH
235}
236
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800237# install_ceilometerclient() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100238function install_ceilometerclient {
Yunhong, Jiange583d9b2013-01-09 09:33:07 +0800239 git_clone $CEILOMETERCLIENT_REPO $CEILOMETERCLIENT_DIR $CEILOMETERCLIENT_BRANCH
240}
241
John H. Tran93361642012-07-26 11:22:05 -0700242# start_ceilometer() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100243function start_ceilometer {
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000244 if [[ "$VIRT_DRIVER" = 'libvirt' ]]; then
Dina Belova0f6d4532014-04-23 17:47:36 +0400245 screen_it ceilometer-acompute "cd ; sg $LIBVIRT_GROUP 'ceilometer-agent-compute --config-file $CEILOMETER_CONF'"
Mehdi Abaakoukfc1b7782013-10-23 06:46:43 +0000246 fi
Piyush Masrani846609b2014-03-14 19:21:48 +0530247 if [[ "$VIRT_DRIVER" = 'vsphere' ]]; then
248 screen_it ceilometer-acompute "cd ; ceilometer-agent-compute --config-file $CEILOMETER_CONF"
249 fi
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200250 screen_it ceilometer-acentral "cd ; ceilometer-agent-central --config-file $CEILOMETER_CONF"
Gordon Chung1c402282013-11-26 13:30:11 -0500251 screen_it ceilometer-anotification "cd ; ceilometer-agent-notification --config-file $CEILOMETER_CONF"
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200252 screen_it ceilometer-collector "cd ; ceilometer-collector --config-file $CEILOMETER_CONF"
253 screen_it ceilometer-api "cd ; ceilometer-api -d -v --log-dir=$CEILOMETER_API_LOG_DIR --config-file $CEILOMETER_CONF"
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200254
Sean Dague7083b822014-02-28 20:16:20 -0500255 # only die on API if it was actually intended to be turned on
Sean Dagueb9a70352014-03-04 15:02:04 -0500256 if is_service_enabled ceilometer-api; then
Sean Dague7083b822014-02-28 20:16:20 -0500257 echo "Waiting for ceilometer-api to start..."
258 if ! timeout $SERVICE_TIMEOUT sh -c "while ! curl --noproxy '*' -s http://localhost:8777/v2/ >/dev/null; do sleep 1; done"; then
259 die $LINENO "ceilometer-api did not start"
260 fi
Mehdi Abaakouk1ed64cb2013-10-23 10:37:05 +0200261 fi
262
Mehdi Abaakouk6d4a9a82013-10-14 16:20:32 +0200263 screen_it ceilometer-alarm-notifier "cd ; ceilometer-alarm-notifier --config-file $CEILOMETER_CONF"
264 screen_it ceilometer-alarm-evaluator "cd ; ceilometer-alarm-evaluator --config-file $CEILOMETER_CONF"
John H. Tran93361642012-07-26 11:22:05 -0700265}
Dean Troyer7903b792012-09-13 17:16:12 -0500266
Dean Troyer699a29f2012-09-10 14:10:27 -0500267# stop_ceilometer() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100268function stop_ceilometer {
Dean Troyer699a29f2012-09-10 14:10:27 -0500269 # Kill the ceilometer screen windows
Gordon Chung1c402282013-11-26 13:30:11 -0500270 for serv in ceilometer-acompute ceilometer-acentral ceilometer-anotification ceilometer-collector ceilometer-api ceilometer-alarm-notifier ceilometer-alarm-evaluator; do
Dean Troyer9fc87922013-05-22 17:19:06 -0500271 screen_stop $serv
Dean Troyer699a29f2012-09-10 14:10:27 -0500272 done
273}
274
Dean Troyercc6b4432013-04-08 15:38:03 -0500275
Dean Troyer7903b792012-09-13 17:16:12 -0500276# Restore xtrace
277$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400278
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100279# Tell emacs to use shell-script-mode
280## Local variables:
281## mode: shell-script
282## End: