hmci/src/main/groovy/biz/nellemann/hmci/MetaSystem.groovy

39 lines
1.1 KiB
Groovy
Raw Normal View History

package biz.nellemann.hmci
import biz.nellemann.hmci.pojo.PcmData
import groovy.json.JsonSlurper
import groovy.util.logging.Slf4j
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException
@Slf4j
abstract class MetaSystem {
protected PcmData metrics
void processMetrics(String json) {
def pcmMap = new JsonSlurper().parseText(json)
metrics = new PcmData(pcmMap as Map)
}
Instant getTimestamp() {
2020-08-14 07:34:44 +00:00
String timestamp = metrics.systemUtil.utilSamples.first().sampleInfo.timeStamp
Instant instant
try {
2020-08-14 07:34:44 +00:00
log.debug("getTimeStamp() - PMC Timestamp: " + timestamp)
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss[XXX][X]");
2020-08-14 07:34:44 +00:00
instant = Instant.from(dateTimeFormatter.parse(timestamp))
log.debug("getTimestamp() - Instant: " + instant.toString())
} catch(DateTimeParseException e) {
2020-08-14 07:34:44 +00:00
log.warn("getTimestamp() - parse error: " + timestamp)
}
2020-08-14 07:34:44 +00:00
return instant ?: Instant.now()
}
}