This commit is contained in:
PaulVua
2025-01-12 17:12:58 +01:00
parent e0fbdef138
commit ddbd85a035
3 changed files with 169 additions and 89 deletions

View File

@@ -59,9 +59,12 @@
<div class="card-body"> <div class="card-body">
<h5 class="card-title">Linux stats</h5> <h5 class="card-title">Linux stats</h5>
<p class="card-text">Disk space </p> <p class="card-text">Disk usage (total size <span id="disk_size"></span> Gb) </p>
<div id="disk_space"></div> <div id="disk_space"></div>
<p class="card-text">Memory usage (total size <span id="memory_size"></span> Mb) </p>
<div id="memory_space"></div>
</div> </div>
</div> </div>
</div> </div>
@@ -130,14 +133,19 @@ window.onload = function() {
method: 'GET', // Use GET or POST depending on your needs method: 'GET', // Use GET or POST depending on your needs
success: function(response) { success: function(response) {
console.log("Linux disk space: " + response); console.log("Linux disk space: " + response);
const match = response.match(/(\d+)%/); //1. disk size
const disk_size = document.getElementById("disk_size");
const firstNumber = response.match(/(?<!\w)(\d+(\.\d+)?)(?=\D)/)[1];
disk_size.innerHTML = firstNumber;
//2. Free space
const match = response.match(/(\d+)%/);
const diskSpace = document.getElementById("disk_space"); const diskSpace = document.getElementById("disk_space");
const percentage = match[1]; const percentage = match[1];
// Create the outer div with class and attributes // Create the outer div with class and attributes
const progressDiv = document.createElement('div'); const progressDiv = document.createElement('div');
progressDiv.className = 'progress'; progressDiv.className = 'progress mb-3';
progressDiv.setAttribute('role', 'progressbar'); progressDiv.setAttribute('role', 'progressbar');
progressDiv.setAttribute('aria-label', 'Example with label'); progressDiv.setAttribute('aria-label', 'Example with label');
progressDiv.setAttribute('aria-valuenow', percentage); progressDiv.setAttribute('aria-valuenow', percentage);
@@ -162,6 +170,64 @@ window.onload = function() {
} }
}); });
//get memory free space
$.ajax({
url: 'launcher.php?type=linux_memory',
dataType: 'text', // Specify that you expect a JSON response
method: 'GET', // Use GET or POST depending on your needs
success: function(response) {
console.log("Linux memory space: " + response);
//1. memory size
const memory_size = document.getElementById("memory_size");
const memorySpace = document.getElementById("memory_space");
const memLine = response.match(/Mem:\s+(\d+\.?\d*)Mi\s+(\d+\.?\d*)Mi/);
const totalMemory = parseFloat(memLine[1]); // Total memory in MiB
const usedMemory = parseFloat(memLine[2]); // Used memory in MiB
// Calculate the percentage
const percentageUsed = ((usedMemory / totalMemory) * 100).toFixed(2);
console.log(totalMemory);
memory_size.innerHTML = totalMemory;
console.log(usedMemory);
console.log(percentageUsed);
// Create the outer div with class and attributes
const progressDiv = document.createElement('div');
progressDiv.className = 'progress mb-3';
progressDiv.setAttribute('role', 'progressbar');
progressDiv.setAttribute('aria-label', 'Example with label');
progressDiv.setAttribute('aria-valuenow', percentageUsed);
progressDiv.setAttribute('aria-valuemin', 0);
progressDiv.setAttribute('aria-valuemax', 100);
// Create the inner progress bar div
const progressBarDiv = document.createElement('div');
progressBarDiv.className = 'progress-bar';
progressBarDiv.style.width = `${percentageUsed}%`; // Set the width dynamically
progressBarDiv.textContent = `${percentageUsed}%`; // Set the text dynamically
// Append the progress bar to the outer div
progressDiv.appendChild(progressBarDiv);
// Append the entire progress bar to the body (or any other container)
memorySpace.appendChild(progressDiv);
},
error: function(xhr, status, error) {
console.error('AJAX request failed:', status, error);
}
});
}) })
.catch(error => console.error('Error loading config.json:', error)); .catch(error => console.error('Error loading config.json:', error));
} }

View File

@@ -18,6 +18,12 @@ if ($type == "linux_disk") {
echo $output; echo $output;
} }
if ($type == "linux_memory") {
$command = 'free -h';
$output = shell_exec($command);
echo $output;
}
if ($type == "sshTunnel") { if ($type == "sshTunnel") {
$ssh_port=$_GET['ssh_port']; $ssh_port=$_GET['ssh_port'];
$command = 'sudo ssh -i /var/www/.ssh/id_rsa -f -N -R "'.$ssh_port.':localhost:22" -p 50221 -o StrictHostKeyChecking=no "airlab_server1@aircarto.fr"'; $command = 'sudo ssh -i /var/www/.ssh/id_rsa -f -N -R "'.$ssh_port.':localhost:22" -p 50221 -o StrictHostKeyChecking=no "airlab_server1@aircarto.fr"';

View File

@@ -115,6 +115,7 @@ config_file = '/var/www/nebuleair_pro_4g/config.json'
# Load the configuration data # Load the configuration data
config = load_config(config_file) config = load_config(config_file)
# Access the shared variables # Access the shared variables
baudrate = config.get('SaraR4_baudrate', 115200) #baudrate du sara R4 baudrate = config.get('SaraR4_baudrate', 115200) #baudrate du sara R4
device_id = config.get('deviceID', '').upper() #device ID en maj device_id = config.get('deviceID', '').upper() #device ID en maj
@@ -123,6 +124,7 @@ bme_280_config = config.get('i2c_BME', False) #présence du BME280
i2C_sound_config = config.get('i2C_sound', False) #présence du capteur son i2C_sound_config = config.get('i2C_sound', False) #présence du capteur son
envea_sondes = config.get('envea_sondes', []) envea_sondes = config.get('envea_sondes', [])
connected_envea_sondes = [sonde for sonde in envea_sondes if sonde.get('connected', False)] connected_envea_sondes = [sonde for sonde in envea_sondes if sonde.get('connected', False)]
selected_networkID = config.get('SARA_R4_neworkID', '')
ser_sara = serial.Serial( ser_sara = serial.Serial(
port='/dev/ttyAMA2', port='/dev/ttyAMA2',
@@ -293,7 +295,7 @@ try:
command= f'AT+UHTTPC=0,4,"/pro_4G/data.php?sensor_id={device_id}","server_response.txt","sensordata.json",4\r' command= f'AT+UHTTPC=0,4,"/pro_4G/data.php?sensor_id={device_id}","server_response.txt","sensordata.json",4\r'
ser_sara.write((command + '\r').encode('utf-8')) ser_sara.write((command + '\r').encode('utf-8'))
response_SARA_3 = read_complete_response(ser_sara) response_SARA_3 = read_complete_response(ser_sara)
if need_to_log:
print("Send data:") print("Send data:")
print(response_SARA_3) print(response_SARA_3)
@@ -328,6 +330,12 @@ try:
# need to reconnect to network # need to reconnect to network
# and reset HTTP profile (AT+UHTTP=0) -> ne fonctionne pas.. # and reset HTTP profile (AT+UHTTP=0) -> ne fonctionne pas..
# tester un reset avec CFUN 15 # tester un reset avec CFUN 15
# 1.Reconnexion au réseau (AT+COPS)
command = f'AT+COPS=1,2,{selected_networkID}\r'
ser_sara.write((command + '\r').encode('utf-8'))
responseReconnect = read_complete_response(ser_sara)
print("Response:")
print(responseReconnect)
elif "Operation not allowed" in lines[-1]: elif "Operation not allowed" in lines[-1]:
print("Operation not allowed. This may require a different configuration.") print("Operation not allowed. This may require a different configuration.")