use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.
the class StatusController method handleRequestImpl.
@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
AppUser appUser = retrieveAppUser(req);
HashSet<String> filteredGroups = new HashSet<String>();
boolean useFilter = false;
if (appUser != null && appUser.isRestrictedUser()) {
useFilter = true;
Set<String> mydbs = this.frameworkContext.getDbInfoManager().getMyDatabases(appUser.getName(), appUser.isRestrictedUser()).getMyDbList();
if (mydbs != null) {
for (String s : mydbs) filteredGroups.add(s);
}
}
String dbgroup = req.getParameter("group");
if (dbgroup == null || dbgroup.trim().length() == 0)
dbgroup = "all";
String dbhost = req.getParameter("host");
java.util.Date now = new java.util.Date();
//the first scan yet to complete
long oneinterval = (this.frameworkContext.getMyperfConfig().getScannerIntervalSeconds() + 1) * 1000;
boolean withinOneScan = (now.getTime() - this.frameworkContext.getStartTime().getTime()) <= oneinterval;
long twointerval = (2 * this.frameworkContext.getMyperfConfig().getScannerIntervalSeconds() + 1) * 1000;
ResultList rList = new ResultList();
//if("all".equalsIgnoreCase(dbgroup))
if (//we should have id either as all or a dbgroup
dbhost == null || dbhost.isEmpty()) {
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("DBGROUP", false, 1);
desc.addColumn("HOST", false, 2);
desc.addColumn("QUERIES /SEC", true, 3);
desc.addColumn("SYS CPU%", true, 4);
desc.addColumn("USER CPU%", true, 5);
desc.addColumn("IOWAIT%", true, 6);
desc.addColumn("LOAD AVG", true, 7);
desc.addColumn("REPL LAG", true, 8);
desc.addColumn("FREE MEM (MB)", true, 9);
desc.addColumn("SLOW QUERY /MIN", true, 10);
desc.addColumn("THREADS RUNNING", true, 11);
desc.addColumn("THREADS", true, 12);
desc.addColumn("CONNECTIONS /SEC", true, 13);
desc.addColumn("ABORTED CC /SEC", true, 14);
desc.addColumn("DEADLOCKS", false, 15);
desc.addColumn("STATUS", false, 16);
desc.addColumn("LAST CHECK TIME", false, 17);
desc.addColumn("LAST ALERT", false, 18);
desc.addColumn("SCAN TIME", true, 19);
rList.setColumnDescriptor(desc);
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
java.text.DecimalFormat df = new java.text.DecimalFormat("#.###");
for (Map.Entry<String, DBGroupInfo> e : this.frameworkContext.getDbInfoManager().getClusters().entrySet()) {
for (DBInstanceInfo dbinfo : e.getValue().getInstances()) {
String dbgroupName = dbinfo.getDbGroupName();
String dbHostName = dbinfo.getHostName();
if (!"all".equals(dbgroup) && !dbgroup.equalsIgnoreCase(dbgroupName))
continue;
if (useFilter && !filteredGroups.contains(dbgroupName))
continue;
InstanceStates stateSnaps = this.frameworkContext.getInstanceStatesManager().getStates(dbinfo.getDbid());
if (stateSnaps == null)
continue;
//java.util.Date lastConnectTime = this.frameworkContext.getDbInfoManager().getLastAccessDate(dbgroupName, dbHostName);
java.util.Date lastConnectTime = stateSnaps.getLastAccessTime();
String dbstatus = "Green";
if (lastConnectTime == null && withinOneScan)
dbstatus = "Unknown";
else if (lastConnectTime == null)
dbstatus = "Red";
else if (now.getTime() - lastConnectTime.getTime() > twointerval)
dbstatus = "Red";
else if (now.getTime() - lastConnectTime.getTime() > oneinterval)
dbstatus = "Yellow";
ResultRow row = new ResultRow();
row.setColumnDescriptor(desc);
List<String> vals = new ArrayList<String>();
vals.add(dbgroupName);
vals.add(dbHostName);
StateSnapshot[] snaps = stateSnaps.copySnapshots();
boolean isSnapValid = snaps[0].getTimestamp() >= 0L && snaps[1].getTimestamp() > snaps[0].getTimestamp();
long interval = snaps[1].getTimestamp() - snaps[0].getTimestamp();
if (isSnapValid) {
//sys CPU
double syscpu = 0.0f;
double usercpu = 0.0f;
double iowaits = 0.0f;
double loadAvg = 0.0f;
int activeThreads = 0;
if (snaps[0].getQueries() >= 0L && snaps[1].getQueries() >= 0L) {
//double val = ((double)(snaps[1].getQueries() - snaps[0].getQueries())*1000)/(double)interval;
double val = diffAvgNoNegative(snaps[1].getQueries(), snaps[0].getQueries(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 1000);
vals.add(df.format(val));
} else {
vals.add("0.00");
}
if (snaps[0].getSyscputime() >= 0L && snaps[1].getSyscputime() >= 0L) {
if (snaps[0].getSyscputime() == snaps[1].getSyscputime()) {
syscpu = 0.0;
vals.add("0.00");
} else {
double val = ((double) (snaps[1].getSyscputime() - snaps[0].getSyscputime()) * 100) / (double) (snaps[1].getTotalcputime() - snaps[0].getTotalcputime());
vals.add(df.format(val));
syscpu = val;
}
} else {
vals.add("0.00");
}
if (snaps[0].getUsercputime() >= 0L && snaps[1].getUsercputime() >= 0L) {
if (snaps[0].getUsercputime() == snaps[1].getUsercputime()) {
usercpu = 0.0;
vals.add("0.00");
} else {
double val = ((double) (snaps[1].getUsercputime() - snaps[0].getUsercputime()) * 100) / (double) (snaps[1].getTotalcputime() - snaps[0].getTotalcputime());
vals.add(df.format(val));
usercpu = val;
}
} else {
vals.add("0.00");
}
if (snaps[0].getIotime() >= 0L && snaps[1].getIotime() >= 0L) {
if (snaps[0].getIotime() == snaps[1].getIotime()) {
iowaits = 0.0;
vals.add("0.00");
} else {
double val = ((double) (snaps[1].getIotime() - snaps[0].getIotime()) * 100) / (double) (snaps[1].getTotalcputime() - snaps[0].getTotalcputime());
vals.add(df.format(val));
iowaits = val;
}
} else {
vals.add("0.00");
}
if (snaps[1].getLoadAverage() >= 0.0f) {
vals.add(df.format(snaps[1].getLoadAverage()));
loadAvg = snaps[1].getLoadAverage();
} else
vals.add("0.00");
vals.add(String.valueOf(snaps[1].getReplLag()));
if (snaps[1].getAvailableMem() >= 0L) {
long val = snaps[1].getAvailableMem() / 1024;
vals.add(String.valueOf(val));
} else
vals.add("0.00");
if (snaps[0].getSlowQueryCount() >= 0L && snaps[1].getSlowQueryCount() >= 0L) {
double val = diffAvgNoNegative(snaps[1].getSlowQueryCount(), snaps[0].getSlowQueryCount(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 60000);
vals.add(df.format(val));
} else
vals.add("0.00");
vals.add(String.valueOf(snaps[1].getActiveThreads()));
activeThreads = snaps[1].getActiveThreads();
vals.add(String.valueOf(snaps[1].getThreads()));
if (snaps[0].getConnections() >= 0L && snaps[1].getConnections() >= 0L) {
//double val = ((double)(snaps[1].getConnections() - snaps[0].getConnections())*1000)/(double)interval;
double val = diffAvgNoNegative(snaps[1].getConnections(), snaps[0].getConnections(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 1000);
vals.add(df.format(val));
} else {
vals.add("0.00");
}
if (snaps[0].getAbortedConnectsClients() >= 0L && snaps[1].getAbortedConnectsClients() >= 0L) {
//double val = ((double)(snaps[1].getAbortedConnectsClients() - snaps[0].getAbortedConnectsClients())*1000)/(double)interval;
double val = diffAvgNoNegative(snaps[1].getAbortedConnectsClients(), snaps[0].getAbortedConnectsClients(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), true, 1000);
vals.add(df.format(val));
} else {
vals.add("0.00");
}
if (snaps[0].getDeadlocks() >= 0L && snaps[1].getDeadlocks() >= 0L) {
double val = diffAvgNoNegative(snaps[1].getDeadlocks(), snaps[0].getDeadlocks(), snaps[1].getTimestamp(), snaps[0].getTimestamp(), snaps[1].getUptime(), false, 1);
vals.add((long) val + "(" + snaps[0].getDeadlocks() + ")");
} else {
vals.add(String.valueOf(snaps[1].getDeadlocks()));
}
//hardcoded threshold now
if (iowaits > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "IO") || (syscpu + usercpu > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "CPU")) || loadAvg > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "LOADAVG") || activeThreads > this.frameworkContext.getAlertSettings().getAlertThreshold(dbinfo, "THREAD"))
if (!"Red".equals(dbstatus))
dbstatus = "Yellow";
} else {
vals.add("0.00");
vals.add("0.00");
vals.add("0.00");
vals.add("0.00");
if (snaps[1].getTimestamp() > 0L)
vals.add(String.valueOf(snaps[1].getReplLag()));
else
vals.add("0");
vals.add("0.00");
vals.add("0.00");
vals.add("0");
vals.add("0");
vals.add("0.00");
vals.add("0.00");
vals.add("0.00");
vals.add("0");
}
vals.add(dbstatus);
if (lastConnectTime != null)
vals.add(sdf.format(lastConnectTime));
else
vals.add("");
Date altDt = stateSnaps.getLastAlertTime();
if (altDt != null) {
String val = stateSnaps.getLastAlertValue();
if (val == null)
val = "";
//else if(val.indexOf('.')>0 && val.length()>=val.indexOf('.')+4)
// val = val.substring(0, val.indexOf('.')+4);
String end_dt = stateSnaps.getLastAlertEndTime() != null ? sdf.format(stateSnaps.getLastAlertEndTime()) : "";
vals.add(sdf.format(altDt) + "-" + end_dt + "/" + stateSnaps.getLastAlertType() + "/" + val);
} else
vals.add("");
vals.add(String.valueOf(stateSnaps.getLastScanTime()));
row.setColumns(vals);
rList.addRow(row);
}
}
} else {
Date d1 = null;
Date d2 = null;
Calendar c = Calendar.getInstance();
//7 days
c.add(Calendar.DATE, -7);
d1 = c.getTime();
d2 = new Date();
java.text.SimpleDateFormat sdf2 = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
sdf2.setTimeZone(TimeZone.getTimeZone("UTC"));
String startDate = sdf2.format(d1);
String endDate = sdf2.format(d2);
try {
//TODO validate DB
rList = this.frameworkContext.getAutoScanner().getMetricDb().retrieveMetricsStatus("mysql_globalstatus".toUpperCase(), this.frameworkContext.getDbInfoManager().findDB(dbgroup, dbhost).getDbid(), Long.parseLong(startDate), Long.parseLong(endDate));
HashMap<String, Integer> connectCounter = new HashMap<String, Integer>(24 * 8);
HashMap<String, Integer> slowCounter = new HashMap<String, Integer>(24 * 8);
if (rList != null && rList.getRows().size() > 0) {
for (ResultRow row : rList.getRows()) {
String ts = row.getColumns().get(1);
String h = ts.substring(0, ts.length());
if (connectCounter.containsKey(h))
connectCounter.put(h, connectCounter.get(h) + 1);
else
connectCounter.put(h, 1);
try {
if (slowCounter.containsKey(h))
slowCounter.put(h, connectCounter.get(h) + Integer.parseInt(row.getColumns().get(3)));
else
slowCounter.put(h, Integer.parseInt(row.getColumns().get(3)));
} catch (Exception ex) {
}
}
}
} catch (Exception ex) {
//logger.log(Level.WARNING, "Failed to retrieve metrics data", ex);
}
}
ModelAndView mv = new ModelAndView(jsonView);
String msg = "OK";
mv.addObject("json_result", ResultListUtil.toJSONString(rList, null, 0, msg));
return mv;
}
use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.
the class UdmController method processUDMDBDetail.
private ModelAndView processUDMDBDetail(HttpServletRequest req, HttpServletResponse resp) {
ModelAndView mv = null;
String group = req.getParameter("group");
String host = req.getParameter("host");
String typ = req.getParameter("typ");
ResultList rList = null;
if (typ == null || typ.isEmpty() || "UDM".equalsIgnoreCase(typ)) {
List<String> udms = this.frameworkContext.getMetricsDef().getUdmManager().getMetricsSubscriptions().getSubscribedUDMs(group, host);
if (udms != null && udms.size() > 0) {
rList = new ResultList();
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("UDM", false, 0);
rList.setColumnDescriptor(desc);
for (String u : udms) {
ResultRow row = new ResultRow();
ArrayList<String> cols = new ArrayList<String>();
cols.add(u);
row.setColumns(cols);
rList.addRow(row);
}
}
} else if ("ALERT".equalsIgnoreCase(typ)) {
List<AlertSubscribers.Subscription> alerts = this.frameworkContext.getMetricsDef().getUdmManager().getAlertSubscriptions().getSubscriptions(group, host);
if (alerts != null && alerts.size() > 0) {
rList = new ResultList();
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("UDM", false, 0);
rList.setColumnDescriptor(desc);
for (AlertSubscribers.Subscription u : alerts) {
ResultRow row = new ResultRow();
ArrayList<String> cols = new ArrayList<String>();
cols.add(u.alertName);
row.setColumns(cols);
rList.addRow(row);
}
}
} else if ("PREDEFINED".equalsIgnoreCase(typ)) {
rList = new ResultList();
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("UDM", false, 0);
rList.setColumnDescriptor(desc);
String[] mgNames = this.frameworkContext.getMetricsDef().getGroupNames();
for (String mgName : mgNames) {
MetricsGroup mg = this.frameworkContext.getMetricsDef().getGroupByName(mgName);
if (!mg.isAuto()) {
//skip groups requiring manual configuration for now
if (this.frameworkContext.getMetricsDef().getUdmManager().isMetricsGroupSubscribed(group, host, mg.getGroupName(), null)) {
ResultRow row = new ResultRow();
ArrayList<String> cols = new ArrayList<String>();
cols.add(mg.getGroupName());
row.setColumns(cols);
rList.addRow(row);
}
}
List<MetricsGroup> subGrps = mg.getSubGroups();
if (subGrps != null && subGrps.size() > 0) {
for (MetricsGroup subG : subGrps) {
if (!subG.isAuto() && this.frameworkContext.getMetricsDef().getUdmManager().isMetricsGroupSubscribed(group, host, mg.getGroupName(), subG.getGroupName())) {
ResultRow row = new ResultRow();
ArrayList<String> cols = new ArrayList<String>();
cols.add(mg.getGroupName() + "." + subG.getGroupName());
row.setColumns(cols);
rList.addRow(row);
}
}
}
}
}
mv = new ModelAndView(this.jsonView);
mv.addObject("json_result", ResultListUtil.toJSONString(rList, null, 0, "OK"));
return mv;
}
use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.
the class SNMPQueryProcessor method querySingle.
@Override
public ResultList querySingle(MyPerfContext context, DBInstanceInfo dbinfo, String appUser, DBConnectionWrapper connWrapper, QueryParameters qps) throws SQLException {
String cat = "sys";
if (qps.getSqlParams().containsKey("p_1")) {
cat = qps.getSqlParams().get("p_1");
}
SNMPClient client = null;
try {
client = new SNMPClient(qps.getHost());
client.setSnmpSetting(context.getSnmpSettings().getHostSetting(dbinfo.getDbGroupName(), dbinfo.getHostName()));
client.start();
if ("disk".equalsIgnoreCase(cat)) {
return queryDisk(client, qps);
} else if ("network".equalsIgnoreCase(cat)) {
return queryNetwork(client, qps);
} else if ("storage".equalsIgnoreCase(cat)) {
return this.queryStorage(client, qps);
} else if ("sys".equalsIgnoreCase(cat)) {
return querySystemData(client, qps);
} else if ("mysqld".equalsIgnoreCase(cat)) {
return queryMysqldData(client, qps);
} else if ("single".equalsIgnoreCase(cat)) {
return this.querySingleSNMP(client, qps);
} else if ("table".equalsIgnoreCase(cat)) {
return this.queryTableSNMP(client, qps);
} else if ("unknown".equalsIgnoreCase(cat)) {
ResultList res = this.querySingleSNMP(client, qps);
if (res == null || res.getRows().size() == 0 || (res.getRows().size() == 1 && "noSuchObject".equals(res.getRows().get(0).getColumns().get(2)))) {
res = this.queryTableSNMP(client, qps);
}
return res;
} else {
ResultList sysList = querySystemData(client, qps);
//don't expect no system data
if (sysList == null)
return null;
try {
ResultList diskList = queryDisk(client, qps);
;
//ResultList mysqldList = queryMysqldData(client, qps);
if (diskList != null) {
for (ResultRow row : diskList.getRows()) {
row.setColumnDescriptor(sysList.getColumnDescriptor());
sysList.addRow(row);
}
}
} catch (Exception ex) {
logger.log(Level.INFO, "Failed to query disk data", ex);
return sysList;
}
try {
ResultList netList = queryNetwork(client, qps);
if (netList != null) {
for (ResultRow row : netList.getRows()) {
row.setColumnDescriptor(sysList.getColumnDescriptor());
sysList.addRow(row);
}
}
} catch (Exception ex) {
logger.log(Level.INFO, "Failed to query netif data", ex);
return sysList;
}
try {
ResultList storageList = queryStorage(client, qps);
if (storageList != null) {
for (ResultRow row : storageList.getRows()) {
row.setColumnDescriptor(sysList.getColumnDescriptor());
sysList.addRow(row);
}
}
} catch (Exception ex) {
logger.log(Level.INFO, "Failed to query storage data", ex);
return sysList;
}
//}
return sysList;
}
} catch (Throwable ex) {
//not a good way, but leave it as is
throw new SQLException(ex);
} finally {
if (client != null)
try {
client.stop();
} catch (Exception iex) {
}
}
}
use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.
the class SNMPQueryProcessor method querySystemData.
private ResultList querySystemData(SNMPClient client, QueryParameters qps) throws Exception {
boolean diff = "1".equalsIgnoreCase(qps.getSqlParams().get("p_2"));
List<SNMPTriple> snmpData = client.querySysData3();
if (snmpData == null)
return null;
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("NAME", false, 0);
desc.addColumn("OID", false, 1);
desc.addColumn("VALUE", false, 2);
ResultList rList = new ResultList();
rList.setColumnDescriptor(desc);
for (SNMPTriple t : snmpData) {
if (diff) {
try {
BigDecimal bd = new BigDecimal(t.value);
} catch (Exception ex) {
continue;
}
}
ResultRow row = new ResultRow();
row.addColumn(t.name);
row.addColumn(t.oid);
row.addColumn(t.value);
row.setColumnDescriptor(desc);
rList.addRow(row);
}
return rList;
}
use of com.yahoo.dba.perf.myperf.common.ResultRow in project mysql_perf_analyzer by yahoo.
the class SNMPQueryProcessor method queryDisk.
/**
* Query disk data, in (name, oid, value). Note name will be prefixed with disk name.
* @param qps
* @return
* @throws Exception
*/
private ResultList queryDisk(SNMPClient client, QueryParameters qps) throws Exception {
boolean diff = "1".equalsIgnoreCase(qps.getSqlParams().get("p_2"));
Map<String, List<SNMPTriple>> snmpData = client.getMultiDiskData();
if (snmpData == null)
return null;
ColumnDescriptor desc = new ColumnDescriptor();
desc.addColumn("NAME", false, 0);
desc.addColumn("OID", false, 1);
desc.addColumn("VALUE", false, 2);
ResultList rList = new ResultList();
rList.setColumnDescriptor(desc);
for (Map.Entry<String, List<SNMPTriple>> e : snmpData.entrySet()) {
String disk = e.getKey();
for (SNMPTriple t : e.getValue()) {
if (diff) {
try {
BigDecimal bd = new BigDecimal(t.value);
} catch (Exception ex) {
continue;
}
}
ResultRow row = new ResultRow();
row.addColumn(disk + "." + t.name);
row.addColumn(t.oid);
row.addColumn(t.value);
row.setColumnDescriptor(desc);
rList.addRow(row);
}
}
return rList;
}
Aggregations