Fixed issue where map was overridden and only last value saved.

This commit is contained in:
Mark Nellemann 2020-09-03 16:12:07 +02:00
parent 45f6dd05fd
commit 1f2235f16d
6 changed files with 135 additions and 17 deletions

View file

@ -1,2 +1,2 @@
group = biz.nellemann.hmci group = biz.nellemann.hmci
version = 1.0.5 version = 1.0.7

View file

@ -133,8 +133,16 @@ class InfluxClient {
batchPoints.point(it) batchPoints.point(it)
} }
getSystemGenericPhysicalAdapters(system, timestamp).each {
batchPoints.point(it)
}
getSystemGenericVirtualAdapters(system, timestamp).each {
batchPoints.point(it)
}
} }
private static List<Point> getSystemMemory(ManagedSystem system, Instant timestamp) { private static List<Point> getSystemMemory(ManagedSystem system, Instant timestamp) {
List<Map> metrics = system.getMemoryMetrics() List<Map> metrics = system.getMemoryMetrics()
return processMeasurementMap(metrics, timestamp, "SystemMemory") return processMeasurementMap(metrics, timestamp, "SystemMemory")
@ -160,6 +168,16 @@ class InfluxClient {
return processMeasurementMap(metrics, timestamp, "SystemFiberChannelAdapters") return processMeasurementMap(metrics, timestamp, "SystemFiberChannelAdapters")
} }
private static List<Point> getSystemGenericPhysicalAdapters(ManagedSystem system, Instant timestamp) {
List<Map> metrics = system.getSystemGenericPhysicalAdapters()
return processMeasurementMap(metrics, timestamp, "SystemGenericPhysicalAdapters")
}
private static List<Point> getSystemGenericVirtualAdapters(ManagedSystem system, Instant timestamp) {
List<Map> metrics = system.getSystemGenericVirtualAdapters()
return processMeasurementMap(metrics, timestamp, "SystemGenericVirtualAdapters")
}
/* /*
Logical Partitions Logical Partitions
@ -180,6 +198,10 @@ class InfluxClient {
//BatchPoints batchPoints = BatchPoints.database(database).build(); //BatchPoints batchPoints = BatchPoints.database(database).build();
getPartitionAffinityScore(partition, timestamp).each {
batchPoints.point(it)
}
getPartitionMemory(partition, timestamp).each { getPartitionMemory(partition, timestamp).each {
batchPoints.point(it) batchPoints.point(it)
} }
@ -199,6 +221,11 @@ class InfluxClient {
//influxDB.write(batchPoints); //influxDB.write(batchPoints);
} }
private static List<Point> getPartitionAffinityScore(LogicalPartition partition, Instant timestamp) {
List<Map> metrics = partition.getAffinityScore()
return processMeasurementMap(metrics, timestamp, "PartitionAffinityScore")
}
private static List<Point> getPartitionMemory(LogicalPartition partition, Instant timestamp) { private static List<Point> getPartitionMemory(LogicalPartition partition, Instant timestamp) {
List<Map> metrics = partition.getMemoryMetrics() List<Map> metrics = partition.getMemoryMetrics()
return processMeasurementMap(metrics, timestamp, "PartitionMemory") return processMeasurementMap(metrics, timestamp, "PartitionMemory")
@ -233,6 +260,7 @@ class InfluxClient {
// Iterate fields // Iterate fields
map.get("fields").each { String fieldName, BigDecimal fieldValue -> map.get("fields").each { String fieldName, BigDecimal fieldValue ->
log.debug("processMeasurementMap() " + measurement + " - fieldName: " + fieldName + ", fieldValue: " + fieldValue)
Point.Builder builder = Point.measurement(measurement) Point.Builder builder = Point.measurement(measurement)
.time(timestamp.toEpochMilli(), TimeUnit.MILLISECONDS) .time(timestamp.toEpochMilli(), TimeUnit.MILLISECONDS)
@ -242,6 +270,7 @@ class InfluxClient {
// For each field, we add all tags // For each field, we add all tags
map.get("tags").each { String tagName, String tagValue -> map.get("tags").each { String tagName, String tagValue ->
builder.tag(tagName, tagValue) builder.tag(tagName, tagValue)
log.debug("processMeasurementMap() " + measurement + " - tagName: " + tagName + ", tagValue: " + tagValue)
} }
list.add(builder.build()) list.add(builder.build())

View file

@ -37,6 +37,29 @@ class LogicalPartition extends MetaSystem {
} }
List<Map> getAffinityScore() {
List<Map> list = new ArrayList<>()
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [
system: system.name,
partition: name,
]
map.put("tags", tagsMap)
log.debug("getAffinityScore() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [
affinityScore: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.affinityScore,
]
map.put("fields", fieldsMap)
log.debug("getAffinityScore() - fields: " + fieldsMap.toString())
list.add(map)
return list
}
List<Map> getMemoryMetrics() { List<Map> getMemoryMetrics() {
List<Map> list = new ArrayList<>() List<Map> list = new ArrayList<>()
@ -75,10 +98,10 @@ class LogicalPartition extends MetaSystem {
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, BigDecimal> fieldsMap = [
utilizedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedProcUnits?.first(), utilizedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedProcUnits?.first(),
//maxVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxVirtualProcessors.first(), maxVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxVirtualProcessors.first(),
//currentVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.currentVirtualProcessors.first(), currentVirtualProcessors: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.currentVirtualProcessors.first(),
//donatedProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.donatedProcUnits.first(), //donatedProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.donatedProcUnits.first(),
//entitledProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.entitledProcUnits.first(), entitledProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.entitledProcUnits.first(),
//idleProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.idleProcUnits.first(), //idleProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.idleProcUnits.first(),
//maxProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxProcUnits.first(), //maxProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxProcUnits.first(),
utilizedCappedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedCappedProcUnits?.first(), utilizedCappedProcUnits: metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.processor?.utilizedCappedProcUnits?.first(),
@ -97,8 +120,8 @@ class LogicalPartition extends MetaSystem {
List<Map> getVirtualEthernetAdapterMetrics() { List<Map> getVirtualEthernetAdapterMetrics() {
List<Map> list = new ArrayList<>() List<Map> list = new ArrayList<>()
Map<String, Map> map = new HashMap<String, Map>()
metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.network?.virtualEthernetAdapters?.each { metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.network?.virtualEthernetAdapters?.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [ HashMap<String, String> tagsMap = [
system: system.name, system: system.name,
@ -131,8 +154,8 @@ class LogicalPartition extends MetaSystem {
List<Map> getVirtualFiberChannelAdaptersMetrics() { List<Map> getVirtualFiberChannelAdaptersMetrics() {
List<Map> list = new ArrayList<>() List<Map> list = new ArrayList<>()
Map<String, Map> map = new HashMap<String, Map>()
metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.storage?.virtualFiberChannelAdapters?.each { metrics.systemUtil?.utilSamples?.first()?.lparsUtil?.first()?.storage?.virtualFiberChannelAdapters?.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [ HashMap<String, String> tagsMap = [
system: system.name, system: system.name,
@ -146,6 +169,7 @@ class LogicalPartition extends MetaSystem {
HashMap<String, BigDecimal> fieldsMap = [ HashMap<String, BigDecimal> fieldsMap = [
transmittedBytes: it.transmittedBytes.first(), transmittedBytes: it.transmittedBytes.first(),
writeBytes: it.writeBytes.first(), writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(),
] ]
map.put("fields", fieldsMap) map.put("fields", fieldsMap)
log.debug("getVirtualFiberChannelAdaptersMetrics() - fields: " + fieldsMap.toString()) log.debug("getVirtualFiberChannelAdaptersMetrics() - fields: " + fieldsMap.toString())

View file

@ -96,8 +96,8 @@ class ManagedSystem extends MetaSystem {
List<Map> getSharedProcessorPools() { List<Map> getSharedProcessorPools() {
List<Map> list = new ArrayList<>() List<Map> list = new ArrayList<>()
Map<String, Map> map = new HashMap<String, Map>()
metrics.systemUtil?.utilSamples?.first()?.serverUtil?.sharedProcessorPool?.each { metrics.systemUtil?.utilSamples?.first()?.serverUtil?.sharedProcessorPool?.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [ HashMap<String, String> tagsMap = [
system: name, system: name,
@ -124,10 +124,9 @@ class ManagedSystem extends MetaSystem {
List<Map> getSystemSharedAdapters() { List<Map> getSystemSharedAdapters() {
List<Map> list = new ArrayList<>() List<Map> list = new ArrayList<>()
Map<String, Map> map = new HashMap<String, Map>()
metrics.systemUtil?.utilSamples?.first()?.viosUtil?.each {vios -> metrics.systemUtil?.utilSamples?.first()?.viosUtil?.each {vios ->
vios.network.sharedAdapters.each { vios.network.sharedAdapters.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [ HashMap<String, String> tagsMap = [
system: name, system: name,
@ -157,11 +156,13 @@ class ManagedSystem extends MetaSystem {
List<Map> getSystemFiberChannelAdapters() { List<Map> getSystemFiberChannelAdapters() {
List<Map> list = new ArrayList<>() List<Map> list = new ArrayList<>()
Map<String, Map> map = new HashMap<String, Map>()
metrics.systemUtil?.utilSamples?.first()?.viosUtil?.each { vios -> metrics.systemUtil?.utilSamples?.first()?.viosUtil?.each { vios ->
log.debug("getSystemFiberChannelAdapters() - VIOS: " + vios.name)
vios.storage?.fiberChannelAdapters?.each { vios.storage?.fiberChannelAdapters?.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [ HashMap<String, String> tagsMap = [
id: it.id,
system: name, system: name,
wwpn: it.wwpn, wwpn: it.wwpn,
vios: vios.name, vios: vios.name,
@ -178,6 +179,38 @@ class ManagedSystem extends MetaSystem {
map.put("fields", fieldsMap) map.put("fields", fieldsMap)
log.debug("getSystemFiberChannelAdapters() - fields: " + fieldsMap.toString()) log.debug("getSystemFiberChannelAdapters() - fields: " + fieldsMap.toString())
list.add(map)
}
}
return list
}
List<Map> getSystemGenericPhysicalAdapters() {
List<Map> list = new ArrayList<>()
metrics.systemUtil?.utilSamples?.first()?.viosUtil?.each { vios ->
vios.storage?.genericPhysicalAdapters?.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [
id: it.id,
system: name,
vios: vios.name,
device: it.physicalLocation,
]
map.put("tags", tagsMap)
log.debug("getSystemGenericPhysicalAdapters() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [
writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(),
transmittedBytes: it.transmittedBytes.first(),
]
map.put("fields", fieldsMap)
log.debug("getSystemGenericPhysicalAdapters() - fields: " + fieldsMap.toString())
list.add(map) list.add(map)
} }
@ -188,4 +221,36 @@ class ManagedSystem extends MetaSystem {
} }
List<Map> getSystemGenericVirtualAdapters() {
List<Map> list = new ArrayList<>()
metrics.systemUtil?.utilSamples?.first()?.viosUtil?.each { vios ->
vios.storage?.genericVirtualAdapters?.each {
Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = [
id: it.id,
system: name,
vios: vios.name,
device: it.physicalLocation,
]
map.put("tags", tagsMap)
log.debug("getSystemGenericVirtualAdapters() - tags: " + tagsMap.toString())
HashMap<String, BigDecimal> fieldsMap = [
writeBytes: it.writeBytes.first(),
readBytes: it.readBytes.first(),
transmittedBytes: it.transmittedBytes.first(),
]
map.put("fields", fieldsMap)
log.debug("getSystemGenericVirtualAdapters() - fields: " + fieldsMap.toString())
list.add(map)
}
}
return list
}
} }

View file

@ -9,10 +9,10 @@ class GenericVirtualAdapter {
String type String type
Integer viosId Integer viosId
String physicalLocation String physicalLocation
BigDecimal numOfReads List<BigDecimal> numOfReads
BigDecimal numOfWrites List<BigDecimal> numOfWrites
BigDecimal readBytes List<BigDecimal> readBytes
BigDecimal writeBytes List<BigDecimal> writeBytes
BigDecimal transmittedBytes List<BigDecimal> transmittedBytes
} }

View file

@ -94,8 +94,8 @@ class LogicalPartitionTest extends Specification {
then: then:
listOfMaps.size() == 4 listOfMaps.size() == 4
listOfMaps.first().get("fields")['writeBytes'] == 546.133 listOfMaps.first().get("fields")['writeBytes'] == 6690.133
listOfMaps.first().get("tags")['viosId'] == '2' listOfMaps.first().get("tags")['viosId'] == '1'
} }