Browse Source

ee import-slow-log done

bugfixes
gau1991 10 years ago
parent
commit
5da7d3462a
  1. 8
      config/plugins.d/import_slow_log.conf
  2. 2
      ee/cli/bootstrap.py
  3. 26
      ee/cli/controllers/isl.py
  4. 61
      ee/cli/plugins/import_slow_log.py

8
config/plugins.d/import_slow_log.conf

@ -0,0 +1,8 @@
### Example Plugin Configuration for EasyEngine
[import_slow_log]
### If enabled, load a plugin named `example` either from the Python module
### `ee.cli.plugins.example` or from the file path
### `/var/lib/ee/plugins/example.py`
enable_plugin = true

2
ee/cli/bootstrap.py

@ -5,9 +5,7 @@
from cement.core import handler
from ee.cli.controllers.base import EEBaseController
from ee.cli.controllers.isl import EEImportslowlogController
def load(app):
handler.register(EEBaseController)
handler.register(EEImportslowlogController)

26
ee/cli/controllers/isl.py

@ -1,26 +0,0 @@
from cement.core.controller import CementBaseController, expose
class EEImportslowlogController(CementBaseController):
class Meta:
label = 'import_slow_log'
stacked_on = 'base'
stacked_type = 'nested'
description = 'info command used for debugging issued with stack or \
site specific configuration'
arguments = [
(['--mysql'],
dict(help='get mysql configuration information',
action='store_true')),
(['--php'],
dict(help='get php configuration information',
action='store_true')),
(['--nginx'],
dict(help='get nginx configuration information',
action='store_true')),
]
@expose(hide=True)
def default(self):
# TODO Default action for ee debug command
print("Inside EEImportslowlogController.default().")

61
ee/cli/plugins/import_slow_log.py

@ -0,0 +1,61 @@
from cement.core.controller import CementBaseController, expose
from cement.core import handler, hook
from ee.core.shellexec import EEShellExec
from ee.core.logging import Log
import os
def import_slow_log_plugin_hook(app):
pass
class EEImportslowlogController(CementBaseController):
class Meta:
label = 'import_slow_log'
stacked_on = 'base'
stacked_type = 'nested'
description = 'Import MySQL slow log to Anemometer database'
@expose(hide=True)
def default(self):
if os.path.isdir("/var/www/22222/htdocs/db/anemometer"):
if os.path.isfile("/var/log/mysql/mysql-slow.log"):
# Get Anemometer user name and password
host = os.popen("grep -e \"\'host\'\" /var/www/22222/htdocs/"
"db/anemometer/conf/config.inc.php "
"| head -1 | cut -d\\\' -f4 | "
"tr -d '\n'").read()
user = os.popen("grep -e \"\'user\'\" /var/www/22222/htdocs/"
"db/anemometer/conf/config.inc.php "
"| head -1 | cut -d\\\' -f4 | "
"tr -d '\n'").read()
password = os.popen("grep -e \"\'password\'\" /var/www/22222/"
"htdocs/db/anemometer/conf/config.inc.php "
"| head -1 | cut -d\\\' -f4 | "
"tr -d '\n'").read()
# Import slow log Anemometer using pt-query-digest
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))
else:
Log.error(self, "Unable to find MySQL slow log file")
else:
Log.error(self, "Anemometer is not installed")
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(EEImportslowlogController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', import_slow_log_plugin_hook)
Loading…
Cancel
Save