Cadvisor Client-Server installation automation script 61/47161/4
authorRutuja Surve <rutuja.r.surve@gmail.com>
Tue, 14 Nov 2017 04:36:23 +0000 (04:36 +0000)
committerRutuja Surve <rutuja.r.surve@gmail.com>
Tue, 14 Nov 2017 04:43:55 +0000 (04:43 +0000)
JIRA: BOTTLENECK-181

Automated the installation for cadvisor client from
jump server host and added docker installation of cadvisor
in monitoring script.

Change-Id: I906b5237bc0ed320106309c1a29e8dd72a05a427
Signed-off-by: Rutuja Surve <rutuja.r.surve@gmail.com>
monitor/automate_cadvisor_client.py [new file with mode: 0644]
monitor/cadvisor_install.sh [new file with mode: 0644]
monitor/config/prometheus.yaml
monitor/monitoring.sh

diff --git a/monitor/automate_cadvisor_client.py b/monitor/automate_cadvisor_client.py
new file mode 100644 (file)
index 0000000..95b98e9
--- /dev/null
@@ -0,0 +1,37 @@
+##############################################################################
+# 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 sys
+import yaml
+sys.path.insert(0, '/home/opnfv/bottlenecks/utils/infra_setup/passwordless_SSH/')
+import ssh
+
+logger = logging.getLogger(__name__)
+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:
+                    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")
+                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/cadvisor_install.sh b/monitor/cadvisor_install.sh
new file mode 100644 (file)
index 0000000..524e24d
--- /dev/null
@@ -0,0 +1,10 @@
+sudo docker run \
+  --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 \
+  --name=cadvisor \
+  google/cadvisor:v0.25.0 \ -storage_driver=Prometheus
index 35bf040..3736d8e 100644 (file)
@@ -25,7 +25,15 @@ scrape_configs:
     scrape_interval: 5s
 
     static_configs:
-      - targets: ['192.168.104.2:9090']
+      - targets: ['192.168.121.2:9090']
+
+  - job_name: 'cadvisor'
+
+    # Override the global default and scrape targets from this job every 5 seconds.
+    scrape_interval: 5s
+
+    static_configs:
+      - targets: ['192.168.121.2:8080','10.1.0.50:8080','10.1.0.51:8080']
 
   - job_name: 'collectd'
 
@@ -33,7 +41,7 @@ scrape_configs:
     scrape_interval: 5s
 
     static_configs:
-      - targets: ['192.168.104.2:9103']
+      - targets: ['192.168.121.2:9103']
 
   - job_name: 'node'
 
@@ -41,4 +49,4 @@ scrape_configs:
     scrape_interval: 5s
 
     static_configs:
-      - targets: ['192.168.104.2:9100']
\ No newline at end of file
+      - targets: ['192.168.121.2:9100']
index b8409d4..16cb308 100644 (file)
@@ -48,3 +48,23 @@ sudo  docker run --name bottlenecks-grafana \
   -v ${GRAFANA}/config/grafana.ini:/etc/grafana/grafana.ini \
   grafana/grafana:4.5.0
 
+# Cadvisor
+sudo docker run \
+  --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 \
+  --name=cadvisor \
+  google/cadvisor:v0.25.0 \ -storage_driver=Prometheus
+
+# Automate Collectd Client
+python automate_collectd_client.py
+
+# Automate Cadvisor Client
+python automate_cadvisor_client.py
+
+# Automate Prometheus Datasource and Grafana Dashboard creation
+python automated-dashboard-datasource.py