Search in sources :

Example 1 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 2 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 3 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 4 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 5 with StatisticDescriptor

use of org.apache.geode.StatisticDescriptor in project geode by apache.

the class DistributedSystemStatisticsIntegrationTest method setUpDoubleStatistics.

private Statistics setUpDoubleStatistics(final int count) {
    String[] descriptions = new String[] { "ONE", "TWO", "THREE" };
    StatisticDescriptor[] descriptors = new StatisticDescriptor[count];
    for (int i = 0; i < count; i++) {
        descriptors[i] = factory().createDoubleGauge(this.statNames[i], descriptions[i], "x");
    }
    StatisticsType type = factory().createType(getUniqueName(), "", descriptors);
    Statistics stats = factory().createStatistics(type, "Display");
    for (int i = 0; i < count; i++) {
        stats.setDouble(this.statNames[i], 0.0);
    }
    return stats;
}
Also used : StatisticsType(org.apache.geode.StatisticsType) Statistics(org.apache.geode.Statistics) StatisticDescriptor(org.apache.geode.StatisticDescriptor)

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