From cb67313c1e14b6eca057bdfc7722bc11506b7a2a Mon Sep 17 00:00:00 2001 From: Yang Yu Date: Wed, 2 May 2018 16:52:11 +0800 Subject: Restructure monitoring scripts Restructure the monitoring scripts and modify the scripts to remove the redundance Change-Id: Ib4a5d7bea2dc455ec03ad61780b6caf06831daa8 Signed-off-by: Yang Yu --- monitor/dispatch/__init__.py | 8 +++++ monitor/dispatch/automate_barometer_client.py | 51 +++++++++++++++++++++++++++ monitor/dispatch/automate_cadvisor_client.py | 43 ++++++++++++++++++++++ monitor/dispatch/automate_collectd_client.py | 50 ++++++++++++++++++++++++++ monitor/dispatch/client_ip_configure.py | 25 +++++++++++++ monitor/dispatch/install_barometer_client.sh | 8 +++++ monitor/dispatch/install_cadvisor_client.sh | 12 +++++++ monitor/dispatch/install_collectd_client.sh | 8 +++++ monitor/dispatch/server_ip_configure.py | 25 +++++++++++++ 9 files changed, 230 insertions(+) create mode 100644 monitor/dispatch/__init__.py create mode 100644 monitor/dispatch/automate_barometer_client.py create mode 100644 monitor/dispatch/automate_cadvisor_client.py create mode 100644 monitor/dispatch/automate_collectd_client.py create mode 100644 monitor/dispatch/client_ip_configure.py create mode 100644 monitor/dispatch/install_barometer_client.sh create mode 100644 monitor/dispatch/install_cadvisor_client.sh create mode 100644 monitor/dispatch/install_collectd_client.sh create mode 100644 monitor/dispatch/server_ip_configure.py (limited to 'monitor/dispatch') diff --git a/monitor/dispatch/__init__.py b/monitor/dispatch/__init__.py new file mode 100644 index 00000000..a90f1d17 --- /dev/null +++ b/monitor/dispatch/__init__.py @@ -0,0 +1,8 @@ +############################################################################## +# Copyright (c) 2018 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## diff --git a/monitor/dispatch/automate_barometer_client.py b/monitor/dispatch/automate_barometer_client.py new file mode 100644 index 00000000..3a246028 --- /dev/null +++ b/monitor/dispatch/automate_barometer_client.py @@ -0,0 +1,51 @@ +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import logging +import yaml +import utils.infra_setup.passwordless_SSH.ssh as ssh + +logger = logging.getLogger(__name__) +barometer_client_install_sh =\ + "/home/opnfv/bottlenecks/monitor/dispatch/install_barometer_client.sh" +barometer_client_install_conf =\ + "/home/opnfv/bottlenecks/monitor/config/barometer_client.conf" + +with open('/tmp/pod.yaml') as f: + dataMap = yaml.safe_load(f) + for x in dataMap: + for y in dataMap[x]: + if (y['role'] == 'Controller') or (y['role'] == 'Compute'): + ip = str(y['ip']) + user = str(y['user']) + pwd = str(y['password']) + ssh_d = ssh.SSH(user, host=ip, password=pwd) + status, stdout, stderr = ssh_d.execute( + "cd /etc && mkdir barometer_config" + ) + if status: + print Exception( + "Command: \"mkdir barometer_config\" failed.") + logger.info(stdout.splitlines()) + with open(barometer_client_install_conf) as stdin_file: + ssh_d.run("cat > /etc/barometer_config/\ +barometer_client.conf", + stdin=stdin_file) + with open(barometer_client_install_sh) as stdin_file: + ssh_d.run("cat > /etc/barometer_config/install.sh", + stdin=stdin_file) + + status, stdout, stderr = ssh_d.execute( + "sudo apt-get install -y docker.io" + ) + if status: + raise Exception("Command for installing docker failed.") + logger.info(stdout.splitlines()) + + ssh_d.run("cd /etc/barometer_config/ && bash ./install.sh") diff --git a/monitor/dispatch/automate_cadvisor_client.py b/monitor/dispatch/automate_cadvisor_client.py new file mode 100644 index 00000000..3a65ff1d --- /dev/null +++ b/monitor/dispatch/automate_cadvisor_client.py @@ -0,0 +1,43 @@ +############################################################################## +# Copyright (c) 2017 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import logging +import yaml +import utils.infra_setup.passwordless_SSH.ssh as ssh + +logger = logging.getLogger(__name__) +cadvisor_client_install_sh =\ + "/home/opnfv/bottlenecks/monitor/dispatch/install_cadvisor_client.sh" + +with open('/tmp/pod.yaml') as f: + dataMap = yaml.safe_load(f) + for x in dataMap: + for y in dataMap[x]: + if (y['role'] == 'Controller') or (y['role'] == 'Compute'): + ip = str(y['ip']) + user = str(y['user']) + pwd = str(y['password']) + ssh_d = ssh.SSH(user, host=ip, password=pwd) + status, stdout, stderr = ssh_d.execute( + "cd /etc && mkdir cadvisor_config" + ) + if status: + print Exception( + "Command: \"mkdir cadvisor_config\" failed.") + logger.info(stdout.splitlines()) + with open(cadvisor_client_install_sh) as stdin_file: + ssh_d.run("cat > /etc/cadvisor_config/install.sh", + stdin=stdin_file) + status, stdout, stderr = ssh_d.execute( + "sudo apt-get install -y docker.io" + ) + if status: + raise Exception("Command for installing docker failed.") + logger.info(stdout.splitlines()) + ssh_d.run("cd /etc/cadvisor_config/ && bash ./install.sh") diff --git a/monitor/dispatch/automate_collectd_client.py b/monitor/dispatch/automate_collectd_client.py new file mode 100644 index 00000000..c4346e51 --- /dev/null +++ b/monitor/dispatch/automate_collectd_client.py @@ -0,0 +1,50 @@ +############################################################################## +# Copyright (c) 2017 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import logging +import yaml +import utils.infra_setup.passwordless_SSH.ssh as ssh + +logger = logging.getLogger(__name__) +collectd_client_install_sh =\ + "/home/opnfv/bottlenecks/monitor/dispatch/install_collectd_client.sh" +collectd_client_install_conf =\ + "/home/opnfv/bottlenecks/monitor/config/collectd_client.conf" + +with open('/tmp/pod.yaml') as f: + dataMap = yaml.safe_load(f) + for x in dataMap: + for y in dataMap[x]: + if (y['role'] == 'Controller') or (y['role'] == 'Compute'): + ip = str(y['ip']) + user = str(y['user']) + pwd = str(y['password']) + ssh_d = ssh.SSH(user, host=ip, password=pwd) + status, stdout, stderr = ssh_d.execute( + "cd /etc && mkdir collectd_config" + ) + if status: + print Exception( + "Command: \"mkdir collectd_config\" failed.") + logger.info(stdout.splitlines()) + with open(collectd_client_install_sh) as stdin_file: + ssh_d.run("cat > /etc/collectd_config/install.sh", + stdin=stdin_file) + with open(collectd_client_install_conf) as stdin_file: + ssh_d.run( + "cat > /etc/collectd_config/collectd_client.conf", + stdin=stdin_file + ) + status, stdout, stderr = ssh_d.execute( + "sudo apt-get install -y docker.io" + ) + if status: + raise Exception("Command for installing docker failed.") + logger.info(stdout.splitlines()) + ssh_d.run("cd /etc/collectd_config/ && bash ./install.sh") diff --git a/monitor/dispatch/client_ip_configure.py b/monitor/dispatch/client_ip_configure.py new file mode 100644 index 00000000..2a66f7b2 --- /dev/null +++ b/monitor/dispatch/client_ip_configure.py @@ -0,0 +1,25 @@ +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import fileinput +import re +import logging +import socket + +logger = logging.getLogger(__name__) +ip_address = socket.gethostbyname(socket.gethostname()) + +for line in fileinput.input(inplace=1): + ip = " Server \"" + str(ip_address) + "\" \"25826\"" + line = re.sub(r'.*Server.*25826.*', r'' + str(ip), line.rstrip()) + print(line) + +for line in fileinput.input(inplace=1): + ip = " URL \"http://" + str(ip_address) + ":9103/collectd-post\"" + line = re.sub(r'.*URL.*collectd-post.*', r'' + str(ip), line.rstrip()) + print(line) diff --git a/monitor/dispatch/install_barometer_client.sh b/monitor/dispatch/install_barometer_client.sh new file mode 100644 index 00000000..491e8245 --- /dev/null +++ b/monitor/dispatch/install_barometer_client.sh @@ -0,0 +1,8 @@ +HOSTNAME=`hostname` + +docker pull opnfv/barometer +sudo docker run --name bottlenecks-barometer-${HOSTNAME} -tid --net=host \ + -v /etc/barometer_config/barometer_client.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \ + -v /etc/barometer_config/barometer_client.conf:/opt/collectd/etc/collectd.conf \ + -v /var/run:/var/run -v /tmp:/tmp \ + --privileged opnfv/barometer /run_collectd.sh \ No newline at end of file diff --git a/monitor/dispatch/install_cadvisor_client.sh b/monitor/dispatch/install_cadvisor_client.sh new file mode 100644 index 00000000..bcd0e8a1 --- /dev/null +++ b/monitor/dispatch/install_cadvisor_client.sh @@ -0,0 +1,12 @@ +HOSTNAME=`hostname` + +sudo docker run \ + --name=bottlenecks-cadvisor-${HOSTNAME} \ + --volume=/:/rootfs:ro \ + --volume=/var/run:/var/run:rw \ + --volume=/sys:/sys:ro \ + --volume=/var/lib/docker/:/var/lib/docker:ro \ + --volume=/dev/disk/:/dev/disk:ro \ + --publish=8080:8080 \ + --detach=true \ + google/cadvisor:v0.25.0 diff --git a/monitor/dispatch/install_collectd_client.sh b/monitor/dispatch/install_collectd_client.sh new file mode 100644 index 00000000..4f081124 --- /dev/null +++ b/monitor/dispatch/install_collectd_client.sh @@ -0,0 +1,8 @@ +MONITOR_CONFIG="/etc/collectd_config" +HOSTNAME=`hostname` + +sudo docker run --name bottlenecks-collectd-${HOSTNAME} -d \ + --privileged \ + -v ${MONITOR_CONFIG}/collectd_client.conf:/etc/collectd/collectd.conf:ro \ + -v /proc:/mnt/proc:ro \ + fr3nd/collectd:5.5.0-1 diff --git a/monitor/dispatch/server_ip_configure.py b/monitor/dispatch/server_ip_configure.py new file mode 100644 index 00000000..62aa6288 --- /dev/null +++ b/monitor/dispatch/server_ip_configure.py @@ -0,0 +1,25 @@ +############################################################################## +# Copyright (c) 2018 Huawei Tech and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import fileinput +import re +import logging +import socket + +logger = logging.getLogger(__name__) +ip_address = socket.gethostbyname(socket.gethostname()) + +for line in fileinput.input(inplace=1): + ip = " Listen \"" + str(ip_address) + "\" \"25826\"" + line = re.sub(r'.*Listen.*25826.*', r'' + str(ip), line.rstrip()) + print(line) + +for line in fileinput.input(inplace=1): + ip = " URL \"http://" + str(ip_address) + ":9103/collectd-post\"" + line = re.sub(r'.*URL.*collectd-post.*', r'' + str(ip), line.rstrip()) + print(line) -- cgit 1.2.3-korg