/** * Given milliseconds, return milliseconds, seconds, minutes, hours, days, or years as appropriate. Note that years is approximate since the logic always assumes there are * exactly 365 days per year. */ public static String getTime(long millis) { return getTime(millis, timeFormatter); }
/** * Given a stopwatch, return milliseconds, seconds, minutes, hours, days, or years as appropriate. Note that years is approximate since the logic always assumes there are * exactly 365 days per year. */ public static String getTime(Stopwatch stopwatch) { return getTime(stopwatch.elapsed(MILLISECONDS)); }
@Override public void execute() { logger.info("Sleeping for {}", FormatUtils.getTime(millis)); Threads.sleep(millis); }
/** * Parse milliseconds from a time string that ends with a unit of measure. If no unit of measure is provided, milliseconds is assumed. Unit of measure is case insensitive. * * @see FormatUtils.getMillis(String time) */ public static int getMillisAsInt(EnvironmentService env, String key, int defaultValue) { return getMillisAsInt(env, key, FormatUtils.getTime(defaultValue)); }
@Override public void start() { if (!enabled) { logger.info("[appdynamics:start] - (skipped) - monitoring is not enabled"); return; } long start = System.currentTimeMillis(); logger.info("[appdynamics:starting]"); startMachineAgent(channel, machineAgent); logger.info("[appdynamics:started] - {}", FormatUtils.getTime(System.currentTimeMillis() - start)); }
@Override public void stop() { long start = System.currentTimeMillis(); logger.info("[appdynamics:stopping]"); DeployUtils.killMatchingProcesses(channel, user, machineAgent.getStartupCommand(), "machine agent"); logger.info("[appdynamics:stopped] - {}", FormatUtils.getTime(System.currentTimeMillis() - start)); }
@Override public void start() { long start = System.currentTimeMillis(); logger.info("[tomcat:start]"); DeployUtils.runscript(channel, username, startup); httpWait.execute(); logger.info("[tomcat:started] - {}", FormatUtils.getTime(System.currentTimeMillis() - start)); }
@Override public void afterMetaData(SqlMetaDataEvent event) { String elapsed = FormatUtils.getTime(event.getStopTimeMillis() - event.getStartTimeMillis()); System.out.println("[" + elapsed + "]"); }
protected void logStats(ThreadSafeListener listener, ExecutionStatistics stats, List<SqlBucket> buckets) { // Display thread related stats long aggregateTime = listener.getAggregateTime(); long wallTime = stats.getExecutionTime(); String avgMillis = FormatUtils.getTime(aggregateTime / buckets.size()); String aTime = FormatUtils.getTime(aggregateTime); String wTime = FormatUtils.getTime(wallTime); String sqlCount = FormatUtils.getCount(listener.getAggregateSqlCount()); String sqlSize = FormatUtils.getSize(listener.getAggregateSqlSize()); Object[] args = { buckets.size(), wTime, aTime, avgMillis, sqlCount, sqlSize }; logger.debug("Threads - [count: {} time: {} aggregate: {} avg: {} sql: {} - {}]", args); }
protected static void logCopy(String src, String dst, long elapsed) { String rate = ""; String size = ""; if (LocationUtils.isExistingFile(src)) { long bytes = new File(src).length(); rate = FormatUtils.getRate(elapsed, bytes); size = FormatUtils.getSize(bytes); } Object[] args = { dst, size, FormatUtils.getTime(elapsed), rate }; logger.debug("Source -> [{}]", src); logger.debug(" created [{}] - [{} {} {}]", args); }
@Override public void stop() { long start = System.currentTimeMillis(); logger.info("[tomcat:stopping]"); Result result = DeployUtils.runscript(channel, username, shutdown, false); if (result.getExitValue() != 0) { DeployUtils.logResult(result, logger, LoggerLevel.WARN); } logger.info("[tomcat:stopped] - {}", FormatUtils.getTime(System.currentTimeMillis() - start)); }
protected void waitForSnapshotState(String snapshotId, String state, int timeoutMillis) { Condition condition = new SnapshotStateCondition(this, snapshotId, state); WaitContext waitContext = getWaitContext(timeoutMillis); Object[] args = { FormatUtils.getTime(waitContext.getTimeoutMillis()), snapshotId, state }; logger.info(format("waiting up to %s for snapshot [%s] to reach state '%s'", args)); WaitResult result = service.wait(waitContext, condition); Object[] resultArgs = { snapshotId, state, FormatUtils.getTime(result.getElapsed()) }; logger.info(format("snapshot [%s] is now '%s' - %s", resultArgs)); }
protected void afterDump(MySqlDumpContext context, long elapsed, long lineCount, long skippedCount) { long length = context.getOutputFile().length(); String time = FormatUtils.getTime(elapsed); String size = FormatUtils.getSize(length); String rate = FormatUtils.getRate(elapsed, length); String lines = FormatUtils.getCount(lineCount); String skipped = FormatUtils.getCount(skippedCount); Object[] args = { time, size, rate, lines, skipped }; logger.info("Dump completed. [Time:{}, Size:{}, Rate:{}, Lines:{} Skipped:{}]", args); }
public List<String[]> getRows(String bucket, List<BucketDeltaLine> deltaLines) { List<String[]> rows = new ArrayList<String[]>(); for (BucketDeltaLine deltaLine : deltaLines) { String files = FormatUtils.getCount(deltaLine.getFileDelta()); String size = FormatUtils.getSize(deltaLine.getByteDelta()); String start = shortDateFormatter.format(deltaLine.getStartDate()); String end = shortDateFormatter.format(deltaLine.getEndDate()); String interval = FormatUtils.getTime(deltaLine.getInterval()); String[] row = new String[] { bucket, files, size, start, end, interval }; rows.add(row); } return rows; }
protected void showResult(ExecutionResult result) { String updates = FormatUtils.getCount(result.getUpdateCount()); String statements = FormatUtils.getCount(result.getStatementsExecuted()); String elapsed = FormatUtils.getTime(result.getElapsed()); Object[] args = { updates, statements, elapsed }; logger.info("Rows updated: {} SQL Statements: {} Total time: {}", args); }
/** * Show information about the transfer of data from a remote server */ protected void from(String absolutePath, CopyResult result) { if (context.isEcho()) { String elapsed = FormatUtils.getTime(result.getElapsedMillis()); String rate = FormatUtils.getRate(result.getElapsedMillis(), result.getAmountInBytes()); Object[] args = { absolutePath, elapsed, rate }; logger.info("copied <- [{}] - [{}, {}]", args); } }
protected void waitForOnlineConfirmation(Instance instance, LaunchInstanceContext context) { InstanceStateName running = InstanceStateName.RUNNING; WaitContext waitContext = getWaitContext(context.getTimeoutMillis()); Object[] args = { FormatUtils.getTime(waitContext.getTimeoutMillis()), instance.getInstanceId(), running.getValue() }; logger.info("Waiting up to {} for [{}] to come online", args); Condition online = new IsOnlineCondition(this, instance.getInstanceId()); WaitResult result = service.wait(waitContext, online); Object[] resultArgs = { instance.getInstanceId(), FormatUtils.getTime(result.getElapsed()) }; logger.info("[{}] is now online - {}", resultArgs); }
/** * Show information about the transfer of data to a remote server */ protected void to(RemoteFile destination, CopyResult result) { if (context.isEcho()) { String elapsed = FormatUtils.getTime(result.getElapsedMillis()); String rate = FormatUtils.getRate(result.getElapsedMillis(), result.getAmountInBytes()); Object[] args = { destination.getAbsolutePath(), elapsed, rate }; logger.info("created -> [{}] - [{}, {}]", args); } }
protected void logWaitResult(HttpWaitResult result, String url, String logMsgPrefix, boolean quiet) { String status = result.getStatus().toString(); String elapsed = FormatUtils.getTime(result.getStop() - result.getStart()); String statusText = getStatusText(result.getFinalRequestResult()); Object[] args = { logMsgPrefix, url, status, statusText, elapsed }; if (!quiet) { logger.info("{} - [{}] - [{} - {}] Total time: {}", args); } }
public static void logResult(Result result, Logger logger, LoggerLevel level) { LoggerUtils.logLines("[" + result.getCommand() + "] - " + FormatUtils.getTime(result.getElapsed()), logger, level); LoggerUtils.logLines(result.getStdout(), logger, level); LoggerUtils.logLines(result.getStderr(), logger, LoggerLevel.WARN); if (result.getExitValue() != 0) { logger.warn("Exit value = {}", result.getExitValue()); } }