>> recordSet = rIter.next();
+// }
+// }
}
}
+// @Override
+ public void process(CommandLine cmdln) {
+ init(cmdln);
+ execute();
+ }
protected void getHelp() {
StringBuilder sb = new StringBuilder();
- sb.append("Collect Container Stats for the YARN REST API.").append("\n");
-
+ sb.append("Collect Application Container Stats for the YARN REST API.").append("\n");
System.out.println(sb.toString());
}
+ @Override
+ public Options getOptions() {
+ Options options = super.getOptions();
+
+ OptionGroup beginOptionGroup = new OptionGroup();
+ Option startOption = new Option("s", "start", true,
+ "Start time for retrieval in 'yyyy-MM-dd HH:mm:ss'");
+ startOption.setRequired(false);
+ beginOptionGroup.addOption(startOption);
+
+ Option lastOption = new Option("l", "last", true,
+ "last x-DAY(S)|x-HOUR(S)|x-MIN(S). 1-HOUR=1 hour, 2-DAYS=2 days, 3-HOURS=3 hours, etc.");
+ lastOption.setRequired(false);
+ beginOptionGroup.addOption(lastOption);
+ options.addOptionGroup(beginOptionGroup);
+
+ // TODO: WIP for current stats.
+// Option currentOption = new Option("c", "current", false, "Get Current / Active Records");
+// currentOption.setRequired(false);
+// beginOptionGroup.addOption(currentOption);
+
+ Option endOption = new Option("e", "end", true,
+ "End time for retrieval in 'yyyy-MM-dd HH:mm:ss'");
+ endOption.setRequired(false);
+ options.addOption(endOption);
+
+ Option incOption = new Option("inc", "increment", true, "Query Increment in minutes");
+ incOption.setRequired(false);
+ options.addOption(incOption);
+
+ return options;
+ }
}
diff --git a/src/main/java/com/cloudera/utils/hadoop/yarn/ContainerStatsCommand.java b/src/main/java/com/cloudera/utils/hadoop/yarn/ContainerStatsCommand.java
new file mode 100644
index 0000000..5e8808a
--- /dev/null
+++ b/src/main/java/com/cloudera/utils/hadoop/yarn/ContainerStatsCommand.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2022. David W. Streever All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.cloudera.utils.hadoop.yarn;
+
+import com.cloudera.utils.hadoop.AbstractStats;
+import com.cloudera.utils.hadoop.hdfs.shell.command.Direction;
+import com.cloudera.utils.hadoop.shell.Environment;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Created by streever on 2016-04-25.
+ *
+ * Using the Resource Manager JMX, collect the stats on applications since the last time this was run or up to
+ * 'n' (limit).
+ */
+public class ContainerStatsCommand extends AbstractStats {
+
+ private ContainerStats containerStats = null;
+ @Override
+ public String getDescription() {
+ return "Collect Container Stats from the YARN REST API";
+ }
+
+ public ContainerStatsCommand(String name, Environment env, Direction directionContext) {
+ super(name, env, directionContext);
+// appStats = new ContainerStatsImpl(env.getConfig());
+ }
+
+ public ContainerStatsCommand(String name, Environment env, Direction directionContext, int directives) {
+ super(name, env, directionContext, directives);
+ }
+
+ public ContainerStatsCommand(String name, Environment env, Direction directionContext, int directives, boolean directivesBefore, boolean directivesOptional) {
+ super(name, env, directionContext, directives, directivesBefore, directivesOptional);
+ }
+
+ public ContainerStatsCommand(String name, Environment env) {
+ super(name, env);
+ }
+
+ protected ContainerStats getContainerStats() {
+ if (containerStats == null)
+ containerStats = new ContainerStats(env.getConfig());
+ return containerStats;
+ }
+ @Override
+ public void process(CommandLine cmdln) {
+ getContainerStats().process(cmdln);
+ Iterator>>> rIter = getContainerStats().getRecords().entrySet().iterator();
+ while (rIter.hasNext()) {
+ Map.Entry>> recordSet = rIter.next();
+ print(recordSet.getKey(), getContainerStats().getRecordFieldMap().get(recordSet.getKey()), recordSet.getValue());
+ }
+ getContainerStats().clearCache();
+ }
+
+ @Override
+ public Options getOptions() {
+ Options options = super.getOptions();
+ Options csOptions = getContainerStats().getOptions();
+ for (Object option: csOptions.getOptions()) {
+ if (option instanceof Option) {
+ options.addOption((Option)option);
+ } else if (option instanceof OptionGroup) {
+ options.addOptionGroup((OptionGroup)option);
+ }
+ }
+ return options;
+ }
+
+ protected void getHelp() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Collect Container Stats for the YARN REST API.").append("\n");
+
+ System.out.println(sb.toString());
+ }
+
+
+}
diff --git a/src/main/java/com/cloudera/utils/hadoop/yarn/ResourceManagerStats.java b/src/main/java/com/cloudera/utils/hadoop/yarn/ResourceManagerStats.java
new file mode 100644
index 0000000..3a436be
--- /dev/null
+++ b/src/main/java/com/cloudera/utils/hadoop/yarn/ResourceManagerStats.java
@@ -0,0 +1,357 @@
+package com.cloudera.utils.hadoop.yarn;
+
+import com.cloudera.utils.hadoop.shell.Environment;
+import com.cloudera.utils.hadoop.shell.command.CommandReturn;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.math.NumberUtils;
+import org.apache.hadoop.conf.Configuration;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public abstract class ResourceManagerStats implements Stats {
+
+ protected ObjectMapper mapper = new ObjectMapper();
+
+ protected Configuration configuration = null;
+
+ protected Boolean ssl = Boolean.FALSE;
+ protected Boolean raw = Boolean.FALSE;
+
+ protected Long increment = 60l * 60l * 1000l; // 1 hour
+
+ /**
+ * The earliest start time to get available jobs. Time since Epoch...
+ */
+ protected Long startTime = 0l;
+ protected Long endTime = 0l;
+
+ protected Map>> records = new LinkedHashMap>>();
+
+ private Options options;
+
+ public Boolean getSsl() {
+ return ssl;
+ }
+
+ public void setSsl(Boolean ssl) {
+ this.ssl = ssl;
+ }
+
+ public Boolean getRaw() {
+ return raw;
+ }
+
+ public void setRaw(Boolean raw) {
+ this.raw = raw;
+ }
+
+ public Long getIncrement() {
+ return increment;
+ }
+
+ public void setIncrement(Long increment) {
+ this.increment = increment;
+ }
+
+ public Long getStartTime() {
+ return startTime;
+ }
+
+ public void setStartTime(Long startTime) {
+ this.startTime = startTime;
+ }
+
+ public Long getEndTime() {
+ return endTime;
+ }
+
+ public void setEndTime(Long endTime) {
+ this.endTime = endTime;
+ }
+
+ public ResourceManagerStats(Configuration configuration) {
+ setConfiguration(configuration);
+ }
+
+ public ResourceManagerStats() {
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
+ public List