@Override // FSNamesystemMBean public String getTopUserOpCounts() { if (!topConf.isEnabled) { return null; } Date now = new Date(); final List<RollingWindowManager.TopWindow> topWindows = topMetrics.getTopWindows(); Map<String, Object> topMap = new TreeMap<String, Object>(); topMap.put("windows", topWindows); topMap.put("timestamp", DFSUtil.dateToIso8601String(now)); ObjectMapper mapper = new ObjectMapper(); try { return mapper.writeValueAsString(topMap); } catch (IOException e) { LOG.warn("Failed to fetch TopUser metrics", e); } return null; }
public TopMetrics(Configuration conf, int[] reportingPeriods) { logConf(conf); for (int i = 0; i < reportingPeriods.length; i++) { rollingWindowManagers.put(reportingPeriods[i], new RollingWindowManager( conf, reportingPeriods[i])); } }
/** * Get a list of the current TopWindow statistics, one TopWindow per tracked * time interval. */ public List<TopWindow> getTopWindows() { long monoTime = Time.monotonicNow(); List<TopWindow> windows = Lists.newArrayListWithCapacity (rollingWindowManagers.size()); for (Entry<Integer, RollingWindowManager> entry : rollingWindowManagers .entrySet()) { TopWindow window = entry.getValue().snapshot(monoTime); windows.add(window); } return windows; }
public void report(long currTime, String userName, String cmd) { LOG.debug("a metric is reported: cmd: {} user: {}", cmd, userName); userName = UserGroupInformation.trimLoginMethod(userName); for (RollingWindowManager rollingWindowManager : rollingWindowManagers .values()) { rollingWindowManager.recordMetric(currTime, cmd, userName, 1); rollingWindowManager.recordMetric(currTime, TopConf.ALL_CMDS, userName, 1); } }