Skip to content

Commit

Permalink
Ganglia review changes (GoogleCloudDataproc#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-stasiak-polidea authored and karth295 committed Mar 26, 2018
1 parent f3110d0 commit 8129876
Showing 1 changed file with 47 additions and 31 deletions.
78 changes: 47 additions & 31 deletions ganglia/ganglia.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/bin/bash
# Copyright 2015 Google, Inc.
# Copyright 2015 Google, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This initialization action installs Ganglia, a distributed monitoring system.

set -x -e

function err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
return 1
}

function update_apt_get() {
for ((i = 0; i < 10; i++)); do
if apt-get update; then
Expand All @@ -25,31 +32,40 @@ function update_apt_get() {
return 1
}

update_apt_get
apt-get install -y ganglia-monitor

MASTER=$(/usr/share/google/get_metadata_value attributes/dataproc-master)
function install_ganglia_dependencies() {
# Install dependencies needed for ganglia
sed -e "/name = \"unspecified\" /s/unspecified/${master}/" -i /etc/ganglia/gmond.conf
sed -e '/mcast_join /s/^ / #/' -i /etc/ganglia/gmond.conf
sed -e '/bind /s/^ / #/' -i /etc/ganglia/gmond.conf
DEBIAN_FRONTEND=noninteractive apt-get install -y \
rrdtool \
gmetad \
ganglia-webfrontend || err 'Unable to install packages'

sed -e "/name = \"unspecified\" /s/unspecified/$MASTER/" -i /etc/ganglia/gmond.conf
sed -e '/mcast_join /s/^ / #/' -i /etc/ganglia/gmond.conf
sed -e '/bind /s/^ / #/' -i /etc/ganglia/gmond.conf
ln -s /etc/ganglia-webfrontend/apache.conf /etc/apache2/sites-enabled/ganglia.conf
sed -i "s/my cluster/${master}/" /etc/ganglia/gmetad.conf
sed -e '/udp_send_channel {/a\ host = localhost' -i /etc/ganglia/gmond.conf
systemctl restart ganglia-monitor &&
systemctl restart gmetad &&
systemctl restart apache2

ROLE=$(/usr/share/google/get_metadata_value attributes/dataproc-role)
if [[ "${ROLE}" == 'Master' ]]; then
# Only run on the master node
# Install dependencies needed for ganglia
DEBIAN_FRONTEND=noninteractive apt install -y rrdtool gmetad ganglia-webfrontend
cp /etc/ganglia-webfrontend/apache.conf /etc/apache2/sites-enabled/ganglia.conf

sed -i "s/my cluster/$MASTER/" /etc/ganglia/gmetad.conf
sed -e '/udp_send_channel {/a\ host = localhost' -i /etc/ganglia/gmond.conf
}

service ganglia-monitor restart && service gmetad restart && service apache2 restart
function main() {
local role=$(/usr/share/google/get_metadata_value attributes/dataproc-role)
local master=$(/usr/share/google/get_metadata_value attributes/dataproc-master)

else
update_apt_get || err 'Unable to update apt-get'
apt-get install -y ganglia-monitor

sed -e "/udp_send_channel {/a\ host = $MASTER" -i /etc/ganglia/gmond.conf
if [[ "${role}" == 'Master' ]]; then
# Only run on the master node
install_ganglia_dependencies || err 'Installing dependencies for Ganglia failed'
else
sed -e "/udp_send_channel {/a\ host = ${master}" -i /etc/ganglia/gmond.conf
sed -i '/udp_recv_channel {/,/}/d' /etc/ganglia/gmond.conf
service ganglia-monitor restart
systemctl restart ganglia-monitor
fi
}

fi
main

0 comments on commit 8129876

Please sign in to comment.