Cleanup code.

This commit is contained in:
Mark Nellemann 2020-12-01 11:48:05 +01:00
parent ec14809d2d
commit ebf84c8350
5 changed files with 109 additions and 197 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.idea
.vscode
.gradle
.project
.classpath

View file

@ -193,7 +193,7 @@ class HmcClient {
Map<String, LogicalPartition> getLogicalPartitionsForManagedSystem(ManagedSystem system) throws Exception {
URL url = new URL(String.format("%s/rest/api/uom/ManagedSystem/%s/LogicalPartition", baseUrl, system.id));
String responseBody = getResponse(url);
Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {};
Map<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>();
// Do not try to parse empty response
if(responseBody == null || responseBody.isEmpty() || responseBody.length() <= 1) {

View file

@ -49,24 +49,14 @@ class LogicalPartition extends MetaSystem {
List<Measurement> getAffinityScore() {
List<Measurement> list = new ArrayList<>();
//Map<String, Map> map = new HashMap<String, Map>()
Map<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", system.name);
put("partition", name);
}
};
//map.put("tags", tagsMap)
Map<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", system.name);
tagsMap.put("partition", name);
log.debug("getAffinityScore() - tags: " + tagsMap.toString());
Map<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("affinityScore", metrics.systemUtil.sample.lparsUtil.affinityScore);
}
};
//map.put("fields", fieldsMap)
Map<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("affinityScore", metrics.systemUtil.sample.lparsUtil.affinityScore);
log.debug("getAffinityScore() - fields: " + fieldsMap.toString());
Measurement measurement = new Measurement(tagsMap, fieldsMap);
@ -78,27 +68,15 @@ class LogicalPartition extends MetaSystem {
List<Measurement> getMemoryMetrics() {
List<Measurement> list = new ArrayList<>();
//Map<String, Map> map = new HashMap<String, Map>()
Map<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", system.name);
put("partition", name);
}
};
//map.put("tags", tagsMap)
Map<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", system.name);
tagsMap.put("partition", name);
log.debug("getMemoryMetrics() - tags: " + tagsMap.toString());
Map<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("logicalMem", metrics.systemUtil.sample.lparsUtil.memory.logicalMem);
put("backedPhysicalMem", metrics.systemUtil.sample.lparsUtil.memory.backedPhysicalMem);
}
};
//map.put("fields", fieldsMap)
Map<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("logicalMem", metrics.systemUtil.sample.lparsUtil.memory.logicalMem);
fieldsMap.put("backedPhysicalMem", metrics.systemUtil.sample.lparsUtil.memory.backedPhysicalMem);
log.debug("getMemoryMetrics() - fields: " + fieldsMap.toString());
Measurement measurement = new Measurement(tagsMap, fieldsMap);
@ -111,35 +89,24 @@ class LogicalPartition extends MetaSystem {
List<Measurement> getProcessorMetrics() {
List<Measurement> list = new ArrayList<>();
//Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", system.name);
put("partition", name);
}
};
//map.put("tags", tagsMap)
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", system.name);
tagsMap.put("partition", name);
log.debug("getProcessorMetrics() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("utilizedProcUnits", metrics.systemUtil.sample.lparsUtil.processor.utilizedProcUnits);
put("maxVirtualProcessors", metrics.systemUtil.sample.lparsUtil.processor.maxVirtualProcessors);
put("currentVirtualProcessors", metrics.systemUtil.sample.lparsUtil.processor.currentVirtualProcessors);
//donatedProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.donatedProcUnits.first(),
put("entitledProcUnits", metrics.systemUtil.sample.lparsUtil.processor.entitledProcUnits);
//idleProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.idleProcUnits.first(),
//maxProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxProcUnits.first(),
put("utilizedCappedProcUnits", metrics.systemUtil.sample.lparsUtil.processor.utilizedCappedProcUnits);
put("utilizedUncappedProcUnits", metrics.systemUtil.sample.lparsUtil.processor.utilizedUncappedProcUnits);
put("timePerInstructionExecution", metrics.systemUtil.sample.lparsUtil.processor.timeSpentWaitingForDispatch);
put("timeSpentWaitingForDispatch", metrics.systemUtil.sample.lparsUtil.processor.timePerInstructionExecution);
}
};
//map.put("fields", fieldsMap)
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("utilizedProcUnits", metrics.systemUtil.sample.lparsUtil.processor.utilizedProcUnits);
fieldsMap.put("maxVirtualProcessors", metrics.systemUtil.sample.lparsUtil.processor.maxVirtualProcessors);
fieldsMap.put("currentVirtualProcessors", metrics.systemUtil.sample.lparsUtil.processor.currentVirtualProcessors);
//fieldsMap.donatedProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.donatedProcUnits.first(),
fieldsMap.put("entitledProcUnits", metrics.systemUtil.sample.lparsUtil.processor.entitledProcUnits);
//fieldsMap.idleProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.idleProcUnits.first(),
//fieldsMap.maxProcUnits: metrics.systemUtil.utilSamples.first().lparsUtil.first().processor.maxProcUnits.first(),
fieldsMap.put("utilizedCappedProcUnits", metrics.systemUtil.sample.lparsUtil.processor.utilizedCappedProcUnits);
fieldsMap.put("utilizedUncappedProcUnits", metrics.systemUtil.sample.lparsUtil.processor.utilizedUncappedProcUnits);
fieldsMap.put("timePerInstructionExecution", metrics.systemUtil.sample.lparsUtil.processor.timeSpentWaitingForDispatch);
fieldsMap.put("timeSpentWaitingForDispatch", metrics.systemUtil.sample.lparsUtil.processor.timePerInstructionExecution);
log.debug("getProcessorMetrics() - fields: " + fieldsMap.toString());
Measurement measurement = new Measurement(tagsMap, fieldsMap);
@ -154,26 +121,20 @@ class LogicalPartition extends MetaSystem {
List<Measurement> list = new ArrayList<>();
metrics.systemUtil.sample.lparsUtil.network.virtualEthernetAdapters.forEach( adapter -> {
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", system.name);
put("partition", name);
put("sea", adapter.sharedEthernetAdapterId);
put("viosId", adapter.viosId.toString());
put("vlanId", adapter.vlanId.toString());
put("vswitchId", adapter.vswitchId.toString());
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", system.name);
tagsMap.put("partition", name);
tagsMap.put("sea", adapter.sharedEthernetAdapterId);
tagsMap.put("viosId", adapter.viosId.toString());
tagsMap.put("vlanId", adapter.vlanId.toString());
tagsMap.put("vswitchId", adapter.vswitchId.toString());
log.debug("getVirtualEthernetAdapterMetrics() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("receivedPhysicalBytes", adapter.receivedPhysicalBytes);
put("sentPhysicalBytes", adapter.sentPhysicalBytes);
put("receivedBytes", adapter.receivedBytes);
put("sentBytes", adapter.sentBytes);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("receivedPhysicalBytes", adapter.receivedPhysicalBytes);
fieldsMap.put("sentPhysicalBytes", adapter.sentPhysicalBytes);
fieldsMap.put("receivedBytes", adapter.receivedBytes);
fieldsMap.put("sentBytes", adapter.sentBytes);
log.debug("getVirtualEthernetAdapterMetrics() - fields: " + fieldsMap.toString());
Measurement measurement = new Measurement(tagsMap, fieldsMap);
@ -190,29 +151,18 @@ class LogicalPartition extends MetaSystem {
List<Measurement> list = new ArrayList<>();
metrics.systemUtil.sample.lparsUtil.storage.virtualFiberChannelAdapters.forEach( adapter -> {
//Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", system.name);
put("partition", name);
put("viosId", adapter.viosId.toString());
put("wwpn", adapter.wwpn);
}
};
//map.put("tags", tagsMap)
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", system.name);
tagsMap.put("partition", name);
tagsMap.put("viosId", adapter.viosId.toString());
tagsMap.put("wwpn", adapter.wwpn);
log.debug("getVirtualFiberChannelAdaptersMetrics() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("transmittedBytes", adapter.transmittedBytes.get(0));
put("writeBytes", adapter.writeBytes.get(0));
put("readBytes", adapter.readBytes.get(0));
}
};
//map.put("fields", fieldsMap)
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("transmittedBytes", adapter.transmittedBytes.get(0));
fieldsMap.put("writeBytes", adapter.writeBytes.get(0));
fieldsMap.put("readBytes", adapter.readBytes.get(0));
log.debug("getVirtualFiberChannelAdaptersMetrics() - fields: " + fieldsMap.toString());
Measurement measurement = new Measurement(tagsMap, fieldsMap);

View file

@ -54,23 +54,17 @@ class ManagedSystem extends MetaSystem {
List<Measurement> list = new ArrayList<>();
//Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", name);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", name);
//map.put("tags", tagsMap)
log.debug("getMemoryMetrics() - tags: " + tagsMap.toString());
Map<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("totalMem", metrics.systemUtil.sample.serverUtil.memory.totalMem);
put("availableMem", metrics.systemUtil.sample.serverUtil.memory.availableMem);
put("configurableMem", metrics.systemUtil.sample.serverUtil.memory.configurableMem);
put("assignedMemToLpars", metrics.systemUtil.sample.serverUtil.memory.assignedMemToLpars);
}
};
Map<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("totalMem", metrics.systemUtil.sample.serverUtil.memory.totalMem);
fieldsMap.put("availableMem", metrics.systemUtil.sample.serverUtil.memory.availableMem);
fieldsMap.put("configurableMem", metrics.systemUtil.sample.serverUtil.memory.configurableMem);
fieldsMap.put("assignedMemToLpars", metrics.systemUtil.sample.serverUtil.memory.assignedMemToLpars);
//map.put("fields", fieldsMap)
log.debug("getMemoryMetrics() - fields: " + fieldsMap.toString());
@ -87,24 +81,19 @@ class ManagedSystem extends MetaSystem {
List<Measurement> list = new ArrayList<>();
//Map<String, Map> map = new HashMap<>()
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", name);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", name);
//map.put("tags", tagsMap)
//measurement.tags = tagsMap;
log.debug("getProcessorMetrics() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("totalProcUnits", metrics.systemUtil.sample.serverUtil.processor.totalProcUnits);
put("utilizedProcUnits", metrics.systemUtil.sample.serverUtil.processor.utilizedProcUnits);
put("availableProcUnits", metrics.systemUtil.sample.serverUtil.processor.availableProcUnits);
put("configurableProcUnits", metrics.systemUtil.sample.serverUtil.processor.configurableProcUnits);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("totalProcUnits", metrics.systemUtil.sample.serverUtil.processor.totalProcUnits);
fieldsMap.put("utilizedProcUnits", metrics.systemUtil.sample.serverUtil.processor.utilizedProcUnits);
fieldsMap.put("availableProcUnits", metrics.systemUtil.sample.serverUtil.processor.availableProcUnits);
fieldsMap.put("configurableProcUnits", metrics.systemUtil.sample.serverUtil.processor.configurableProcUnits);
//map.put("fields", fieldsMap)
//measurement.fields = fieldsMap;
log.debug("getProcessorMetrics() - fields: " + fieldsMap.toString());
@ -122,22 +111,16 @@ class ManagedSystem extends MetaSystem {
metrics.systemUtil.sample.serverUtil.sharedProcessorPool.forEach(adapter -> {
//Map<String, Map> map = new HashMap<String, Map>()
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", name);
put("pool", adapter.name);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", name);
tagsMap.put("pool", adapter.name);
//map.put("tags", tagsMap)
log.debug("getSharedProcessorPools() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("assignedProcUnits", adapter.assignedProcUnits);
put("availableProcUnits", adapter.availableProcUnits);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("assignedProcUnits", adapter.assignedProcUnits);
fieldsMap.put("availableProcUnits", adapter.availableProcUnits);
//map.put("fields", fieldsMap)
log.debug("getSharedProcessorPools() - fields: " + fieldsMap.toString());
@ -159,25 +142,20 @@ class ManagedSystem extends MetaSystem {
//Map<String, Map> map = new HashMap<String, Map>()
Measurement measurement = new Measurement();
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("system", name);
put("type", adapter.type);
put("vios", vios.name);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("system", name);
tagsMap.put("type", adapter.type);
tagsMap.put("vios", vios.name);
//map.put("tags", tagsMap)
measurement.tags = tagsMap;
log.debug("getSystemSharedAdapters() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("sentBytes", adapter.sentBytes);
put("receivedBytes", adapter.receivedBytes);
put("transferredBytes", adapter.transferredBytes);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("sentBytes", adapter.sentBytes);
fieldsMap.put("receivedBytes", adapter.receivedBytes);
fieldsMap.put("transferredBytes", adapter.transferredBytes);
//map.put("fields", fieldsMap)
measurement.fields = fieldsMap;
log.debug("getSystemSharedAdapters() - fields: " + fieldsMap.toString());
@ -201,27 +179,22 @@ class ManagedSystem extends MetaSystem {
//HashMap<String, Map> map = new HashMap<>()
Measurement measurement = new Measurement();
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("id", adapter.id);
put("system", name);
put("wwpn", adapter.wwpn);
put("vios", vios.name);
put("device", adapter.physicalLocation);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("id", adapter.id);
tagsMap.put("system", name);
tagsMap.put("wwpn", adapter.wwpn);
tagsMap.put("vios", vios.name);
tagsMap.put("device", adapter.physicalLocation);
//map.put("tags", tagsMap)
measurement.tags = tagsMap;
log.debug("getSystemFiberChannelAdapters() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("writeBytes", adapter.writeBytes);
put("readBytes", adapter.readBytes);
put("transmittedBytes", adapter.transmittedBytes);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("writeBytes", adapter.writeBytes);
fieldsMap.put("readBytes", adapter.readBytes);
fieldsMap.put("transmittedBytes", adapter.transmittedBytes);
//map.put("fields", fieldsMap)
measurement.fields = fieldsMap;
log.debug("getSystemFiberChannelAdapters() - fields: " + fieldsMap.toString());
@ -245,25 +218,19 @@ class ManagedSystem extends MetaSystem {
Measurement measurement = new Measurement();
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("id", adapter.id);
put("system", name);
put("vios", vios.name);
put("device", adapter.physicalLocation);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("id", adapter.id);
tagsMap.put("system", name);
tagsMap.put("vios", vios.name);
tagsMap.put("device", adapter.physicalLocation);
measurement.tags = tagsMap;
log.debug("getSystemGenericPhysicalAdapters() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("writeBytes", adapter.writeBytes);
put("readBytes", adapter.readBytes);
put("transmittedBytes", adapter.transmittedBytes);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("writeBytes", adapter.writeBytes);
fieldsMap.put("readBytes", adapter.readBytes);
fieldsMap.put("transmittedBytes", adapter.transmittedBytes);
measurement.fields = fieldsMap;
log.debug("getSystemGenericPhysicalAdapters() - fields: " + fieldsMap.toString());
@ -287,25 +254,19 @@ class ManagedSystem extends MetaSystem {
Measurement measurement = new Measurement();
HashMap<String, String> tagsMap = new HashMap<String, String>() {
{
put("id", adapter.id);
put("system", name);
put("vios", vios.name);
put("device", adapter.physicalLocation);
}
};
HashMap<String, String> tagsMap = new HashMap<String, String>();
tagsMap.put("id", adapter.id);
tagsMap.put("system", name);
tagsMap.put("vios", vios.name);
tagsMap.put("device", adapter.physicalLocation);
measurement.tags = tagsMap;
log.debug("getSystemGenericVirtualAdapters() - tags: " + tagsMap.toString());
HashMap<String, Number> fieldsMap = new HashMap<String, Number>() {
{
put("writeBytes", adapter.writeBytes);
put("readBytes", adapter.readBytes);
put("transmittedBytes", adapter.transmittedBytes);
}
};
HashMap<String, Number> fieldsMap = new HashMap<String, Number>();
fieldsMap.put("writeBytes", adapter.writeBytes);
fieldsMap.put("readBytes", adapter.readBytes);
fieldsMap.put("transmittedBytes", adapter.transmittedBytes);
measurement.fields = fieldsMap;
log.debug("getSystemGenericVirtualAdapters() - fields: " + fieldsMap.toString());

View file

@ -95,7 +95,7 @@ abstract class MetaSystem {
@FromJson
Number fromJson(String string) {
return new Double(string);
return Double.parseDouble(string);
}
@ToJson