More cleanup.

This commit is contained in:
Mark Nellemann 2020-10-15 15:23:16 +02:00
parent 3265f0721c
commit fe5a516cd3
6 changed files with 29 additions and 69 deletions

View file

@ -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;

View file

@ -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<String,ManagedSystem> 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<String, LogicalPartition> partitionMap = new HashMap<String, LogicalPartition>() {};
// 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

View file

@ -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,27 +190,16 @@ 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<Point> getPartitionAffinityScore(LogicalPartition partition, Instant timestamp) {

View file

@ -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());

View file

@ -242,7 +242,7 @@ class ManagedSystem extends MetaSystem {
metrics.systemUtil.sample.viosUtil.forEach( vios -> {
vios.storage.genericPhysicalAdapters.forEach( adapter -> {
//Map<String, Map> map = new HashMap<String, Map>()
Measurement measurement = new Measurement();
HashMap<String, String> tagsMap = new HashMap<String, String>() {
@ -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<String, Map> map = new HashMap<String, Map>()
Measurement measurement = new Measurement();
HashMap<String, String> tagsMap = new HashMap<String, String>() {
@ -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());

View file

@ -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"
}