ILIAS-7-Install-Tutorial for Ubuntu 20.04

Monitoring script (CPU-load)

Preparing the BBB servers

  • We ssh to every BBB server we want to monitore. The goal is that there is a file in the www-root with the cpu load information that we will read in another step (data transfer via SSH). Repeat this step with every server you want to monitor.
  • apt install sysstat
  • Give this projekt a name. Example: turn1.kivinet.de
  • Create the projectpath: mkdir -p /opt/scripts/turn1.kivinet.de
  • nano /opt/scripts/getload.sh
  • Paste the following code in:
1
2
3
4
5
6
7
#!/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/bin/X11:

#What is your path were the file cpuload can be accessible through www? - no trailing /
projectpath=/opt/scripts/turn1.kivinet.de

mpstat 1 1 | grep "all" | awk '{ print 100 - $NF; exit; }' > ${projectpath}/cpuload.txt
  • Change line 5 with your project name
  • Exit with STRG + x
  • chmod +x /opt/scripts/getload.sh
  • nano /etc/crontab
  • Paste this line in before the #
1
*/1 *   * * *   root    /opt/scripts/getload.sh > /dev/null 2>&1
  • cd /opt/scripts/turn1.kivinet.de
  • Wait a minute or trigger the script manually. Is there a file called cpuload.txt? ls
  • What is the content of this file (zero is OK if the server has more or less no load)? cat cpuload.txt

Perform a siege stresstest

  • apt install siege
  • siege localhost -c 999    <-- -c means the numer of users.
  • cat cpuload
  • The number should raise
  • Stop siege with STRG+C

Prepare the ILIAS server

Get the external data to your host server

  • We use SSH for this. I use the dirty method with sshpass. Maybe you like SSH key instead.
  • apt install sshpass
  • mkdir /opt/tmp
  • nano /opt/scripts/getserverload
  • Paste this in and enter your credentials and paths. Add all servers as I show in this example:
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
#!/bin/bash

for ((i=1;i<=30;i++));

do

#1
pass=PASSWORD
port=22
user=root
host=turn1.kivinet.de
projectpath=/opt/scripts/turn1.kivinet.de
localpath=/opt/tmp/

echo ${projectpath}
sshpass -p "${pass}" rsync -av --rsh=ssh --progress -e "ssh -T -o Compression=no -x -p ${port}" ${user}@${host}:${projectpath} ${localpath}

#2
pass=PASSWORD
port=22
user=root
host=turn2.kivinet.de
projectpath=/opt/scripts/turn1.kivinet.de
localpath=/opt/tmp/

echo ${projectpath}
sshpass -p "${pass}" rsync -av --rsh=ssh --progress -e "ssh -T -o Compression=no -x -p ${port}" ${user}@${host}:${projectpath} ${localpath}

#3
#...



sleep 2;

: $i;

done
  • STRG + x
  • chmod +x /opt/scripts/getserverload
  • Add SSH-Fingerprint:
    • ssh remoteip/host
    • Fingerprint: say yes
    • Cancel SHH with STRC + C
  • Test the script: /opt/scripts/getserverload
  • nano /etc/crontab
  • Paste this line in: 
1
*/1 *   * * *   root   /opt/scripts/getserverload> /dev/null 2>&

Install the charts program

  • SSH to your ILIAS server
  • cd /var/www/html
  • mkdir charts
  • cd charts
  • npm install chart.js --save
  • nano extdata.php
  • Paste this code in:
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
<?php
$wwwpath="/var/www/html/charts";
$extdataloc = array();
$barsvalues = array();
$string = "";
 
 
//No trailing / - paste hier your server URLs in
$extdataloc[0] = "/opt/tmp/[project1]/cpuload.txt";
$extdataloc[1] = "/opt/tmp/[project2]/cpuload.txt";
 
 
$ac = 0;
$ac = count($extdataloc);
for ($i = 0; $i<$ac;$i++)
{
$barsvalues[$i] = file_get_contents($extdataloc[$i]);
echo $barsvalues[$i];
if ($barsvalues[$i] < 1)
{
$barsvalues[$i] = 1;
}
 
}
 
$string = implode(",", $barsvalues);
$string = "[".$string."]";
$string = str_replace("\n", "", $string);
echo $string;
file_put_contents("${wwwpath}/input_data.json", $string);
?>
  • Exit with STRG + x
  • nano chart.html
  • Paste the following code in:
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
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>Ressourcenmonitor</title>
<style>
.chart_container {
margin: auto;
position: relative;
height: 60rem;
width: 60vw;
}
</style>
</head>

<body>
<div class="chart-container">
<canvas id="myChart"></canvas>
</div>
<script src="./node_modules/chart.js/dist/Chart.min.js"></script>
<script type="module">
import KivinetChart from "./ilias_chart.js";
const ctx = document.getElementById('myChart');
new KivinetChart(ctx);
</script>
</body>

</html>
  • Exit with STRG + x
  • nano ilias_chart.js
  • Paste the following code in:
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
const data_url = "./input_data.json";
const update_interval_ms = 2000;

const kivinet_chart_definition = {
type: 'bar',
data: {
// Hier Anzahl Server erhöhen, einfach einen einfügen
labels: ['BBB-Server 1 (ZEV)',
'BBB-Server 2 (ZEV)',
'BBB-Server 3 (ROW)',
'BBB-Server 4 (BRV)',
'Kivinet (ZEV)',
'Turn-Server'],
datasets: [{
label: '',
data: [1, 1, 1, 1, 1, 1],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
legend: {
display: false,
},
responsive: true,
title: {
display: true,
text: 'Auslastung unserer Server'
},
layout: {
padding: {
left: 50,
right: 50,
top: 50,
bottom: 50
}
},
scales: {
yAxes: [{
ticks: {
min: 0,
max: 100,
callback: function (value, index, values) {
return value + '%';
}
}
}]
}
}
}

class KivinetChart {
constructor(ctx) {
this.chart = new Chart(ctx, kivinet_chart_definition);
this.on_timer_fetch_data();
setInterval(() => this.on_timer_fetch_data(), update_interval_ms);
}

update_chart(new_data) {
this.chart.data.datasets[0].data = new_data;
this.chart.update();
}

on_timer_fetch_data() {
fetch(data_url)
.then(response => response.json())
.then(data => this.update_chart(data));
}
}


export default KivinetChart;
  • Exit with STRG + x

Set the cronjob to update the chart

  • nano sleep.sh
  • Paste the following code in:
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
wwwpath=/var/www/html/charts
for ((i=1;i<=30;i++));

do

/usr/bin/php ${wwwpath}/extdata.php;

sleep 2;

: $i;

done
  • chmod +x -R /var/www/html/charts
  • nano /etc/crontab
1
*/1 *   * * *   root   /var/www/html/charts/sleep.sh > /dev/null 2>&1
  • https://youriliasserver.com/charts/chart.html


No comment has been posted yet.