use of com.yahoo.dba.perf.myperf.common.ProcessListEntry in project mysql_perf_analyzer by yahoo.
the class AlertReportRunner method run.
@Override
public void run() {
AlertEntry alertEntry = new AlertEntry(timestamp, alertReason, alertValue, dbInfo.getDbGroupName(), dbInfo.getHostName());
this.context.getAlerts().addAlert(alertEntry);
ResultSet rs = null;
Statement stmt = null;
long reportTimestamp = System.currentTimeMillis();
List<ProcessListEntry> prList = new ArrayList<ProcessListEntry>();
java.util.LinkedHashMap<String, String> repMap = new java.util.LinkedHashMap<String, String>();
String innodbStatus = null;
ResultList rList = null;
ResultList clientList = null;
try {
stmt = connection.getConnection().createStatement();
stmt.setFetchSize(5000);
//stmt.setMaxRows(5000);
//rs = stmt.executeQuery("select * from information_schema.processlist limit 5000");
//remove limit to handle the case of very large connections
rs = stmt.executeQuery("select * from information_schema.processlist");
boolean hasRowInfo = rs != null && hasRowInfo(rs);
boolean hasRowRead = rs != null && hasRowsRead(rs);
while (rs != null && rs.next()) {
ProcessListEntry ps = new ProcessListEntry(rs, hasRowInfo, hasRowRead);
prList.add(ps);
}
if ("REPLLAG".equalsIgnoreCase(this.alertReason) || "REPLDOWN".equalsIgnoreCase(this.alertReason)) {
DBUtils.close(rs);
rs = stmt.executeQuery("show slave status");
int i = 0;
int cnt = rs.getMetaData().getColumnCount();
while (rs != null && rs.next()) {
String suffix = "";
if (i > 0)
suffix = "_" + i;
for (int k = 0; k < cnt; k++) repMap.put(rs.getMetaData().getColumnName(k + 1) + suffix, rs.getString(k + 1));
i++;
}
}
//if ("CPU".equalsIgnoreCase(alertReason) ||"THREAD".equalsIgnoreCase(alertReason)||"REPLLAG".equalsIgnoreCase(this.alertReason))
{
DBUtils.close(rs);
rs = stmt.executeQuery("show engine innodb status");
if (rs != null && rs.next()) {
innodbStatus = rs.getString("Status");
}
DBUtils.close(rs);
rs = stmt.executeQuery("select * from information_schema.innodb_locks");
if (rs != null) {
rList = ResultListUtil.fromSqlResultSet(rs, 5000);
}
}
//TODO we need two snapshot to get useful data
if ("CONNECT_FAILURE".equalsIgnoreCase(alertReason)) {
//dump summary of processlist if possible
String sql = "select user, host, command, count(*) conns from information_schema.processlist group by user, host, command";
DBUtils.close(rs);
rs = stmt.executeQuery(sql);
if (rs != null) {
clientList = ResultListUtil.fromSqlResultSet(rs, 5000);
}
DBUtils.close(rs);
}
} catch (Exception ex) {
logger.log(Level.WARNING, "Error when retrieve alert detail", ex);
} finally {
DBUtils.close(rs);
DBUtils.close(stmt);
}
if (prList.size() > 0 || repMap.size() > 0) {
//sort by sql text
java.util.Collections.sort(prList);
ProcessListSummary prSum = new ProcessListSummary();
prSum.setProcessList(prList);
prSum.setInnodbStatus(innodbStatus);
prSum.setLockList(rList);
//prSum.setClientList(clientList);
prSum.setReportTimestamp(reportTimestamp);
prSum.summarize();
AlertReport ar = this.context.createAlertReport(reportTimestamp, alertEntry);
ar.setProcessListSummary(prSum);
if (repMap.size() > 0)
ar.setReplicationSummary(repMap);
ar.saveAsText();
}
if (this.dbInfo.isAlertEnabled())
this.context.emailAlert(alertEntry);
}
Aggregations