Search in sources :

Example 1 with LoggingMetric

use of org.pentaho.di.core.logging.LoggingMetric in project pentaho-kettle by pentaho.

the class Trans method writeMetricsInformation.

protected synchronized void writeMetricsInformation() throws KettleException {
    // 
    List<MetricsDuration> metricsList = MetricsUtil.getDuration(log.getLogChannelId(), Metrics.METRIC_PLUGIN_REGISTRY_REGISTER_EXTENSIONS_START);
    if ((log != null) && (log.isDebug()) && !metricsList.isEmpty()) {
        log.logDebug(metricsList.get(0).toString());
    }
    metricsList = MetricsUtil.getDuration(log.getLogChannelId(), Metrics.METRIC_PLUGIN_REGISTRY_PLUGIN_REGISTRATION_START);
    if ((log != null) && (log.isDebug()) && !metricsList.isEmpty()) {
        log.logDebug(metricsList.get(0).toString());
    }
    long total = 0;
    metricsList = MetricsUtil.getDuration(log.getLogChannelId(), Metrics.METRIC_PLUGIN_REGISTRY_PLUGIN_TYPE_REGISTRATION_START);
    if ((log != null) && (log.isDebug()) && metricsList != null && !metricsList.isEmpty()) {
        for (MetricsDuration duration : metricsList) {
            total += duration.getDuration();
            log.logDebug("   - " + duration.toString() + "  Total=" + total);
        }
    }
    Database db = null;
    MetricsLogTable metricsLogTable = transMeta.getMetricsLogTable();
    try {
        db = new Database(this, metricsLogTable.getDatabaseMeta());
        db.shareVariablesWith(this);
        db.connect();
        db.setCommit(logCommitSize);
        List<String> logChannelIds = LoggingRegistry.getInstance().getLogChannelChildren(getLogChannelId());
        for (String logChannelId : logChannelIds) {
            Queue<MetricsSnapshotInterface> snapshotList = MetricsRegistry.getInstance().getSnapshotLists().get(logChannelId);
            if (snapshotList != null) {
                Iterator<MetricsSnapshotInterface> iterator = snapshotList.iterator();
                while (iterator.hasNext()) {
                    MetricsSnapshotInterface snapshot = iterator.next();
                    db.writeLogRecord(metricsLogTable, LogStatus.START, new LoggingMetric(batchId, snapshot), null);
                }
            }
            Map<String, MetricsSnapshotInterface> snapshotMap = MetricsRegistry.getInstance().getSnapshotMaps().get(logChannelId);
            if (snapshotMap != null) {
                synchronized (snapshotMap) {
                    Iterator<MetricsSnapshotInterface> iterator = snapshotMap.values().iterator();
                    while (iterator.hasNext()) {
                        MetricsSnapshotInterface snapshot = iterator.next();
                        db.writeLogRecord(metricsLogTable, LogStatus.START, new LoggingMetric(batchId, snapshot), null);
                    }
                }
            }
        }
        // Also time-out the log records in here...
        // 
        db.cleanupLogRecords(metricsLogTable);
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "Trans.Exception.UnableToWriteMetricsInformationToLogTable"), e);
    } finally {
        if (!db.isAutoCommit()) {
            db.commit(true);
        }
        db.disconnect();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) MetricsLogTable(org.pentaho.di.core.logging.MetricsLogTable) MetricsSnapshotInterface(org.pentaho.di.core.metrics.MetricsSnapshotInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) LoggingMetric(org.pentaho.di.core.logging.LoggingMetric) Database(org.pentaho.di.core.database.Database) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Database (org.pentaho.di.core.database.Database)1 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)1 KettleException (org.pentaho.di.core.exception.KettleException)1 KettleFileException (org.pentaho.di.core.exception.KettleFileException)1 KettleTransException (org.pentaho.di.core.exception.KettleTransException)1 KettleValueException (org.pentaho.di.core.exception.KettleValueException)1 LoggingMetric (org.pentaho.di.core.logging.LoggingMetric)1 MetricsLogTable (org.pentaho.di.core.logging.MetricsLogTable)1 MetricsDuration (org.pentaho.di.core.metrics.MetricsDuration)1 MetricsSnapshotInterface (org.pentaho.di.core.metrics.MetricsSnapshotInterface)1 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)1 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1