Style-check for monitoring scripts 09/57009/1
authorYang Yu <Gabriel.yuyang@huawei.com>
Wed, 2 May 2018 04:14:49 +0000 (12:14 +0800)
committerYu Yang (Gabriel) <Gabriel.yuyang@huawei.com>
Thu, 3 May 2018 08:08:54 +0000 (08:08 +0000)
Fix the style-check errors for monitoring scripts.
In another patch, the scripts will be restructured
according the dicretory structure.

Change-Id: I4149b18177fa1bdeb1b12a84ecad3d7d0b78260b
Signed-off-by: Yang Yu <Gabriel.yuyang@huawei.com>
(cherry picked from commit 742fc9ab94ede1187c9146e5336e28fe84d510c5)

14 files changed:
monitor/automate_cadvisor_client.py
monitor/automate_collectd_client.py
monitor/automated_dashboard_datasource.py [moved from monitor/automated-dashboard-datasource.py with 95% similarity]
monitor/barometer_automated_client_install.py
monitor/barometer_collectd.conf [moved from monitor/barometer-collectd.conf with 100% similarity]
monitor/barometer_install_client.sh
monitor/barometer_install_script.sh [moved from monitor/barometer-install-script.sh with 72% similarity]
monitor/client_ip_configure.py
monitor/custom_dashboard.py [moved from monitor/custom-dashboard.py with 83% similarity]
monitor/custom_query_dashboard.json [moved from monitor/custom-query-dashboard.json with 100% similarity]
monitor/grafana/dashboards/prometheus_system_rev1.json [moved from monitor/grafana/dashboards/prometheus-system_rev1.json with 100% similarity]
monitor/install_collectd_client.sh [moved from monitor/install-collectd-client.sh with 82% similarity]
monitor/monitoring.sh
monitor/server_ip_configure.py

index 95b98e9..f84892d 100644 (file)
@@ -8,30 +8,34 @@
 ##############################################################################
 
 import logging
-import sys
 import yaml
-sys.path.insert(0, '/home/opnfv/bottlenecks/utils/infra_setup/passwordless_SSH/')
-import ssh
+import utils.infra_setup.passwordless_SSH.ssh as ssh
 
 logger = logging.getLogger(__name__)
+cadvisor_install_sh = "/home/opnfv/bottlenecks/monitor/cadvisor_install.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'):
+            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")
+                ssh_d = ssh.SSH(user, host=ip, password=pwd)
+                status, stdout, stderr = ssh_d.execute(
+                    "cd /etc && mkdir cadvisor_config"
+                )
                 if status:
                     raise Exception("Command failed with non-zero status.")
                     logger.info(stdout.splitlines())
-                with open("/home/opnfv/bottlenecks/monitor/cadvisor_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 docker.io")
+                with open(cadvisor_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 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")
-
+                ssh_d.run("cd /etc/cadvisor_config/ && bash ./install.sh")
index 6dd7067..8358cfc 100644 (file)
@@ -8,31 +8,40 @@
 ##############################################################################
 
 import logging
-import sys
 import yaml
-sys.path.insert(0, '/home/opnfv/bottlenecks/utils/infra_setup/passwordless_SSH/')
-import ssh
+import utils.infra_setup.passwordless_SSH.ssh as ssh
 
 logger = logging.getLogger(__name__)
+collectd_client_install_sh =\
+    "/home/opnfv/bottlenecks/monitor/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'):
+            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")
+                ssh_d = ssh.SSH(user, host=ip, password=pwd)
+                status, stdout, stderr = ssh_d.execute(
+                    "cd /etc && mkdir collectd_config"
+                )
                 if status:
                     raise Exception("Command failed with non-zero status.")
                     logger.info(stdout.splitlines())
-                with open("/home/opnfv/bottlenecks/monitor/install-collectd-client.sh") as stdin_file:
-                    ssh_d.run("cat > /etc/collectd-config/install.sh", stdin=stdin_file)
-                with open("/home/opnfv/bottlenecks/monitor/config/collectd-client.conf") as stdin_file:
-                    ssh_d.run("cat > /etc/collectd-config/collectd.conf", stdin=stdin_file)
-                status, stdout, stderr = ssh_d.execute("sudo apt-get install docker.io")
+                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.conf",
+                              stdin=stdin_file)
+                status, stdout, stderr = ssh_d.execute(
+                    "sudo apt-get install 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")
+                ssh_d.run("cd /etc/collectd_config/ && bash ./install.sh")
similarity index 95%
rename from monitor/automated-dashboard-datasource.py
rename to monitor/automated_dashboard_datasource.py
index 69f3ebe..ee60504 100644 (file)
@@ -23,7 +23,7 @@ def _create_dashboard(ip, port, path):
         data = jsonutils.load(f)
     try:
         post(url, {"dashboard": data})
-        logger.info( "Trying to post dashboard json!")
+        logger.info("Trying to post dashboard json!")
     except Exception:
         logger.info("Create dashboard failed")
         raise
@@ -66,6 +66,6 @@ ip_address = socket.gethostbyname(socket.gethostname())
 _create_data_source(ip_address, 3000)
 _create_dashboard(ip_address, 3000, '/var/lib/grafana/' +
                   'dashboards/' +
-                  'prometheus-system_rev1.json')
+                  'prometheus_system_rev1.json')
 _create_dashboard(ip_address, 3000,
                   'prototype_dashboard_collapsible.json')
index 7bbfa70..9bb2c6b 100644 (file)
@@ -8,29 +8,36 @@
 ##############################################################################
 
 import logging
-import sys
 import yaml
-sys.path.insert(0, '/home/opnfv/bottlenecks/utils/infra_setup/passwordless_SSH/')
-import ssh
+import utils.infra_setup.passwordless_SSH.ssh as ssh
 
 logger = logging.getLogger(__name__)
+barometer_client_install_sh =\
+    "/home/opnfv/bottlenecks/monitor/barometer_install_client.sh"
+barometer_client_install_conf =\
+    "/home/opnfv/bottlenecks/monitor/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'):
+            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")
+                ssh_d = ssh.SSH(user, host=ip, password=pwd)
+                status, stdout, stderr = ssh_d.execute(
+                    "cd /etc && mkdir barometer_config"
+                )
                 if status:
                     raise Exception("Command failed with non-zero status.")
                     logger.info(stdout.splitlines())
-                with open("/home/opnfv/bottlenecks/monitor/barometer_client.conf") as stdin_file:
-                    ssh_d.run("cat > /etc/barometer-config/barometer_client_collectd.conf", stdin=stdin_file)
-
-                with open("/home/opnfv/bottlenecks/monitor/barometer_install_client.sh") as stdin_file:
-                    ssh_d.run("cat > /etc/barometer-config/install.sh", stdin=stdin_file)
+                with open(barometer_client_install_conf) as stdin_file:
+                    ssh_d.run("cat > /etc/barometer_config/\
+                        barometer_client_collectd.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)
 
-                ssh_d.run("cd /etc/barometer-config/ && bash ./install.sh")
+                ssh_d.run("cd /etc/barometer_config/ && bash ./install.sh")
index d75adf1..2bf6cd8 100644 (file)
@@ -1,5 +1,5 @@
 docker pull opnfv/barometer
 sudo docker run  --name bottlenecks-barometer-client -tid --net=host -v `pwd`/../src/collectd_sample_configs:/opt/collectd/etc/collectd.conf.d \
--v /etc/barometer-config/barometer_client_collectd.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \
--v /etc/barometer-config/barometer_client_collectd.conf:/opt/collectd/etc/collectd.conf \
+-v /etc/barometer_config/barometer_client_collectd.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \
+-v /etc/barometer_config/barometer_client_collectd.conf:/opt/collectd/etc/collectd.conf \
 -v /var/run:/var/run -v /tmp:/tmp --privileged opnfv/barometer /run_collectd.sh
similarity index 72%
rename from monitor/barometer-install-script.sh
rename to monitor/barometer_install_script.sh
index 9dc2009..b0abbb9 100644 (file)
@@ -1,5 +1,5 @@
 docker pull opnfv/barometer
 sudo docker run  --name bottlenecks-barometer-server -tid --net=host -v `pwd`/../src/collectd_sample_configs:/opt/collectd/etc/collectd.conf.d \
--v /home/opnfv/bottlenecks/monitor/barometer-collectd.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \
--v /etc/barometer-config/barometer_client_collectd.conf:/opt/collectd/etc/collectd.conf \
+-v /home/opnfv/bottlenecks/monitor/barometer_collectd.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \
+-v /etc/barometer_config/barometer_client_collectd.conf:/opt/collectd/etc/collectd.conf \
 -v /var/run:/var/run -v /tmp:/tmp --privileged opnfv/barometer /run_collectd.sh
index 9bfb12c..2a66f7b 100644 (file)
@@ -10,18 +10,16 @@ import fileinput
 import re
 import logging
 import socket
-import requests
-from oslo_serialization import jsonutils
 
 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())
+    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())
+    ip = "    URL \"http://" + str(ip_address) + ":9103/collectd-post\""
+    line = re.sub(r'.*URL.*collectd-post.*', r'' + str(ip), line.rstrip())
     print(line)
similarity index 83%
rename from monitor/custom-dashboard.py
rename to monitor/custom_dashboard.py
index 48173f8..2a4f79c 100644 (file)
@@ -9,14 +9,15 @@
 
 import json
 
+
 def customize_query(filename, rowtitle, panelname, expr):
     with open(filename, 'r+') as f:
         data = json.load(f)
-        x = data['rows'] #this is an array of the rows of the dashboard
+        x = data['rows']  # this is an array of the rows of the dashboard
         for y in x:
             if y['title'] == rowtitle:
                 pan = y['panels']
-                for i in range(len(pan)-1) :
+                for i in range(len(pan) - 1):
                     z = pan[i]
                     if z['title'] == panelname:
                         tar = z['targets']
@@ -26,6 +27,7 @@ def customize_query(filename, rowtitle, panelname, expr):
                             json.dump(data, f, indent=4)
                             f.truncate()
 
-customize_query("/home/opnfv/bottlenecks/monitor/custom-query-dashboard.json",
-    "Dashboard Row", "Memory Usage per Container", "Sample Prometheus Query")
 
+customize_query("/home/opnfv/bottlenecks/monitor/custom-query-dashboard.json",
+                "Dashboard Row", "Memory Usage per Container",
+                "Sample Prometheus Query")
similarity index 82%
rename from monitor/install-collectd-client.sh
rename to monitor/install_collectd_client.sh
index 00fa4c8..3861f98 100644 (file)
@@ -1,4 +1,4 @@
-MONITOR_CONFIG="/etc/collectd-config"
+MONITOR_CONFIG="/etc/collectd_config"
 
 # Collectd
 sudo docker run --name bottlenecks-automated-collectd -d \
index 01c1edc..9abe49d 100644 (file)
@@ -64,7 +64,7 @@ sudo docker run \
 python client_ip_configure.py barometer_client.conf
 
 # Configure IP Address in barometer server configuration
-python server_ip_configure.py barometer-collectd.conf
+python server_ip_configure.py barometer_collectd.conf
 
 # Automate Collectd Client
 python automate_collectd_client.py
@@ -73,10 +73,10 @@ python automate_collectd_client.py
 python automate_cadvisor_client.py
 
 # Automate Barometer installation for jump server
-bash ./barometer-install-script.sh
+bash ./barometer_install_script.sh
 
 # Automate Barometer installation for compute/controller nodes
 python barometer_automated_client_install.py
 
 # Automate Prometheus Datasource and Grafana Dashboard creation
-python automated-dashboard-datasource.py
+python automated_dashboard_datasource.py
index 4e8d630..62aa628 100644 (file)
@@ -10,18 +10,16 @@ import fileinput
 import re
 import logging
 import socket
-import requests
-from oslo_serialization import jsonutils
 
 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())
+    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())
+    ip = "    URL \"http://" + str(ip_address) + ":9103/collectd-post\""
+    line = re.sub(r'.*URL.*collectd-post.*', r'' + str(ip), line.rstrip())
     print(line)