-
Notifications
You must be signed in to change notification settings - Fork 1
/
monitor.yml
278 lines (198 loc) · 6.02 KB
/
monitor.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
##installation of Monitoring Tools (sFlow-RT) and all the dependencies
---
- hosts: sflow_machine
become: yes
become_method: sudo
become_user: root
tasks:
- name: Update package lists
apt:
update_cache: yes
- name: Get home directory of the user
shell: "getent passwd {{ ansible_user }} | cut -d: -f6"
register: user_home
- name: Print home directory
debug:
var: user_home.stdout
- name: Install required packages
apt:
name: "{{ item }}"
state: present
loop:
- gcc
- perl
- make
- terminator
- openjdk-11-jdk
- git
- git-review
- zip
- curl
- unzip
- bzip2
- python2-dev
- python-setuptools
- python3-dev
- python3-setuptools
- python3-pip
- xterm
- default-jdk
- python3
- snapd
- name: Install Docker dependencies
apt:
name: "{{ item }}"
state: present
loop:
- apt-transport-https
- ca-certificates
- curl
- gnupg
- software-properties-common
- lsb-release
- name: Create directory for Docker keyring
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Download Docker GPG key
get_url:
url: https://download.docker.com/linux/ubuntu/gpg
dest: /etc/apt/keyrings/docker.gpg
mode: '0644'
- name: Debug before adding GPG key
debug:
msg: "Before adding GPG key"
- name: Add Docker GPG key to apt keyring
shell: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- name: Debug after adding GPG key
debug:
msg: "After adding GPG key"
- name: Add Docker repository
lineinfile:
path: /etc/apt/sources.list.d/docker.list
line: "deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
create: yes
- name: Update package lists again
apt:
update_cache: yes
- name: Install Docker packages
apt:
name: "{{ item }}"
state: present
loop:
- docker-ce
- docker-ce-cli
- containerd.io
- name: Add Java environment variables
lineinfile:
dest: /etc/environment
line: |
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
JRE_HOME=/usr/lib/jvm/java-11-openjdk-amd64/jre
- name: Gather package facts
package_facts:
manager: apt
- name: Install Python
apt:
name: python
state: present
- name: Download get-pip.py
get_url:
url: https://bootstrap.pypa.io/pip/2.7/get-pip.py
dest: /tmp/get-pip.py
when: ansible_distribution_major_version|int == 16
- name: Install pip for Python 2
command: python2 /tmp/get-pip.py
when: ansible_distribution_major_version|int == 16
- name: Update Package Manager
command: sudo apt update
- name: Install python3-pip
apt:
name: python3-pip
state: present
- name: Upgrade pip for Python 3
pip:
name: pip
state: latest
executable: pip3
- name: Ensure Docker service is running
service:
name: docker
state: started
- name: Install Portainer
shell: |
sudo docker rm -f portainer
sudo docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:2.9.3
- name: Download sFlow-RT tarball
get_url:
url: http://www.inmon.com/products/sFlow-RT/sflow-rt.tar.gz
dest: "{{ user_home.stdout }}/sflow-rt.tar.gz"
- name: Create sFlow-RT directory
become: yes
file:
path: "{{ user_home.stdout }}/sflow-rt"
state: directory
- name: Extract sFlow-RT tarball
become: yes
unarchive:
src: "{{ user_home.stdout }}/sflow-rt.tar.gz"
dest: "{{ user_home.stdout }}/sflow-rt"
remote_src: yes
extra_opts: "--strip-components=1"
- name: Install required sFlow-RT applications
shell: "{{ user_home.stdout }}/sflow-rt/get-app.sh sflow-rt {{ item }}"
args:
chdir: "{{ user_home.stdout }}/sflow-rt"
loop:
- browse-metrics
- active-routes
- browse-drops
- browse-flows
- ddos-protect
- fabric-metrics
- ixp-metrics
- mininet-dashboard
- particle
- prometheus
- sflow-test
- sunburst
- topology
- trace-flow
- world-map
- dashboard-example
- name: Install Java
apt:
name: openjdk-11-jre-headless
state: present
- name: Debug - Before starting sFlow-RT
debug:
msg: "About to start sFlow-RT script"
- name: Start sFlow-RT in the background
shell: "nohup {{ user_home.stdout }}/sflow-rt/start.sh > /dev/null 2>&1 &"
- name: Debug - After starting sFlow-RT
debug:
msg: "sFlow-RT script started successfully"
- name: Create a data directory
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ user_home.stdout }}/data"
- name: Create prometheus.yml file
ansible.builtin.template:
src: prometheus.yml.j2
dest: "{{ user_home.stdout }}/prometheus.yml"
vars:
user_home: "{{ lookup('env', 'HOME') }}"
- name: Install prometheus as a container
shell: |
sudo docker rm -f prometheus-sflow
sudo docker run -d --user root --name prometheus-sflow --rm -v {{ user_home.stdout }}/data:/prometheus -v {{ user_home.stdout }}/prometheus.yml:/etc/prometheus/prometheus.yml -p 9090:9090 prom/prometheus
- name: Install grafana as a container
shell: |
sudo docker rm -f grafana
sudo docker run -d -p 3000:3000 --name=grafana grafana/grafana-oss