diff --git a/src/main/java/biz/nellemann/hmci/Configuration.java b/src/main/java/biz/nellemann/hmci/Configuration.java index 967c026..acdb743 100644 --- a/src/main/java/biz/nellemann/hmci/Configuration.java +++ b/src/main/java/biz/nellemann/hmci/Configuration.java @@ -1,7 +1,5 @@ package biz.nellemann.hmci; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.tomlj.Toml; import org.tomlj.TomlParseResult; import org.tomlj.TomlTable; @@ -14,7 +12,7 @@ import java.util.List; public class Configuration { - private final static Logger log = LoggerFactory.getLogger(Configuration.class); + //private final static Logger log = LoggerFactory.getLogger(Configuration.class); final public Long refresh; final public Long rescan; @@ -160,7 +158,7 @@ public class Configuration { HmcObject() { } - HmcObject(String url, String username, String password, Boolean unsafe) { + HmcObject(String name, String url, String username, String password, Boolean unsafe) { this.url = url; this.username = username; this.password = password; diff --git a/src/main/java/biz/nellemann/hmci/HmcClient.java b/src/main/java/biz/nellemann/hmci/HmcClient.java index 8ed607d..ed4070a 100644 --- a/src/main/java/biz/nellemann/hmci/HmcClient.java +++ b/src/main/java/biz/nellemann/hmci/HmcClient.java @@ -29,7 +29,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.security.SecureRandom; -import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Map; @@ -156,7 +155,7 @@ class HmcClient { Map managedSystemsMap = new HashMap<>(); // Do not try to parse empty response - if(responseBody.isEmpty() || responseBody.length() <= 1) { + if(responseBody == null || responseBody.isEmpty() || responseBody.length() <= 1) { responseErrors++; return managedSystemsMap; } @@ -197,7 +196,7 @@ class HmcClient { Map partitionMap = new HashMap() {}; // Do not try to parse empty response - if(responseBody.isEmpty() || responseBody.length() <= 1) { + if(responseBody == null || responseBody.isEmpty() || responseBody.length() <= 1) { responseErrors++; return partitionMap; } @@ -238,7 +237,7 @@ class HmcClient { String jsonBody = null; // Do not try to parse empty response - if(responseBody.isEmpty() || responseBody.length() <= 1) { + if(responseBody == null || responseBody.isEmpty() || responseBody.length() <= 1) { responseErrors++; log.warn("getPcmDataForManagedSystem() - empty response"); return null; @@ -276,7 +275,7 @@ class HmcClient { String jsonBody = null; // Do not try to parse empty response - if(responseBody.isEmpty() || responseBody.length() <= 1) { + if(responseBody == null || responseBody.isEmpty() || responseBody.length() <= 1) { responseErrors++; log.warn("getPcmDataForLogicalPartition() - empty response"); return null; @@ -351,11 +350,11 @@ class HmcClient { final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + public void checkClientTrusted(X509Certificate[] chain, String authType) { } @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + public void checkServerTrusted(X509Certificate[] chain, String authType) { } @Override diff --git a/src/main/java/biz/nellemann/hmci/InfluxClient.java b/src/main/java/biz/nellemann/hmci/InfluxClient.java index a8d93bd..94b9eb6 100644 --- a/src/main/java/biz/nellemann/hmci/InfluxClient.java +++ b/src/main/java/biz/nellemann/hmci/InfluxClient.java @@ -63,8 +63,7 @@ class InfluxClient { createDatabase(); // Enable batch writes to get better performance. - //influxDB.enableBatch(BatchOptions.DEFAULTS); - BatchOptions options = BatchOptions.DEFAULTS.actions(100).flushDuration(500); + BatchOptions options = BatchOptions.DEFAULTS.actions(1000).flushDuration(5000).precision(TimeUnit.SECONDS); influxDB.enableBatch(options); batchPoints = BatchPoints.database(database).precision(TimeUnit.SECONDS).build(); @@ -121,33 +120,20 @@ class InfluxClient { return; } - getSystemMemory(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getSystemMemory(system, timestamp).forEach( it -> batchPoints.point(it) ); - getSystemProcessor(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getSystemProcessor(system, timestamp).forEach( it -> batchPoints.point(it) ); - getSystemSharedProcessorPools(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getSystemSharedProcessorPools(system, timestamp).forEach( it -> batchPoints.point(it) ); - getSystemSharedAdapters(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getSystemSharedAdapters(system, timestamp).forEach( it -> batchPoints.point(it) ); - getSystemFiberChannelAdapters(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getSystemFiberChannelAdapters(system, timestamp).forEach( it -> batchPoints.point(it) ); - getSystemGenericPhysicalAdapters(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getSystemGenericPhysicalAdapters(system, timestamp).forEach( it -> batchPoints.point(it) ); + + getSystemGenericVirtualAdapters(system, timestamp).forEach( it -> batchPoints.point(it) ); - getSystemGenericVirtualAdapters(system, timestamp).forEach( it -> { - batchPoints.point(it); - }); } @@ -204,29 +190,18 @@ class InfluxClient { return; } - getPartitionAffinityScore(partition, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getPartitionAffinityScore(partition, timestamp).forEach( it -> batchPoints.point(it)); - getPartitionMemory(partition, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getPartitionMemory(partition, timestamp).forEach( it -> batchPoints.point(it)); - getPartitionProcessor(partition, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getPartitionProcessor(partition, timestamp).forEach( it -> batchPoints.point(it)); - getPartitionVirtualEthernetAdapter(partition, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getPartitionVirtualEthernetAdapter(partition, timestamp).forEach( it -> batchPoints.point(it)); - getPartitionVirtualFiberChannelAdapter(partition, timestamp).forEach( it -> { - batchPoints.point(it); - }); + getPartitionVirtualFiberChannelAdapter(partition, timestamp).forEach( it -> batchPoints.point(it)); - //influxDB.write(batchPoints); } - + private static List getPartitionAffinityScore(LogicalPartition partition, Instant timestamp) { List metrics = partition.getAffinityScore(); return processMeasurementMap(metrics, timestamp, "PartitionAffinityScore"); diff --git a/src/main/java/biz/nellemann/hmci/Insights.java b/src/main/java/biz/nellemann/hmci/Insights.java index 5630519..624ec76 100644 --- a/src/main/java/biz/nellemann/hmci/Insights.java +++ b/src/main/java/biz/nellemann/hmci/Insights.java @@ -64,7 +64,7 @@ class Insights { hmcClients.forEach(( hmcId, hmcClient) -> { try { - hmcClient.logoff();; + hmcClient.logoff(); hmcClient.login(); hmcClient.getManagedSystems().forEach((systemId, system) -> { @@ -152,16 +152,12 @@ class Insights { void writeMetricsForManagedSystems() { - systems.forEach((systemId, system) -> { - influxClient.writeManagedSystem(system); - }); + systems.forEach((systemId, system) -> influxClient.writeManagedSystem(system)); } void writeMetricsForLogicalPartitions() { - partitions.forEach((partitionId, partition) -> { - influxClient.writeLogicalPartition(partition); - }); + partitions.forEach((partitionId, partition) -> influxClient.writeLogicalPartition(partition)); } @@ -197,6 +193,7 @@ class Insights { } executions++; + //noinspection BusyWait sleep(configuration.refresh * 1000); } while (keepRunning.get()); diff --git a/src/main/java/biz/nellemann/hmci/ManagedSystem.java b/src/main/java/biz/nellemann/hmci/ManagedSystem.java index 0a19ebc..afcb873 100644 --- a/src/main/java/biz/nellemann/hmci/ManagedSystem.java +++ b/src/main/java/biz/nellemann/hmci/ManagedSystem.java @@ -242,7 +242,7 @@ class ManagedSystem extends MetaSystem { metrics.systemUtil.sample.viosUtil.forEach( vios -> { vios.storage.genericPhysicalAdapters.forEach( adapter -> { - //Map map = new HashMap() + Measurement measurement = new Measurement(); HashMap tagsMap = new HashMap() { @@ -254,7 +254,6 @@ class ManagedSystem extends MetaSystem { } }; - //map.put("tags", tagsMap) measurement.tags = tagsMap; log.debug("getSystemGenericPhysicalAdapters() - tags: " + tagsMap.toString()); @@ -266,7 +265,6 @@ class ManagedSystem extends MetaSystem { } }; - //map.put("fields", fieldsMap) measurement.fields = fieldsMap; log.debug("getSystemGenericPhysicalAdapters() - fields: " + fieldsMap.toString()); @@ -287,7 +285,6 @@ class ManagedSystem extends MetaSystem { vios.storage.genericVirtualAdapters.forEach( adapter -> { - //Map map = new HashMap() Measurement measurement = new Measurement(); HashMap tagsMap = new HashMap() { @@ -299,7 +296,6 @@ class ManagedSystem extends MetaSystem { } }; - //map.put("tags", tagsMap) measurement.tags = tagsMap; log.debug("getSystemGenericVirtualAdapters() - tags: " + tagsMap.toString()); @@ -311,7 +307,6 @@ class ManagedSystem extends MetaSystem { } }; - //map.put("fields", fieldsMap) measurement.fields = fieldsMap; log.debug("getSystemGenericVirtualAdapters() - fields: " + fieldsMap.toString()); diff --git a/src/test/groovy/biz/nellemann/hmci/HmcClientTest.groovy b/src/test/groovy/biz/nellemann/hmci/HmcClientTest.groovy index 29eae94..2414dec 100644 --- a/src/test/groovy/biz/nellemann/hmci/HmcClientTest.groovy +++ b/src/test/groovy/biz/nellemann/hmci/HmcClientTest.groovy @@ -12,11 +12,7 @@ class HmcClientTest extends Specification { def setup() { mockServer.start() - Configuration.HmcObject configHmc = new Configuration.HmcObject() - configHmc.name = "site1" - configHmc.url = mockServer.url("/").toString() - configHmc.username = "testUser" - configHmc.password = "testPassword" + Configuration.HmcObject configHmc = new Configuration.HmcObject("site1", mockServer.url("/").toString(), "testUser", "testPassword", true); hmc = new HmcClient(configHmc) hmc.authToken = "blaBla" }