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();
}
}
Aggregations