Search in sources :

Example 11 with StatisticDescriptor

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;
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

Example 12 with StatisticDescriptor

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();
}
Also used : StatisticNotFoundException(org.apache.geode.internal.statistics.StatisticNotFoundException) StatisticId(org.apache.geode.internal.statistics.StatisticId) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

Example 13 with StatisticDescriptor

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);
    }
}
Also used : StatisticNotFoundException(org.apache.geode.internal.statistics.StatisticNotFoundException) StatisticId(org.apache.geode.internal.statistics.StatisticId) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

Example 14 with StatisticDescriptor

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()]);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) ArrayList(java.util.ArrayList) StatisticInfo(org.apache.geode.internal.admin.statalerts.StatisticInfo) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) StatisticInfoImpl(org.apache.geode.internal.admin.statalerts.StatisticInfoImpl) DummyStatisticInfoImpl(org.apache.geode.internal.admin.statalerts.DummyStatisticInfoImpl)

Example 15 with StatisticDescriptor

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);
}
Also used : StatisticsType(org.apache.geode.StatisticsType) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) Statistics(org.apache.geode.Statistics) StatValue(org.apache.geode.internal.statistics.StatArchiveReader.StatValue) StatisticDescriptor(org.apache.geode.StatisticDescriptor) TestStatArchiveWriter(org.apache.geode.internal.statistics.TestStatArchiveWriter) List(java.util.List) File(java.io.File) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StatisticDescriptor (org.apache.geode.StatisticDescriptor)25 StatisticsType (org.apache.geode.StatisticsType)19 Statistics (org.apache.geode.Statistics)18 Test (org.junit.Test)13 File (java.io.File)11 List (java.util.List)11 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 StatValue (org.apache.geode.internal.statistics.StatArchiveReader.StatValue)9 TestStatArchiveWriter (org.apache.geode.internal.statistics.TestStatArchiveWriter)8 Iterator (java.util.Iterator)3 StatisticId (org.apache.geode.internal.statistics.StatisticId)3 StatisticNotFoundException (org.apache.geode.internal.statistics.StatisticNotFoundException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MainWithChildrenRollingFileHandler (org.apache.geode.internal.io.MainWithChildrenRollingFileHandler)2 Info (org.apache.geode.internal.statistics.TestSampleHandler.Info)2 ResourceInstanceInfo (org.apache.geode.internal.statistics.TestSampleHandler.ResourceInstanceInfo)2 ResourceTypeInfo (org.apache.geode.internal.statistics.TestSampleHandler.ResourceTypeInfo)2 SampledInfo (org.apache.geode.internal.statistics.TestSampleHandler.SampledInfo)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2