Permalink
Browse files

option to only display query fingerprints (with anonymized comments d…

…rawn from samples)
  • Loading branch information...
1 parent d1c02a4 commit 826f54589e4c13a336db18d95d772f07fcfa0f7d asher committed May 23, 2012
Showing with 60 additions and 23 deletions.
  1. +3 −7 conf.php.sample
  2. +32 −12 dashboard.php
  3. +3 −1 explain.php
  4. +22 −3 more.php
View
@@ -1,9 +1,4 @@
<?php
- # I'm guessing that eventually more elaborate configuration will be needed
- # since the mk-digest db might live on an entirely different host. That's
- # not the case for us right now, so we'll make that case work later
- # - Mike 2010-04-04
-
# these are default values; they can be overridden on a per-host basis
$conf['db_user'] = ''; # user with which to login
$conf['db_password'] = ''; # password
@@ -13,13 +8,14 @@
$conf['db_query_review_table'] = 'query_review';
$conf['db_query_review_history_table'] = 'query_review_history';
$conf['limit'] = 20; # max number of slow queries to display, defaults to 20
- # $conf['explain'] = false; # set to disable explain functionality
+ # $conf['explain'] = false; # set to disable explain functionality, default is true
+ # $conf['anon'] = true; # set to only display query fingerprints, default is false
# You can aggregate the review tables for many db instances in a single db.
# In that case, ishmael will auto-generate the list of hosts based on the
# contents of the aggregate db. $conf['hosts'] will not be used.
#
- # If you have db{1..20}, use table names like db1_query_review.
+ # If you have db{1..20}, use table names like db1_query_review.
# define db_central_host and add a wildcard to the table definitions:
#
# $conf['db_central_host'] = ''; # only define if aggregating many hosts to one db
View
@@ -61,25 +61,45 @@
# Get list of bad queries
$q = "SELECT
- checksum,
- sample,
- SUM(ts_cnt) AS count,
- SUM(query_time_sum) AS time,
- ts_max AS time_max,
- (SUM(ts_cnt)/{$query_qty_sum}*100) AS qty_pct,
- (SUM(query_time_sum)/{$query_time_sum}*100) AS time_pct,
- ((SUM(query_time_sum)/{$query_time_sum}*100)/(SUM(ts_cnt)/{$query_qty_sum}*100)) AS ratio
+ h.checksum,
+ r.fingerprint,
+ h.sample,
+ SUM(h.ts_cnt) AS count,
+ SUM(h.query_time_sum) AS time,
+ h.ts_max AS time_max,
+ (SUM(h.ts_cnt)/{$query_qty_sum}*100) AS qty_pct,
+ (SUM(h.query_time_sum)/{$query_time_sum}*100) AS time_pct,
+ ((SUM(h.query_time_sum)/{$query_time_sum}*100)/(SUM(h.ts_cnt)/{$query_qty_sum}*100)) AS ratio
FROM
- {$host_conf['db_query_review_history_table']}
- WHERE
- ts_max > date_sub(now(),interval $hours hour)
- GROUP BY checksum ORDER BY $sort DESC LIMIT $limit";
+ {$host_conf['db_query_review_history_table']} h
+ INNER JOIN
+ {$host_conf['db_query_review_table']} r
+ USING(checksum) WHERE
+ h.ts_max > date_sub(now(),interval $hours hour)
+ GROUP BY h.checksum ORDER BY $sort DESC LIMIT $limit";
$result = mysql_query($q);
$err = mysql_error();
print_r($err);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
+ if ($conf['anon']) {
+ if (preg_match('@/\*.*\*/@', $row['sample'], $matches)) {
+ if (preg_match('@ 127.0.0.1 \*/@', $matches[0])) {
+ $extra = $matches[0];
+ } elseif (preg_match('@ \d+\.\d+\.\d+\.\d+ @', $matches[0])) {
+ $extra = preg_replace('@\d+\.\d+\.\d+\.\d+@', 'External_IP', $matches[0]);
+ } elseif (preg_match('@ \S+ \*/@', $matches[0])) {
+ $extra = preg_replace('@ \S+ \*/@', ' User */', $matches[0]);
+ }
+ else {
+ $extra = $matches[0];
+ }
+ $row['sample'] = $extra . ' ' . $row['fingerprint'];
+ } else {
+ $row['sample'] = $row['fingerprint'];
+ }
+ }
$row['explain_url'] = "explain.php?" . ish_build_query(array('checksum'=>$row['checksum']));
$row['more_url'] = "more.php?" . ish_build_query(array('checksum'=>$row['checksum']));
$rows[] = $row;
View
@@ -5,7 +5,8 @@
require_once('init.php');
$explain = (isset($conf['explain'])) ? $conf['explain'] : true;
- if (!$explain) {
+ $anon = (isset($conf['anon'])) ? $conf['anon'] : false;
+ if (!$explain || $anon) {
header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
return;
@@ -20,6 +21,7 @@
$query = $row['sample'];
$explain = "EXPLAIN ".preg_replace('|^\s*\/\*.*\*\/|', '', $query);
+ mysql_connect($conf['db_live_host'],$conf['db_live_user'],$conf['db_live_password']) or die(sprintf("Unable to connect to MySQL server: %s", mysql_error()));
mysql_select_db($host_conf['db_database_live']) or die("Unable to select database");
$is_select_query = (stripos($explain, 'SELECT') !== false);
View
@@ -19,17 +19,36 @@
);
$q = "SELECT
- *
+ h.*, r.fingerprint
FROM
- {$host_conf['db_query_review_history_table']}
- WHERE
+ {$host_conf['db_query_review_history_table']} h
+ INNER JOIN
+ {$host_conf['db_query_review_table']} r
+ USING(checksum) WHERE
checksum={$checksum} AND
ts_max > date_sub(now(),interval $hours hour)
ORDER BY ts_max ASC";
$result=mysql_query($q);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
+ if ($conf['anon']) {
+ if (preg_match('@/\*.*\*/@', $row['sample'], $matches)) {
+ if (preg_match('@ 127.0.0.1 \*/@', $matches[0])) {
+ $extra = $matches[0];
+ } elseif (preg_match('@ \d+\.\d+\.\d+\.\d+ @', $matches[0])) {
+ $extra = preg_replace('@\d+\.\d+\.\d+\.\d+@', 'External_IP', $matches[0]);
+ } elseif (preg_match('@ \S+ \*/@', $matches[0])) {
+ $extra = preg_replace('@ \S+ \*/@', ' User */', $matches[0]);
+ }
+ else {
+ $extra = $matches[0];
+ }
+ $row['sample'] = $extra . ' ' . $row['fingerprint'];
+ } else {
+ $row['sample'] = $row['fingerprint'];
+ }
+ }
$rows[] = $row;
}

0 comments on commit 826f545

Please sign in to comment.