Scripts for Prometheus & cAdvisor installation 70/870/3
authorabhijit_onap <abhijit.das.gupta@huawei.com>
Tue, 28 May 2019 14:37:38 +0000 (14:37 +0000)
committerabhijit_onap <abhijit.das.gupta@huawei.com>
Thu, 6 Jun 2019 13:40:50 +0000 (13:40 +0000)
Scripts to automate Prometheus and cAdvisor Installation
Prometheus will be installed in ELIOT Manager and
cAdvisor in the ELIOT Edge Node

1)prometheus.sh
2)generatePromeyml.sh
3)cadvisorsetup.sh

Signed-off-by: abhijit_onap <abhijit.das.gupta@huawei.com>
Change-Id: I6aa168603826d5358a9acce87f056f837e660d95

scripts/cadvisorsetup.sh [new file with mode: 0644]
scripts/generatePromeyml.sh [new file with mode: 0755]
scripts/prometheus.sh [new file with mode: 0755]

diff --git a/scripts/cadvisorsetup.sh b/scripts/cadvisorsetup.sh
new file mode 100644 (file)
index 0000000..1ceae4a
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 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
+##############################################################################
+
+HOSTNAME=`hostname`
+sudo docker run  \
+ --volume=/:/rootfs:ro \
+ --volume=/var/run:/var/run:ro \
+ --volume=/sys:/sys:ro \
+ --volume=/var/lib/docker/:/var/lib/docker:ro \
+ --volume=/dev/disk/:/dev/disk:ro \
+ --publish=8081:8080 \
+ --detach=true \
+ --name=cadvisor-${HOSTNAME} \
+ google/cadvisor:latest 
+
diff --git a/scripts/generatePromeyml.sh b/scripts/generatePromeyml.sh
new file mode 100755 (executable)
index 0000000..b986788
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 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
+##############################################################################
+
+promyml=~/prometheus.yml
+workernodeip=""
+blank=""
+count=1
+firstline=1
+while read line
+do
+  if [ $count -gt $firstline ]; then
+     workernodeip+="','"
+  fi
+  nodeinfo="${line}"
+  nodeip=$(echo ${nodeinfo} | cut -d"|" -f2)
+  echo $nodeip
+  workernodeip+=$nodeip
+  workernodeip+=":8081"
+  echo $workernodeip
+  count=2
+  echo $count
+done < nodelist
+
+echo "workernodeip="
+echo $workernodeip
+
+cat <<EOF > "${promyml}"
+---
+global:
+  scrape_interval: 15s
+
+scrape_configs:
+  - job_name: 'prometheus'
+    scrape_interval: 5s
+    static_configs:
+      - targets: ['localhost:9090']
+
+  - job_name: cadvisor
+    scrape_interval: 5s
+    static_configs:
+      - targets: ['$workernodeip']
+EOF
diff --git a/scripts/prometheus.sh b/scripts/prometheus.sh
new file mode 100755 (executable)
index 0000000..f2a3c17
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash -ex
+##############################################################################
+# Copyright (c) 2019 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
+##############################################################################
+
+# start
+PROMETHEUS_HOST_PORT="9090"
+PROMETHEUS_CONTAINTER_PORT="9090"
+#cp ci_management/prometheus.yml $HOME
+source generatePromeyml.sh
+if [ ! -d "/etc/prometheus" ]; then
+  sudo mkdir /etc/prometheus
+fi
+
+sudo docker run -p ${PROMETHEUS_HOST_PORT}:${PROMETHEUS_CONTAINTER_PORT} \
+     -v ~/prometheus.yml:/etc/prometheus/prometheus.yml \
+     -d prom/prometheus \
+     --config.file=/etc/prometheus/prometheus.yml