pfSense Gold Subscription

Author Topic: Unofficial E2guardian package for pfSense  (Read 14226 times)

0 Members and 1 Guest are viewing this topic.

Offline empbilly

  • Hero Member
  • *****
  • Posts: 826
  • Karma: +35/-5
  • Jesus é Senhor!
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #555 on: August 12, 2017, 11:46:06 am »
I am also using the e2guardian and in a matter of hours the "memory ram" and swap are skyrocketing. I modified the script that marcelloc suggested in some posts above and when it restarts the service, for example 90% and 75% respectively, the values fall to 50% for memory and normalize the swap.

Offline pfsensation

  • Full Member
  • ***
  • Posts: 201
  • Karma: +2/-0
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #556 on: August 12, 2017, 11:55:53 am »
I am also using the e2guardian and in a matter of hours the "memory ram" and swap are skyrocketing. I modified the script that marcelloc suggested in some posts above and when it restarts the service, for example 90% and 75% respectively, the values fall to 50% for memory and normalize the swap.

Can you share your script? This is driving me insane now...

Offline empbilly

  • Hero Member
  • *****
  • Posts: 826
  • Karma: +35/-5
  • Jesus é Senhor!
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #557 on: August 12, 2017, 01:46:44 pm »
Script by remzej
Original: https://forum.pfsense.org/index.php?topic=126309.msg727239#msg727239

Modified:

Code: [Select]
#!/usr/local/bin/php-cgi -q
<?php
/*
 * monitor_memory_usage.php
 *
 * part of pfSense (https://www.pfsense.org)
 * Copyright (c) 2011-2015 Rubicon Communications, LLC (Netgate)
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once('config.inc');
require_once(
'util.inc');
require_once(
'squid.inc');
require_once(
'e2guardian.inc');
global 
$config;

// Monitor memory usage by remzej
// Get SWAP usage funtion
function swap_usage() {
exec("/usr/sbin/swapinfo"$swap_info);
$swap_used "";
foreach ($swap_info as $line) {
if (preg_match('/(\d+)%$/'$line$matches)) {
$swap_used $matches[1];
break;
}
}
return $swap_used;
}

// Get memory usage function
function mem_usage() {
$memory "";
exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " .
"vm.stats.vm.v_cache_count vm.stats.vm.v_free_count"$memory);

$totalMem $memory[0];
$availMem $memory[1] + $memory[2] + $memory[3];
$usedMem $totalMem $availMem;
$memUsage round(($usedMem 100) / $totalMem0);

return $memUsage;
}

// Get memory and SWAP usage value
$memusage_pct mem_usage();
$swapusage_pct swap_usage();

// Display memory usage
echo "Memory Usage: " $memusage_pct "%" PHP_EOL;
echo "SWAP Usage: " $swapusage_pct "%" PHP_EOL;

// If memory usage is above 90% and SWAP usage is above 75%, stop and restart squid services.  
if ((($memusage_pct 70) && ($swapusage_pct 50)) || ($memusage_pct 55) ) {
// stop e2g service
exec("/usr/local/sbin/e2guardian stop");
// stop squid service
squid_stop_monitor();
if (is_service_running('squid')) {
stop_service("squid");
}
                
// start e2g service
exec("/usr/local/sbin/e2guardian start");
// start squid service
                
squid_restart_services();
log_error(gettext(sprintf("[squid] Memory usage is $memusage_pct percent and SWAP usage is $swapusage_pct percent, stopping and restarting services.")));
}
?>


Offline pfsensation

  • Full Member
  • ***
  • Posts: 201
  • Karma: +2/-0
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #558 on: August 12, 2017, 04:40:42 pm »
Script by remzej
Original: https://forum.pfsense.org/index.php?topic=126309.msg727239#msg727239

Modified:

Code: [Select]
#!/usr/local/bin/php-cgi -q
<?php
/*
 * monitor_memory_usage.php
 *
 * part of pfSense (https://www.pfsense.org)
 * Copyright (c) 2011-2015 Rubicon Communications, LLC (Netgate)
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once('config.inc');
require_once(
'util.inc');
require_once(
'squid.inc');
require_once(
'e2guardian.inc');
global 
$config;

// Monitor memory usage by remzej
// Get SWAP usage funtion
function swap_usage() {
exec("/usr/sbin/swapinfo"$swap_info);
$swap_used "";
foreach ($swap_info as $line) {
if (preg_match('/(\d+)%$/'$line$matches)) {
$swap_used $matches[1];
break;
}
}
return $swap_used;
}

// Get memory usage function
function mem_usage() {
$memory "";
exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " .
"vm.stats.vm.v_cache_count vm.stats.vm.v_free_count"$memory);

$totalMem $memory[0];
$availMem $memory[1] + $memory[2] + $memory[3];
$usedMem $totalMem $availMem;
$memUsage round(($usedMem 100) / $totalMem0);

return $memUsage;
}

// Get memory and SWAP usage value
$memusage_pct mem_usage();
$swapusage_pct swap_usage();

// Display memory usage
echo "Memory Usage: " $memusage_pct "%" PHP_EOL;
echo "SWAP Usage: " $swapusage_pct "%" PHP_EOL;

// If memory usage is above 90% and SWAP usage is above 75%, stop and restart squid services.  
if ((($memusage_pct 70) && ($swapusage_pct 50)) || ($memusage_pct 55) ) {
// stop e2g service
exec("/usr/local/sbin/e2guardian stop");
// stop squid service
squid_stop_monitor();
if (is_service_running('squid')) {
stop_service("squid");
}
                
// start e2g service
exec("/usr/local/sbin/e2guardian start");
// start squid service
                
squid_restart_services();
log_error(gettext(sprintf("[squid] Memory usage is $memusage_pct percent and SWAP usage is $swapusage_pct percent, stopping and restarting services.")));
}
?>


Thanks! I see you left the code for Squid there too, is there really a need to kill off squid too? From what I've seen, restarting E2 Guardian works just fine.

Offline empbilly

  • Hero Member
  • *****
  • Posts: 826
  • Karma: +35/-5
  • Jesus é Senhor!
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #559 on: August 12, 2017, 05:14:05 pm »
Script by remzej
Original: https://forum.pfsense.org/index.php?topic=126309.msg727239#msg727239

Modified:

Code: [Select]
#!/usr/local/bin/php-cgi -q
<?php
/*
 * monitor_memory_usage.php
 *
 * part of pfSense (https://www.pfsense.org)
 * Copyright (c) 2011-2015 Rubicon Communications, LLC (Netgate)
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once('config.inc');
require_once(
'util.inc');
require_once(
'squid.inc');
require_once(
'e2guardian.inc');
global 
$config;

// Monitor memory usage by remzej
// Get SWAP usage funtion
function swap_usage() {
exec("/usr/sbin/swapinfo"$swap_info);
$swap_used "";
foreach ($swap_info as $line) {
if (preg_match('/(\d+)%$/'$line$matches)) {
$swap_used $matches[1];
break;
}
}
return $swap_used;
}

// Get memory usage function
function mem_usage() {
$memory "";
exec("/sbin/sysctl -n vm.stats.vm.v_page_count vm.stats.vm.v_inactive_count " .
"vm.stats.vm.v_cache_count vm.stats.vm.v_free_count"$memory);

$totalMem $memory[0];
$availMem $memory[1] + $memory[2] + $memory[3];
$usedMem $totalMem $availMem;
$memUsage round(($usedMem 100) / $totalMem0);

return $memUsage;
}

// Get memory and SWAP usage value
$memusage_pct mem_usage();
$swapusage_pct swap_usage();

// Display memory usage
echo "Memory Usage: " $memusage_pct "%" PHP_EOL;
echo "SWAP Usage: " $swapusage_pct "%" PHP_EOL;

// If memory usage is above 90% and SWAP usage is above 75%, stop and restart squid services.  
if ((($memusage_pct 70) && ($swapusage_pct 50)) || ($memusage_pct 55) ) {
// stop e2g service
exec("/usr/local/sbin/e2guardian stop");
// stop squid service
squid_stop_monitor();
if (is_service_running('squid')) {
stop_service("squid");
}
                
// start e2g service
exec("/usr/local/sbin/e2guardian start");
// start squid service
                
squid_restart_services();
log_error(gettext(sprintf("[squid] Memory usage is $memusage_pct percent and SWAP usage is $swapusage_pct percent, stopping and restarting services.")));
}
?>


Thanks! I see you left the code for Squid there too, is there really a need to kill off squid too? From what I've seen, restarting E2 Guardian works just fine.

So, I ended up just adding the e2g block. :D

Offline pfsensation

  • Full Member
  • ***
  • Posts: 201
  • Karma: +2/-0
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #560 on: August 13, 2017, 12:09:04 pm »
I'm starting to experience system dumps again. Anyone else experiencing the same? Very strange... I've already clean installed.

Offline marcelloc

  • Hero Member
  • *****
  • Posts: 13319
  • Karma: +572/-6
    • View Profile
Re: Unofficial E2guardian package for pfSense
« Reply #561 on: August 14, 2017, 04:15:46 pm »
I'm starting to experience system dumps again. Anyone else experiencing the same? Very strange... I've already clean installed.

I've compiled the binaries again with the little changes from previous 4.1.2_2 we were using to 4.1.3. I don't expect any change on process behavior from last update but I've compiled it anyway to keep this project with the latest updates from e2guardian.