use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class StatisticInfoImpl method create.
public static StatisticInfoImpl create(String toString, StatisticsFactory f) {
int startBrack = toString.indexOf("[");
int endBrack = toString.indexOf("]");
if (startBrack == -1 || endBrack == -1)
return null;
String name = toString.substring(0, startBrack).trim();
String ids = toString.substring(startBrack + 1, endBrack).trim();
StatisticsType type = f.findType(name);
if (type == null)
return null;
Statistics[] stats = f.findStatisticsByType(type);
if (stats.length == 0)
return null;
StatisticDescriptor[] descs = type.getStatistics();
for (int i = 0; i < descs.length; i++) {
if (descs[i].getName().equalsIgnoreCase(ids))
return new StatisticInfoImpl(stats[0], descs[i]);
}
return null;
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class VMStatsMonitor method handleNotification.
@Override
public void handleNotification(StatisticsNotification notification) {
for (StatisticId statId : notification) {
StatisticDescriptor descriptor = statId.getStatisticDescriptor();
String name = descriptor.getName();
Number value;
try {
value = notification.getValue(statId);
} catch (StatisticNotFoundException e) {
value = 0;
}
log(name, value);
statsMap.put(name, value);
}
refreshStats();
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class MBeanStatsMonitor method handleNotification.
@Override
public void handleNotification(final StatisticsNotification notification) {
for (StatisticId statId : notification) {
StatisticDescriptor descriptor = statId.getStatisticDescriptor();
String name = descriptor.getName();
Number value;
try {
value = notification.getValue(statId);
} catch (StatisticNotFoundException e) {
value = 0;
}
log(name, value);
statsMap.put(name, value);
}
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class StatAlertsManager method createMemberStatAlertDefinition.
/**
* Convert {@link StatAlertDefinition }(Created by client like GFMon2.0) with
* {@link DummyStatisticInfoImpl} to StatAlertDefinition with {@link StatisticInfoImpl}
*/
private StatAlertDefinition[] createMemberStatAlertDefinition(DistributionManager dm, StatAlertDefinition[] defns) {
dm.getCancelCriterion().checkCancelInProgress(null);
Statistics[] statistics;
StatisticsType type;
StatisticDescriptor desc;
String textId;
boolean skipDefinition = false;
List result = new ArrayList();
for (int i = 0; i < defns.length; i++) {
skipDefinition = false;
StatAlertDefinition defn = defns[i];
StatisticInfo[] statInfos = defn.getStatisticInfo();
for (int ii = 0; ii < statInfos.length && !skipDefinition; ii++) {
textId = statInfos[ii].getStatisticsTextId();
// TODO If none by TextID, use StatType and getAll.
statistics = dm.getSystem().findStatisticsByTextId(textId);
if (statistics.length == 0) {
logger.error(LocalizedMessage.create(LocalizedStrings.StatAlertsManager_STATALERTSMANAGER_CREATEMEMBERSTATALERTDEFINITION_STATISTICS_WITH_GIVEN_TEXTID_0_NOT_FOUND, textId));
skipDefinition = true;
// To print all errors
continue;
}
type = statistics[0].getType();
desc = type.nameToDescriptor(statInfos[ii].getStatisticName());
// Replace the actual StatInfo object
statInfos[ii] = new StatisticInfoImpl(statistics[0], desc);
if (logger.isDebugEnabled()) {
logger.debug("StatAlertsManager.createMemberStatAlertDefinition: created statInfo {}", statInfos[ii]);
}
}
if (!skipDefinition) {
defn.setStatisticInfo(statInfos);
result.add(defn);
if (logger.isDebugEnabled()) {
logger.debug("StatAlertsManager.createMemberStatAlertDefinition :: {}", defns[i].getStringRepresentation());
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("StatAlertsManager.createMemberStatAlertDefinition :: StatAlertDefinition {} is excluded", defn.getName());
}
}
}
return (StatAlertDefinition[]) result.toArray(new StatAlertDefinition[result.size()]);
}
use of org.apache.geode.StatisticDescriptor in project geode by apache.
the class StatArchiveWriterReaderIntegrationTest method testLongGaugeOneSample.
@Test
public void testLongGaugeOneSample() throws Exception {
final TestStatisticsManager manager = new TestStatisticsManager(1, getUniqueName(), WRITER_INITIAL_DATE_MILLIS);
final TestStatisticsSampler sampler = new TestStatisticsSampler(manager);
final SampleCollector sampleCollector = new SampleCollector(sampler);
final StatArchiveDescriptor archiveDescriptor = new StatArchiveDescriptor.Builder().setArchiveName(this.archiveFileName).setSystemId(1).setSystemStartTime(WRITER_INITIAL_DATE_MILLIS).setSystemDirectoryPath(this.testName.getMethodName()).setProductDescription(getClass().getSimpleName()).build();
final StatArchiveWriter writer = new TestStatArchiveWriter(archiveDescriptor);
sampleCollector.addSampleHandler(writer);
final StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { manager.createLongGauge("long_gauge_1", "d1", "u1") };
final StatisticsType ST1 = manager.createType("ST1", "ST1", statsST1);
final Statistics st1_1 = manager.createAtomicStatistics(ST1, "st1_1", 1);
incLong(st1_1, "long_gauge_1", 5);
final long sampleTimeNanos = WRITER_PREVIOUS_TIMESTAMP_NANOS + NANOS_PER_MILLI * 2;
sampleCollector.sample(sampleTimeNanos);
writer.close();
final StatisticDescriptor[] sds = ST1.getStatistics();
for (int i = 0; i < sds.length; i++) {
assertEquals(5L, st1_1.get(sds[i].getName()));
}
final StatArchiveReader reader = new StatArchiveReader(new File[] { new File(this.archiveFileName) }, null, false);
// compare all resourceInst values against what was printed above
final List resources = reader.getResourceInstList();
assertNotNull(resources);
assertEquals(1, resources.size());
final StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) resources.get(0);
assertNotNull(ri);
final String statsName = ri.getName();
assertNotNull(statsName);
assertEquals("st1_1", statsName);
assertEquals("ST1", ri.getType().getName());
final StatValue[] statValues = ri.getStatValues();
assertNotNull(statValues);
assertEquals(1, statValues.length);
final String statName = ri.getType().getStats()[0].getName();
assertNotNull(statName);
assertEquals("long_gauge_1", statName);
assertEquals(statName, statValues[0].getDescriptor().getName());
assertEquals(1, statValues[0].getSnapshotsSize());
assertEquals(5.0, statValues[0].getSnapshotsMostRecent(), 0.01);
final long[] timeStampsMillis = statValues[0].getRawAbsoluteTimeStamps();
assertNotNull(timeStampsMillis);
assertEquals(1, timeStampsMillis.length);
final long initialPreviousTimeStampMillis = NanoTimer.nanosToMillis(WRITER_PREVIOUS_TIMESTAMP_NANOS);
final long timeStampMillis = NanoTimer.nanosToMillis(sampleTimeNanos);
final long deltaMillis = timeStampMillis - initialPreviousTimeStampMillis;
assertEquals(2, deltaMillis);
final long expectedTimeStampMillis = deltaMillis + WRITER_INITIAL_DATE_MILLIS;
assertEquals(expectedTimeStampMillis, timeStampsMillis[0]);
final double[] snapshots = statValues[0].getRawSnapshots();
assertNotNull(snapshots);
assertEquals(1, snapshots.length);
assertEquals(5.0, snapshots[0], 0.01);
}
Aggregations