Merge "Collectd"
[yardstick.git] / yardstick / network_services / nfvi / collectd.sh
1 #!/bin/bash
2 #
3 # Copyright (c) 2016-2017 Intel Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 INSTALL_NSB_BIN="/opt/nsb_bin"
18 cd $INSTALL_NSB_BIN
19
20 if [ "$(whoami)" != "root" ]; then
21         echo "Must be root to run $0"
22         exit 1;
23 fi
24
25 echo "setup proxy..."
26 http_proxy=$1
27 https_proxy=$2
28 if [[ "$http_proxy" != "" ]]; then
29     export http_proxy=$http_proxy
30     export https_proxy=$http_proxy
31 fi
32
33 if [[ "$https_proxy" != "" ]]; then
34     export https_proxy=$https_proxy
35 fi
36
37 echo "Install required libraries to run collectd..."
38 pkg=(git flex bison build-essential pkg-config automake  autotools-dev libltdl-dev librabbitmq-dev rabbitmq-server cmake)
39 for i in "${pkg[@]}"; do
40 dpkg-query -W --showformat='${Status}\n' "${i}"|grep "install ok installed"
41     if [  "$?" -eq "1" ]; then
42         apt-get -y install "${i}";
43     fi
44 done
45 echo "Done"
46
47 ldconfig -p | grep libpqos >/dev/null
48 if [ $? -eq 0 ]
49 then
50     echo "Intel RDT library already installed. Done"
51 else
52     pushd .
53
54     echo "Get intel_rdt repo and install..."
55     rm -rf intel-cmt-cat >/dev/null
56     git clone https://github.com/01org/intel-cmt-cat.git
57     pushd intel-cmt-cat
58     make install PREFIX=/usr
59     popd
60
61     popd
62     echo "Done."
63 fi
64
65 ls /usr/lib/libdpdk.so >/dev/null
66 if [ $? -eq 0 ]
67 then
68     echo "DPDK already installed. Done"
69 else
70     pushd .
71
72     echo "Get dpdk and install..."
73     mkdir -p $INSTALL_NSB_BIN
74     rm -rf "$INSTALL_NSB_BIN"/dpdk >/dev/null
75     git clone http://dpdk.org/git/dpdk
76     pushd dpdk
77     mkdir -p /mnt/huge
78     mount -t hugetlbfs nodev /mnt/huge
79     sed -i 's/CONFIG_RTE_BUILD_SHARED_LIB=n/CONFIG_RTE_BUILD_SHARED_LIB=y/g' config/common_base
80     sed -i 's/CONFIG_RTE_EAL_PMD_PATH=""/CONFIG_RTE_EAL_PMD_PATH="\/usr\/lib\/dpdk-pmd\/"/g' config/common_base
81
82                 echo "Build dpdk v16.04"
83                 make config T=x86_64-native-linuxapp-gcc
84                 make
85                 sudo make install prefix=/usr
86                 mkdir -p /usr/lib/dpdk-pmd
87                 find /usr/lib -type f -name 'librte_pmd*' | while read path ; do ln -s $path /usr/lib/dpdk-pmd/`echo $path | grep -o 'librte_.*so'` ;  done
88
89                 echo "Disable ASLR."
90                 echo 0 > /proc/sys/kernel/randomize_va_space
91     make install PREFIX=/usr
92     popd
93
94     popd
95     echo "Done."
96 fi
97
98 which $INSTALL_NSB_BIN/yajl > /dev/null
99 if [ -f "/usr/local/lib/libyajl.so.2.1.1" ]
100 then
101                                 echo "ovs stats libs already installed."
102 else
103                 echo "installing ovs stats libraries"
104                 pushd .
105
106                 cd $INSTALL_NSB_BIN
107                 git clone https://github.com/lloyd/yajl.git
108                 pushd yajl
109                 ./configure
110                 make
111                 make install
112                 popd
113
114     popd
115 fi
116
117 which $INSTALL_NSB_BIN/collectd/collectd >/dev/null
118 if [ $? -eq 0 ]
119 then
120     echo "Collectd already installed. Done"
121 else
122     pushd .
123     echo "Get collectd from repository and install..."
124     rm -rf collectd >/dev/null
125     git clone https://github.com/collectd/collectd.git
126     pushd collectd
127     git stash
128     git checkout -n nfvi 47c86ace348a1d7a5352a83d10935209f89aa4f5
129     ./build.sh
130     ./configure --with-libpqos=/usr/ --with-libdpdk=/usr --with-libyajl=/usr/local --enable-debug --enable-dpdkstat --enable-virt --enable-ovs_stats
131     make install > /dev/null
132     popd
133     echo "Done."
134     popd
135 fi
136
137 modprobe msr
138 cp $INSTALL_NSB_BIN/collectd.conf /opt/collectd/etc/
139
140 echo "Check if admin user already created"
141 rabbitmqctl list_users | grep '^admin$' > /dev/null
142 if [ $? -eq 0 ];
143 then
144     echo "'admin' user already created..."
145 else
146     echo "Creating 'admin' user for collectd data export..."
147     rabbitmqctl delete_user guest
148     rabbitmqctl add_user admin admin
149     rabbitmqctl authenticate_user admin admin
150     rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
151     echo "Done"
152 fi