public void RemoveTransaction(String id) throws Exception { Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = con.prepareStatement("delete from rawdata where transactionid=?"); cmd.setString(1, id); cmd.execute(); cmd.close(); // System.out.println("attempting config connection close"); con.close(); // System.out.println("config connection closed"); } catch (Exception x) { x.printStackTrace(); } finally { try { if (!con.isClosed()) { // System.out.println("attempting config connection close"); con.close(); // System.out.println("config connection closed"); } } catch (Exception e) { } } }
Connection con = Utility.getPerformanceDBConnection(); try { PreparedStatement cmd = con.prepareStatement("delete from rawdata where uri=?");
public static long GetDiskUsageOverTime(String pol, long timerange, boolean pooled) { Connection con = null; long ret = -1; try { con = Utility.getPerformanceDBConnection(); long limit = System.currentTimeMillis() - timerange; PreparedStatement com = con.prepareStatement("select avg(diskKBs) from rawdatamachineprocess where uri=? and utcdatetime > ?; "); com.setString(1, pol); com.setLong(2, limit); ResultSet rs = com.executeQuery(); if (rs.next()) { ret = (long) rs.getDouble(1); } rs.close(); com.close(); } catch (Exception ex) { log.log(Level.WARN, "trouble calculating avg disk used for " + pol, ex); } try { if (con != null && !con.isClosed()) { con.close(); } } catch (Exception ex) { log.log(Level.WARN, SLACommon.getBundleString("ErrorClosingDB"), ex); } return ret; }
public static long GetMemoryUsageOverTime(String pol, long timerange, boolean pooled) { Connection con = null; long ret = -1; try { con = Utility.getPerformanceDBConnection(); long limit = System.currentTimeMillis() - timerange; PreparedStatement com = con.prepareStatement("select avg(memoryused) from rawdatamachineprocess where uri=? and utcdatetime > ?; "); com.setString(1, pol); com.setLong(2, limit); ResultSet rs = com.executeQuery(); if (rs.next()) { ret = (long) rs.getDouble(1); } rs.close(); com.close(); } catch (Exception ex) { log.log(Level.WARN, "trouble calculating avg mmem used for " + pol, ex); } try { if (con != null && !con.isClosed()) { con.close(); } } catch (Exception ex) { log.log(Level.WARN, SLACommon.getBundleString("ErrorClosingDB"), ex); } return ret; }
public static long GrabInvocationRate(long x, String URL) { Connection con = null; try { con = Utility.getPerformanceDBConnection(); PreparedStatement comm = con.prepareStatement("select success from agg2 where URI=? and soapaction=? and timerange=?"); comm.setString(1, URL); comm.setString(2, allitems); comm.setLong(3, x); ResultSet rs = comm.executeQuery(); long ret = 0; if (rs.next()) { ret = rs.getLong(1); } rs.close(); comm.close(); con.close(); return ret; } catch (Exception ex) { log.log(Level.ERROR, null, ex); } try { if (con != null && !con.isClosed()) { con.close(); } } catch (Exception ex) { log.log(Level.WARN, SLACommon.getBundleString("ErrorClosingDB"), ex); } return 0; }
public static int GetCPUUsageOverTime(String pol, long timerange, boolean pooled) { Connection con = null; int ret = -1; try { con = Utility.getPerformanceDBConnection(); long limit = System.currentTimeMillis() - timerange; PreparedStatement com = con.prepareStatement("select avg(percentcpu) from rawdatamachineprocess where uri=? and utcdatetime > ?; "); com.setString(1, pol); com.setLong(2, limit); ResultSet rs = com.executeQuery(); if (rs.next()) { ret = (int) rs.getDouble(1); } rs.close(); com.close(); } catch (Exception ex) { log.log(Level.WARN, "trouble calculating avg cpu used for " + pol, ex); } try { if (con != null && !con.isClosed()) { con.close(); } } catch (Exception ex) { log.log(Level.WARN, SLACommon.getBundleString("ErrorClosingDB"), ex); } return ret; }
public static long GrabFaultRate(long timeInMs, String URL) { Connection con = null; try { con = Utility.getPerformanceDBConnection(); PreparedStatement comm = con.prepareStatement("select failure from agg2 where uri=? and soapaction=? and timerange=?"); // comm.setString(1,); comm.setString(1, URL); comm.setString(2, allitems); comm.setLong(3, timeInMs); ResultSet rs = comm.executeQuery(); long ret = 0; if (rs.next()) { ret = rs.getLong(1); } rs.close(); comm.close(); con.close(); return ret; } catch (Exception ex) { log.log(Level.ERROR, null, ex); } try { if (con != null && !con.isClosed()) { con.close(); } } catch (Exception ex) { log.log(Level.WARN, SLACommon.getBundleString("ErrorClosingDB"), ex); } return 0; }
private void updateLastRanAt(ReportDefinition get) { Connection con = Utility.getPerformanceDBConnection(); PreparedStatement cmd = null; try { cmd = con.prepareStatement("update arsjobs set lastranat=? where jobid=?"); cmd.setLong(1, System.currentTimeMillis()); cmd.setString(2, get.getJobId()); cmd.executeUpdate(); } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(cmd); DBUtils.safeClose(con); } } }
try { con = Utility.getPerformanceDBConnection();
JAXBContext GetARSSerializationContext = Utility.getARSSerializationContext(); Unmarshaller u = GetARSSerializationContext.createUnmarshaller(); con = Utility.getPerformanceDBConnection(); cmd = con.prepareStatement("select * from arsjobs where jobid=?;"); cmd.setString(1, job);
private static boolean IsReportJobOwner(String currentUser, String jobId) { Connection con = null; boolean ok = false; PreparedStatement cmd = null; ResultSet rs = null; try { con = Utility.getPerformanceDBConnection(); cmd = con.prepareStatement("select * from arsjobs where jobid=? and owninguser=?"); cmd.setString(1, jobId); cmd.setString(2, currentUser); rs = cmd.executeQuery(); if (rs.next()) { ok = true; } } catch (Exception ex) { log.log(Level.ERROR, "error caught searching for a report job", ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(cmd); DBUtils.safeClose(con); } return ok; }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME, 0, myUrl, "machine/process", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkBrokers(ConfigCon, PerfCon, periods); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME, 0, myUrl, "machine/process", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkMachinesProcesses(ConfigCon, PerfCon, periods); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME, 0, myUrl, "status", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkForStatusItemsOnly(ConfigCon, PerfCon, periods); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
@Override public void run() { UUID random = UUID.randomUUID(); MessageProcessor.getSingletonObject().processMessageInput(SERVICE_NAME + " for " + uri, 0, myUrl, "transactional", "system", random.toString(), new HashMap(), "", this.getClass().getCanonicalName(), "", ""); Connection ConfigCon = Utility.getConfigurationDBConnection(); Connection PerfCon = Utility.getPerformanceDBConnection(); try { doWorkTransactional(ConfigCon, PerfCon, periods, uri); MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "success", 0, false, System.currentTimeMillis(), new HashMap()); } catch (Exception ex) { MessageProcessor.getSingletonObject().processMessageOutput(random.toString(), "error " + ex.getMessage(), 0, true, System.currentTimeMillis(), new HashMap()); log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(PerfCon); DBUtils.safeClose(ConfigCon); } }
private List<NetworkAdapterPerformanceData> getNICLogsByRange(String hostname, String domainname, long timestamp) { Connection con = Utility.getPerformanceDBConnection(); List<NetworkAdapterPerformanceData> ret = new ArrayList<NetworkAdapterPerformanceData>(); NetworkAdapterPerformanceData p = null; PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select * from rawdatanic where hostname=? and domainname=? and utcdatetime = ?;"); com.setString(1, hostname); com.setString(2, domainname); com.setLong(3, timestamp); rs = com.executeQuery(); while (rs.next()) { p = new NetworkAdapterPerformanceData(); p.setAdapterName(rs.getString("nicid")); p.setKilobytespersecondNetworkReceive(rs.getLong("receiveKBs")); p.setKilobytespersecondNetworkTransmit(rs.getLong("sendKBs")); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(rs.getLong("utcdatetime")); ret.add(p); } } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return ret; }
private String storeReport(byte[] bits, String jobId, boolean pooled) throws Exception { String id = UUID.randomUUID().toString(); Connection con = null; PreparedStatement cmd = null; if (pooled) { con = Utility.getPerformanceDBConnection(); } else { con = Utility.getPerformanceDB_NONPOOLED_Connection(); } try { cmd = con.prepareStatement("INSERT INTO arsreports(reportid, jobid, datetime,reportcontents) VALUES (?, ?, ?,?);"); cmd.setString(1, id); cmd.setString(2, jobId); cmd.setLong(3, System.currentTimeMillis()); cmd.setBytes(4, bits); cmd.execute(); } catch (Exception ex) { log.log(Level.ERROR, "error storing report", ex); DBUtils.safeClose(cmd); DBUtils.safeClose(con); throw ex; } finally { DBUtils.safeClose(cmd); DBUtils.safeClose(con); } return id; }
protected static Duration getUpTime(String uri) { Connection con = Utility.getPerformanceDBConnection(); PreparedStatement com = null; ResultSet rs = null; try { com = con.prepareStatement("select * from availability where uri=? order by utcdatetime desc limit 1"); com.setString(1, uri); Duration d = null; rs = com.executeQuery(); if (rs.next()) { long changeat = rs.getLong("utcdatetime"); long now = System.currentTimeMillis(); d = DAS4jBean.df.newDuration(now - changeat); } DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); return d; } catch (Exception ex) { log.log(Level.ERROR, "unable to get uptime for uri " + uri, ex); } finally { DBUtils.safeClose(rs); DBUtils.safeClose(com); DBUtils.safeClose(con); } return null; }
/** * provides a wrapper for getting alternate urls without passing a db * connection * * @param url * @param pooled * @return */ protected static List<String> GetAlternateUrls(String url, boolean pooled) { java.sql.Connection perf = null; if (pooled) { perf = Utility.getPerformanceDBConnection(); } else { perf = Utility.getPerformanceDB_NONPOOLED_Connection(); } List<String> ret = Collections.EMPTY_LIST; try { ret = GetAlternateUrls(url, perf); } catch (Exception ex) { log.log(Level.ERROR, null, ex); } finally { DBUtils.safeClose(perf); } return ret; } private boolean done = false;
/** * provides a wrapper for getting alternate urls without passing a db * connection * * @param url * @param pooled * @return */ static Set<String> GetAlternateUrls(String url, boolean pooled) { java.sql.Connection perf = null; if (pooled) { perf = Utility.getPerformanceDBConnection(); } else { perf = Utility.getPerformanceDB_NONPOOLED_Connection(); } Set<String> ret = Collections.EMPTY_SET; try { ret = GetAlternateUrls(url, perf); } catch (Exception ex) { log.log(Level.WARN, null, ex); } finally { DBUtils.safeClose(perf); } return ret; } }