Merged tracefiles into development

This commit is contained in:
Mark Nellemann 2021-06-11 02:14:29 +02:00
commit 2166f1394b
4 changed files with 49 additions and 0 deletions

View file

@ -37,6 +37,7 @@ public class Application implements Callable<Integer> {
@Option(names = { "-d", "--debug" }, description = "Enable debugging [default: 'false'].") @Option(names = { "-d", "--debug" }, description = "Enable debugging [default: 'false'].")
private boolean[] enableDebug = new boolean[0]; private boolean[] enableDebug = new boolean[0];
public static void main(String... args) { public static void main(String... args) {
int exitCode = new CommandLine(new Application()).execute(args); int exitCode = new CommandLine(new Application()).execute(args);
System.exit(exitCode); System.exit(exitCode);

View file

@ -91,6 +91,12 @@ public final class Configuration {
c.unsafe = false; c.unsafe = false;
} }
if(hmcTable.contains(key+".trace")) {
c.trace = hmcTable.getString(key+".trace");
} else {
c.trace = null;
}
list.add(c); list.add(c);
} }
} }
@ -179,6 +185,7 @@ public final class Configuration {
String username; String username;
String password; String password;
Boolean unsafe = false; Boolean unsafe = false;
String trace;
Long update = 30L; Long update = 30L;
Long rescan = 60L; Long rescan = 60L;

View file

@ -19,6 +19,9 @@ import biz.nellemann.hmci.Configuration.HmcObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
@ -42,6 +45,8 @@ class HmcInstance implements Runnable {
private final InfluxClient influxClient; private final InfluxClient influxClient;
private final AtomicBoolean keepRunning = new AtomicBoolean(true); private final AtomicBoolean keepRunning = new AtomicBoolean(true);
private File traceDir;
private Boolean doTrace = false;
HmcInstance(HmcObject configHmc, InfluxClient influxClient) { HmcInstance(HmcObject configHmc, InfluxClient influxClient) {
this.hmcId = configHmc.name; this.hmcId = configHmc.name;
@ -50,6 +55,20 @@ class HmcInstance implements Runnable {
this.influxClient = influxClient; this.influxClient = influxClient;
hmcRestClient = new HmcRestClient(configHmc.url, configHmc.username, configHmc.password, configHmc.unsafe); hmcRestClient = new HmcRestClient(configHmc.url, configHmc.username, configHmc.password, configHmc.unsafe);
log.debug(String.format("HmcInstance() - id: %s, update: %s, refresh %s", hmcId, updateValue, rescanValue)); log.debug(String.format("HmcInstance() - id: %s, update: %s, refresh %s", hmcId, updateValue, rescanValue));
if(configHmc.trace != null) {
try {
traceDir = new File(configHmc.trace);
traceDir.mkdirs();
if(traceDir.canWrite()) {
doTrace = true;
} else {
log.warn("HmcInstance() - can't write to trace dir: " + traceDir.toString());
}
} catch (Exception e) {
log.error("HmcInstance() - trace error: " + e.getMessage());
}
}
} }
@ -171,7 +190,11 @@ class HmcInstance implements Runnable {
if(tmpJsonString != null && !tmpJsonString.isEmpty()) { if(tmpJsonString != null && !tmpJsonString.isEmpty()) {
system.processMetrics(tmpJsonString); system.processMetrics(tmpJsonString);
if(doTrace) {
writeTraceFile(systemId, tmpJsonString);
} }
}
}); });
@ -194,6 +217,9 @@ class HmcInstance implements Runnable {
} }
if(tmpJsonString2 != null && !tmpJsonString2.isEmpty()) { if(tmpJsonString2 != null && !tmpJsonString2.isEmpty()) {
partition.processMetrics(tmpJsonString2); partition.processMetrics(tmpJsonString2);
if(doTrace) {
writeTraceFile(partitionId, tmpJsonString2);
}
} }
}); });
@ -252,4 +278,18 @@ class HmcInstance implements Runnable {
} }
private void writeTraceFile(String id, String json) {
String fileName = String.format("%s-%s.json", id, Instant.now().toString());
try {
log.debug("Writing trace file: " + fileName);
File traceFile = new File(traceDir, fileName);
BufferedWriter writer = new BufferedWriter(new FileWriter(traceFile));
writer.write(json);
writer.close();
} catch (IOException e) {
log.warn("writeTraceFile() - " + e.getMessage());
}
}
} }

View file

@ -30,3 +30,4 @@ database = "hmci"
#username = "viewer" #username = "viewer"
#password = "someSecret" #password = "someSecret"
#unsafe = false #unsafe = false
#trace = "/tmp/pcm-files"