use of org.apache.geode.internal.statistics.StatArchiveReader in project geode by apache.
the class SystemAdmin method statistics.
/**
* List the statistics of a running system.
*
* @param directory the system directory of the system to list.
* @param archiveNames the archive file(s) to read.
* @param details if true the statistic descriptions will also be listed.
* @param nofilter if true then printed stat values will all be raw unfiltered.
* @param persec if true then printed stat values will all be the rate of change, per second, of
* the raw values.
* @param persample if true then printed stat values will all be the rate of change, per sample,
* of the raw values.
* @param prunezeros if true then stat values whose samples are all zero will not be printed.
*
* @throws UncreatedSystemException if the system <code>sysDir</code> does not exist, is not a
* directory, or does not contain a configuration file.
* @throws NoSystemException if the system is not running or could not be connected to.
* @throws IllegalArgumentException if a statSpec does not match a resource and/or statistic.
* @throws GemFireIOException if the archive could not be read
*/
public void statistics(File directory, List archiveNames, boolean details, boolean nofilter, boolean persec, boolean persample, boolean prunezeros, boolean monitor, long startTime, long endTime, List cmdLineSpecs) {
if (persec && nofilter) {
throw new IllegalArgumentException(LocalizedStrings.SystemAdmin_THE_NOFILTER_AND_PERSEC_OPTIONS_ARE_MUTUALLY_EXCLUSIVE.toLocalizedString());
}
if (persec && persample) {
throw new IllegalArgumentException(LocalizedStrings.SystemAdmin_THE_PERSAMPLE_AND_PERSEC_OPTIONS_ARE_MUTUALLY_EXCLUSIVE.toLocalizedString());
}
if (nofilter && persample) {
throw new IllegalArgumentException(LocalizedStrings.SystemAdmin_THE_PERSAMPLE_AND_NOFILTER_OPTIONS_ARE_MUTUALLY_EXCLUSIVE.toLocalizedString());
}
StatSpec[] specs = createSpecs(cmdLineSpecs);
if (archiveOption != null) {
if (directory != null) {
throw new IllegalArgumentException(LocalizedStrings.SystemAdmin_THE_ARCHIVE_AND_DIR_OPTIONS_ARE_MUTUALLY_EXCLUSIVE.toLocalizedString());
}
StatArchiveReader reader = null;
boolean interrupted = false;
try {
reader = new StatArchiveReader((File[]) archiveNames.toArray(new File[archiveNames.size()]), specs, !monitor);
// (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
if (specs.length == 0) {
if (details) {
StatArchiveReader.StatArchiveFile[] archives = reader.getArchives();
for (int i = 0; i < archives.length; i++) {
System.out.println(archives[i].getArchiveInfo().toString());
}
}
}
do {
if (specs.length == 0) {
Iterator it = reader.getResourceInstList().iterator();
while (it.hasNext()) {
ResourceInst inst = (ResourceInst) it.next();
StatValue[] values = inst.getStatValues();
boolean firstTime = true;
for (int i = 0; i < values.length; i++) {
if (values[i] != null && values[i].hasValueChanged()) {
if (firstTime) {
firstTime = false;
System.out.println(inst.toString());
}
printStatValue(values[i], startTime, endTime, nofilter, persec, persample, prunezeros, details);
}
}
}
} else {
Map<CombinedResources, List<StatValue>> allSpecsMap = new HashMap<CombinedResources, List<StatValue>>();
for (int i = 0; i < specs.length; i++) {
StatValue[] values = reader.matchSpec(specs[i]);
if (values.length == 0) {
if (!quiet) {
System.err.println(LocalizedStrings.SystemAdmin_WARNING_NO_STATS_MATCHED_0.toLocalizedString(specs[i].cmdLineSpec));
}
} else {
Map<CombinedResources, List<StatValue>> specMap = new HashMap<CombinedResources, List<StatValue>>();
for (StatValue v : values) {
CombinedResources key = new CombinedResources(v);
List<StatArchiveReader.StatValue> list = specMap.get(key);
if (list != null) {
list.add(v);
} else {
specMap.put(key, new ArrayList<StatValue>(Collections.singletonList(v)));
}
}
if (!quiet) {
System.out.println(LocalizedStrings.SystemAdmin_INFO_FOUND_0_MATCHES_FOR_1.toLocalizedString(new Object[] { Integer.valueOf(specMap.size()), specs[i].cmdLineSpec }));
}
for (Map.Entry<CombinedResources, List<StatValue>> me : specMap.entrySet()) {
List<StatArchiveReader.StatValue> list = allSpecsMap.get(me.getKey());
if (list != null) {
list.addAll(me.getValue());
} else {
allSpecsMap.put(me.getKey(), me.getValue());
}
}
}
}
for (Map.Entry<CombinedResources, List<StatValue>> me : allSpecsMap.entrySet()) {
System.out.println(me.getKey());
for (StatValue v : me.getValue()) {
printStatValue(v, startTime, endTime, nofilter, persec, persample, prunezeros, details);
}
}
}
if (monitor) {
while (!reader.update()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
interrupted = true;
}
}
}
} while (monitor && !interrupted);
} catch (IOException ex) {
throw new GemFireIOException(LocalizedStrings.SystemAdmin_FAILED_READING_0.toLocalizedString(archiveOption), ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
}
Aggregations