Search in sources :

Example 1 with MetricsSnapshot

use of org.pentaho.di.core.metrics.MetricsSnapshot in project pentaho-kettle by pentaho.

the class LogChannel method snap.

@Override
public void snap(MetricsInterface metric, String subject, long... value) {
    if (!isGatheringMetrics()) {
        return;
    }
    String key = MetricsSnapshot.getKey(metric, subject);
    Map<String, MetricsSnapshotInterface> metricsMap = null;
    MetricsSnapshotInterface snapshot = null;
    Queue<MetricsSnapshotInterface> metricsList = null;
    switch(metric.getType()) {
        case MAX:
            // 
            if (value.length != 1) {
                // ignore
                break;
            }
            metricsMap = metricsRegistry.getSnapshotMap(logChannelId);
            snapshot = metricsMap.get(key);
            if (snapshot != null) {
                if (value[0] > snapshot.getValue()) {
                    snapshot.setValue(value[0]);
                    snapshot.setDate(new Date());
                }
            } else {
                snapshot = new MetricsSnapshot(MetricsSnapshotType.MAX, metric, subject, value[0], logChannelId);
                metricsMap.put(key, snapshot);
            }
            break;
        case MIN:
            // 
            if (value.length != 1) {
                // ignore
                break;
            }
            metricsMap = metricsRegistry.getSnapshotMap(logChannelId);
            snapshot = metricsMap.get(key);
            if (snapshot != null) {
                if (value[0] < snapshot.getValue()) {
                    snapshot.setValue(value[0]);
                    snapshot.setDate(new Date());
                }
            } else {
                snapshot = new MetricsSnapshot(MetricsSnapshotType.MIN, metric, subject, value[0], logChannelId);
                metricsMap.put(key, snapshot);
            }
            break;
        case SUM:
            metricsMap = metricsRegistry.getSnapshotMap(logChannelId);
            snapshot = metricsMap.get(key);
            if (snapshot != null) {
                snapshot.setValue(snapshot.getValue() + value[0]);
            } else {
                snapshot = new MetricsSnapshot(MetricsSnapshotType.SUM, metric, subject, value[0], logChannelId);
                metricsMap.put(key, snapshot);
            }
            break;
        case COUNT:
            metricsMap = metricsRegistry.getSnapshotMap(logChannelId);
            snapshot = metricsMap.get(key);
            if (snapshot != null) {
                snapshot.setValue(snapshot.getValue() + 1L);
            } else {
                snapshot = new MetricsSnapshot(MetricsSnapshotType.COUNT, metric, subject, 1L, logChannelId);
                metricsMap.put(key, snapshot);
            }
            break;
        case START:
            metricsList = metricsRegistry.getSnapshotList(logChannelId);
            snapshot = new MetricsSnapshot(MetricsSnapshotType.START, metric, subject, 1L, logChannelId);
            metricsList.add(snapshot);
            break;
        case STOP:
            metricsList = metricsRegistry.getSnapshotList(logChannelId);
            snapshot = new MetricsSnapshot(MetricsSnapshotType.STOP, metric, subject, 1L, logChannelId);
            metricsList.add(snapshot);
            break;
        default:
            break;
    }
}
Also used : MetricsSnapshotInterface(org.pentaho.di.core.metrics.MetricsSnapshotInterface) MetricsSnapshot(org.pentaho.di.core.metrics.MetricsSnapshot) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 MetricsSnapshot (org.pentaho.di.core.metrics.MetricsSnapshot)1 MetricsSnapshotInterface (org.pentaho.di.core.metrics.MetricsSnapshotInterface)1