summaryrefslogtreecommitdiffstats
path: root/monitor/dispatch
diff options
context:
space:
mode:
authorYang Yu <Gabriel.yuyang@huawei.com>2018-05-02 16:52:11 +0800
committerYang Yu <Gabriel.yuyang@huawei.com>2018-05-03 15:59:28 +0800
commitcb67313c1e14b6eca057bdfc7722bc11506b7a2a (patch)
tree226b177ff6e8a227368c2d765174ba9d4f875829 /monitor/dispatch
parent742fc9ab94ede1187c9146e5336e28fe84d510c5 (diff)
Restructure monitoring scripts
Restructure the monitoring scripts and modify the scripts to remove the redundance Change-Id: Ib4a5d7bea2dc455ec03ad61780b6caf06831daa8 Signed-off-by: Yang Yu <Gabriel.yuyang@huawei.com>
Diffstat (limited to 'monitor/dispatch')
-rw-r--r--monitor/dispatch/__init__.py8
-rw-r--r--monitor/dispatch/automate_barometer_client.py51
-rw-r--r--monitor/dispatch/automate_cadvisor_client.py43
-rw-r--r--monitor/dispatch/automate_collectd_client.py50
-rw-r--r--monitor/dispatch/client_ip_configure.py25
-rw-r--r--monitor/dispatch/install_barometer_client.sh8
-rw-r--r--monitor/dispatch/install_cadvisor_client.sh12
-rw-r--r--monitor/dispatch/install_collectd_client.sh8
-rw-r--r--monitor/dispatch/server_ip_configure.py25
9 files changed, 230 insertions, 0 deletions
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)