|
|
@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
from cement.core.controller import CementBaseController, expose |
|
|
|
from cement.core import handler, hook |
|
|
|
from ee.core.shellexec import EEShellExec |
|
|
|
from ee.core.shellexec import * |
|
|
|
from ee.core.mysql import EEMysql |
|
|
|
from ee.core.services import EEService |
|
|
|
from ee.core.logging import Log |
|
|
@ -32,6 +32,9 @@ class EEDebugController(CementBaseController): |
|
|
|
dict(help='Stop debug', action='store_true')), |
|
|
|
(['--start'], |
|
|
|
dict(help='Start debug', action='store_true')), |
|
|
|
(['--import-slow-log'], |
|
|
|
dict(help='Import MySQL slow log to Anemometer database', |
|
|
|
action='store_true')), |
|
|
|
(['--nginx'], |
|
|
|
dict(help='start/stop debugging nginx server ' |
|
|
|
'configuration for site', |
|
|
@ -268,21 +271,6 @@ class EEDebugController(CementBaseController): |
|
|
|
EEMysql.execute(self, "set global long_query_time = 2;") |
|
|
|
EEMysql.execute(self, "set global log_queries_not_using" |
|
|
|
"_indexes = \'ON\';") |
|
|
|
if self.app.pargs.interval: |
|
|
|
try: |
|
|
|
cron_time = int(self.app.pargs.interval) |
|
|
|
except Exception as e: |
|
|
|
cron_time = 5 |
|
|
|
|
|
|
|
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l " |
|
|
|
"2> /dev/null | {{ cat; echo -e" |
|
|
|
" \\\"#EasyEngine start MySQL " |
|
|
|
"slow log \\n*/{0} * * * * " |
|
|
|
"/usr/local/bin/ee " |
|
|
|
"import-slow-log\\n" |
|
|
|
"#EasyEngine end MySQL slow log" |
|
|
|
"\\\"; }} | crontab -\"" |
|
|
|
.format(cron_time)) |
|
|
|
else: |
|
|
|
Log.info(self, "MySQL slow log is already enabled") |
|
|
|
|
|
|
@ -494,13 +482,69 @@ class EEDebugController(CementBaseController): |
|
|
|
and (not self.app.pargs.fpm) and (not self.app.pargs.mysql) |
|
|
|
and (not self.app.pargs.wp) and (not self.app.pargs.rewrite) |
|
|
|
and (not self.app.pargs.all) |
|
|
|
and (not self.app.pargs.site_name)): |
|
|
|
and (not self.app.pargs.site_name) |
|
|
|
and (not self.app.pargs.import_slow_log) |
|
|
|
and (not self.app.pargs.interval)): |
|
|
|
if self.app.pargs.stop or self.app.pargs.start: |
|
|
|
print("--start/stop option is deprecated since ee3.0.5") |
|
|
|
self.app.args.print_help() |
|
|
|
else: |
|
|
|
self.app.args.print_help() |
|
|
|
|
|
|
|
if self.app.pargs.import_slow_log: |
|
|
|
self.import_slow_log() |
|
|
|
|
|
|
|
if self.app.pargs.interval: |
|
|
|
try: |
|
|
|
cron_time = int(self.app.pargs.interval) |
|
|
|
except Exception as e: |
|
|
|
cron_time = 5 |
|
|
|
|
|
|
|
try: |
|
|
|
if not EEShellExec.cmd_exec(self, "crontab -l | grep " |
|
|
|
"'ee debug --import-slow-log'"): |
|
|
|
if not cron_time == 0: |
|
|
|
Log.info(self, "setting up crontab entry," |
|
|
|
" please wait ...") |
|
|
|
EEShellExec.cmd_exec(self, "/bin/bash -c \"crontab -l " |
|
|
|
"2> /dev/null | {{ cat; echo -e" |
|
|
|
" \\\"#EasyEngine start MySQL " |
|
|
|
"slow log \\n*/{0} * * * * " |
|
|
|
"/usr/local/bin/ee debug" |
|
|
|
" --import-slow-log\\n" |
|
|
|
"#EasyEngine end MySQL slow log" |
|
|
|
"\\\"; }} | crontab -\"" |
|
|
|
.format(cron_time)) |
|
|
|
else: |
|
|
|
if not cron_time == 0: |
|
|
|
Log.info(self, "updating crontab entry," |
|
|
|
" please wait ...") |
|
|
|
if not EEShellExec.cmd_exec(self, "/bin/bash -c " |
|
|
|
"\"crontab " |
|
|
|
"-l | sed '/EasyEngine " |
|
|
|
"start MySQL slow " |
|
|
|
"log/!b;n;c\*\/{0} " |
|
|
|
"\* \* \* " |
|
|
|
"\* \/usr" |
|
|
|
"\/local\/bin\/ee debug " |
|
|
|
"--import\-slow\-log' " |
|
|
|
"| crontab -\"" |
|
|
|
.format(cron_time)): |
|
|
|
Log.error(self, "failed to update crontab entry") |
|
|
|
else: |
|
|
|
Log.info(self, "removing crontab entry," |
|
|
|
" please wait ...") |
|
|
|
if not EEShellExec.cmd_exec(self, "/bin/bash -c " |
|
|
|
"\"crontab " |
|
|
|
"-l | sed '/EasyEngine " |
|
|
|
"start MySQL slow " |
|
|
|
"log/,+2d'" |
|
|
|
"| crontab -\"" |
|
|
|
.format(cron_time)): |
|
|
|
Log.error(self, "failed to remove crontab entry") |
|
|
|
except CommandExecutionError as e: |
|
|
|
Log.debug(self, str(e)) |
|
|
|
|
|
|
|
if self.app.pargs.all == 'on': |
|
|
|
if self.app.pargs.site_name: |
|
|
|
self.app.pargs.wp = 'on' |
|
|
@ -569,6 +613,59 @@ class EEDebugController(CementBaseController): |
|
|
|
|
|
|
|
logwatch(self, watch_list) |
|
|
|
|
|
|
|
@expose(hide=True) |
|
|
|
def import_slow_log(self): |
|
|
|
"""Default function for import slow log""" |
|
|
|
if os.path.isdir("{0}22222/htdocs/db/anemometer" |
|
|
|
.format(EEVariables.ee_webroot)): |
|
|
|
if os.path.isfile("/var/log/mysql/mysql-slow.log"): |
|
|
|
# Get Anemometer user name and password |
|
|
|
Log.info(self, "Importing MySQL slow log to Anemometer") |
|
|
|
host = os.popen("grep -e \"\'host\'\" {0}22222/htdocs/" |
|
|
|
.format(EEVariables.ee_webroot) |
|
|
|
+ "db/anemometer/conf/config.inc.php " |
|
|
|
"| head -1 | cut -d\\\' -f4 | " |
|
|
|
"tr -d '\n'").read() |
|
|
|
user = os.popen("grep -e \"\'user\'\" {0}22222/htdocs/" |
|
|
|
.format(EEVariables.ee_webroot) |
|
|
|
+ "db/anemometer/conf/config.inc.php " |
|
|
|
"| head -1 | cut -d\\\' -f4 | " |
|
|
|
"tr -d '\n'").read() |
|
|
|
password = os.popen("grep -e \"\'password\'\" {0}22222/" |
|
|
|
.format(EEVariables.ee_webroot) |
|
|
|
+ "htdocs/db/anemometer/conf" |
|
|
|
"/config.inc.php " |
|
|
|
"| head -1 | cut -d\\\' -f4 | " |
|
|
|
"tr -d '\n'").read() |
|
|
|
|
|
|
|
# Import slow log Anemometer using pt-query-digest |
|
|
|
try: |
|
|
|
EEShellExec.cmd_exec(self, "pt-query-digest --user={0} " |
|
|
|
"--password={1} " |
|
|
|
"--review D=slow_query_log," |
|
|
|
"t=global_query_review " |
|
|
|
"--history D=slow_query_log,t=" |
|
|
|
"global_query_review_history " |
|
|
|
"--no-report --limit=0% " |
|
|
|
"--filter=\" \\$event->{{Bytes}} = " |
|
|
|
"length(\\$event->{{arg}}) " |
|
|
|
"and \\$event->{{hostname}}=\\\"" |
|
|
|
"{2}\\\"\" " |
|
|
|
"/var/log/mysql/mysql-slow.log" |
|
|
|
.format(user, password, host)) |
|
|
|
except CommandExecutionError as e: |
|
|
|
Log.debug(self, str(e)) |
|
|
|
Log.error(self, "MySQL slow log import failed.") |
|
|
|
else: |
|
|
|
Log.error(self, "MySQL slow log file not found," |
|
|
|
" so not imported slow logs") |
|
|
|
else: |
|
|
|
Log.error(self, " Anemometer is not installed." + |
|
|
|
Log.ENDC + " You can install Anemometer with " |
|
|
|
"this command " |
|
|
|
+ Log.BOLD + "\n `ee stack install --utils`" |
|
|
|
+ Log.ENDC) |
|
|
|
|
|
|
|
|
|
|
|
def load(app): |
|
|
|
# register the plugin class.. this only happens if the plugin is enabled |
|
|
|