Merge "vPE Sample VNF is missing in the installation scripts"
[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 INSTALL_NSB_BIN="/opt/nsb_bin"
17 cd $INSTALL_NSB_BIN
18
19 if [ "$(whoami)" != "root" ]; then
20         echo "Must be root to run $0"
21         exit 1;
22 fi
23
24 echo "setup proxy..."
25 if [[ -n $1 ]]; then
26     export http_proxy=$1
27     export https_proxy=$2
28 fi
29
30 if [[ -n $2 ]]; then
31     export https_proxy=$2
32 fi
33
34 echo "Install required libraries to run collectd..."
35 pkg=(git flex bison build-essential pkg-config automake  autotools-dev libltdl-dev librabbitmq-dev rabbitmq-server cmake libvirt-dev)
36 for i in "${pkg[@]}"; do
37 dpkg-query -W --showformat='${Status}\n' "${i}"|grep "install ok installed"
38     if [  "$?" -eq "1" ]; then
39         apt-get -y install "${i}";
40     fi
41 done
42 echo "Done"
43
44 if ldconfig -p | grep -q libpqos ; then
45     echo "Intel RDT library already installed. Done"
46 else
47     pushd .
48
49     echo "Get intel_rdt repo and install..."
50     rm -rf intel-cmt-cat >/dev/null
51     git clone https://github.com/01org/intel-cmt-cat.git
52
53     (cd intel-cmt-cat; make install PREFIX=/usr)
54
55     popd
56     echo "Done."
57 fi
58
59 if [[ -r /usr/lib/libdpdk.so ]]; then
60     echo "DPDK already installed. Done"
61 else
62     pushd .
63
64     echo "Get dpdk and install..."
65     mkdir -p $INSTALL_NSB_BIN
66     pushd dpdk-16.07
67     mkdir -p /mnt/huge
68     mount -t hugetlbfs nodev /mnt/huge
69     sed -i 's/CONFIG_RTE_BUILD_SHARED_LIB=n/CONFIG_RTE_BUILD_SHARED_LIB=y/g' config/common_base
70     sed -i 's/CONFIG_RTE_EAL_PMD_PATH=""/CONFIG_RTE_EAL_PMD_PATH="\/usr\/lib\/dpdk-pmd\/"/g' config/common_base
71
72                 echo "Build dpdk v16.07"
73                 make config T=x86_64-native-linuxapp-gcc
74                 make
75                 sudo make install prefix=/usr
76                 mkdir -p /usr/lib/dpdk-pmd
77                 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
78
79                 echo "Disable ASLR."
80                 echo 0 > /proc/sys/kernel/randomize_va_space
81     make install PREFIX=/usr
82     popd
83
84     popd
85     echo "Done."
86 fi
87
88 which $INSTALL_NSB_BIN/yajl > /dev/null
89 if [ -f "/usr/local/lib/libyajl.so.2.1.1" ]
90 then
91                                 echo "ovs stats libs already installed."
92 else
93                 echo "installing ovs stats libraries"
94                 pushd .
95
96                 cd $INSTALL_NSB_BIN
97                 git clone https://github.com/lloyd/yajl.git
98                 pushd yajl
99                 ./configure
100                 make
101                 make install
102                 popd
103
104     popd
105 fi
106
107 ls $INSTALL_NSB_BIN/pmu-tools >/dev/null
108 if [ $? -eq 0 ]
109 then
110     echo "DPDK already installed. Done"
111 else
112     cd $INSTALL_NSB_BIN
113
114     git clone https://github.com/andikleen/pmu-tools.git
115     cd pmu-tools
116     cd jevents
117     sed -i -e 's/CFLAGS := -g -Wall -O2 -Wno-unused-result/CFLAGS := -g -Wall -O2 -Wno-unused-result -fPIC/g'  Makefile
118     make
119     sudo make install
120     cd $INSTALL_NSB_BIN/pmu-tools
121     python event_download.py
122 fi
123
124 cd $INSTALL_NSB_BIN
125 which $INSTALL_NSB_BIN/collectd/collectd >/dev/null
126 if [ $? -eq 0 ]
127 then
128     echo "Collectd already installed. Done"
129 else
130     pushd .
131     echo "Get collectd from repository and install..."
132     rm -rf collectd >/dev/null
133     git clone https://github.com/collectd/collectd.git
134     pushd collectd
135     git stash
136     ./build.sh
137     ./configure --with-libpqos=/usr/ --with-libdpdk=/usr --with-libyajl=/usr/local --with-libjevents=/usr/local --enable-debug --enable-dpdkstat --enable-virt --enable-ovs_stats --enable-intel_pmu --prefix=$INSTALL_NSB_BIN/collectd
138     make install > /dev/null
139     popd
140     echo "Done."
141     popd
142 fi
143
144 modprobe msr
145 # we overwrite the config file during _start_collectd so don't copy it
146 #cp $INSTALL_NSB_BIN/collectd.conf /opt/nsb_bin/collectd/etc/
147 sudo service rabbitmq-server restart
148 echo "Check if admin user already created"
149 rabbitmqctl list_users | grep '^admin$' > /dev/null
150 if [ $? -eq 0 ];
151 then
152     echo "'admin' user already created..."
153 else
154     echo "Creating 'admin' user for collectd data export..."
155     rabbitmqctl delete_user guest
156     rabbitmqctl add_user admin admin
157     rabbitmqctl authenticate_user admin admin
158     rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
159     echo "Done"
160 fi