Add debug option.

Increase okhttp timeouts.
This commit is contained in:
Mark Nellemann 2021-01-25 19:14:26 +01:00
parent 272b2aa375
commit b93b560fd9
9 changed files with 44 additions and 26 deletions

View file

@ -25,7 +25,7 @@ dependencies {
implementation 'org.tomlj:tomlj:1.0.0'
implementation 'org.influxdb:influxdb-java:2.21'
implementation 'org.slf4j:slf4j-api:1.7.30'
runtimeOnly 'org.slf4j:slf4j-simple:1.7.30'
implementation 'org.slf4j:slf4j-simple:1.7.30'
testImplementation('org.spockframework:spock-core:2.0-M4-groovy-3.0')
testImplementation('com.squareup.okhttp3:mockwebserver:4.9.0')

14
doc/readme-service.md Normal file
View file

@ -0,0 +1,14 @@
# HMCi as a System Service
## Systemd
To install as a systemd service, copy the **hmci.service**
file into */etc/systemd/system/* and enable the service:
systemctl daemon-reload
systemctl enable hmci.service
systemctl restart hmci.service
To read log output from the service, use:
journalctl -f -u hmci.service

View file

@ -1,4 +0,0 @@
To setup as a systemd service, copy the hmci.service
file into /etc/systemd/system/ and enable the service:
systemctl enable hmci.service

View file

@ -1,3 +1,3 @@
id = hmci
group = biz.nellemann.hmci
version = 1.1.1
version = 1.1.2

View file

@ -15,11 +15,10 @@
*/
package biz.nellemann.hmci;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
import picocli.CommandLine.Option;
import picocli.CommandLine.Command;
import org.slf4j.impl.SimpleLogger;
import java.io.File;
import java.io.IOException;
@ -33,11 +32,14 @@ import java.util.concurrent.Callable;
versionProvider = biz.nellemann.hmci.VersionProvider.class)
public class Application implements Callable<Integer> {
private final static Logger log = LoggerFactory.getLogger(Application.class);
//private final static Logger log = LoggerFactory.getLogger(Application.class);
@Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/hmci.toml'].", defaultValue = "/etc/hmci.toml", paramLabel = "<file>")
private String configurationFile;
@Option(names = { "-d", "--debug" }, description = "Enable debugging [default: 'false'].")
private boolean enableDebug = false;
public static void main(String... args) {
int exitCode = new CommandLine(new Application()).execute(args);
System.exit(exitCode);
@ -57,6 +59,10 @@ public class Application implements Callable<Integer> {
return -1;
}
if(enableDebug) {
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
}
try {
configuration = new Configuration(configurationFile);
influxClient = new InfluxClient(configuration.getInflux());
@ -73,7 +79,7 @@ public class Application implements Callable<Integer> {
}
} catch (InterruptedException | RuntimeException e) {
log.error(e.getMessage());
System.err.println(e.getMessage());
return 1;
}

View file

@ -133,13 +133,13 @@ class HmcInstance implements Runnable {
});
} catch (Exception e) {
log.error("discover() - getLogicalPartitions", e);
log.warn("discover() - getLogicalPartitions", e);
}
});
} catch(Exception e) {
log.error("discover() - getManagedSystems: " + e.getMessage());
log.warn("discover() - getManagedSystems: " + e.getMessage());
}
}
@ -154,7 +154,7 @@ class HmcInstance implements Runnable {
try {
tmpJsonString = hmcRestClient.getPcmDataForManagedSystem(system);
} catch (Exception e) {
log.error("getMetricsForSystems()", e);
log.warn("getMetricsForSystems() " + e.getMessage());
}
if(tmpJsonString != null && !tmpJsonString.isEmpty()) {
@ -178,7 +178,7 @@ class HmcInstance implements Runnable {
try {
tmpJsonString2 = hmcRestClient.getPcmDataForLogicalPartition(partition);
} catch (Exception e) {
log.error("getMetricsForPartitions() - getPcmDataForLogicalPartition", e);
log.warn("getMetricsForPartitions() - getPcmDataForLogicalPartition " + e.getMessage());
}
if(tmpJsonString2 != null && !tmpJsonString2.isEmpty()) {
partition.processMetrics(tmpJsonString2);
@ -187,7 +187,7 @@ class HmcInstance implements Runnable {
});
} catch(Exception e) {
log.error("getMetricsForPartitions()", e);
log.warn("getMetricsForPartitions() " + e.getMessage());
}
}
@ -201,7 +201,7 @@ class HmcInstance implements Runnable {
try {
tmpJsonString = hmcRestClient.getPcmDataForEnergy(system.energy);
} catch (Exception e) {
log.error("getMetricsForEnergy()", e);
log.warn("getMetricsForEnergy() " + e.getMessage());
}
if(tmpJsonString != null && !tmpJsonString.isEmpty()) {
@ -217,7 +217,7 @@ class HmcInstance implements Runnable {
try {
systems.forEach((systemId, system) -> influxClient.writeManagedSystem(system));
} catch (NullPointerException npe) {
log.warn("writeMetricsForManagedSystems() - NPE: " + npe.toString(), npe);
log.warn("writeMetricsForManagedSystems() - NPE: " + npe.getMessage(), npe);
}
}
@ -226,7 +226,7 @@ class HmcInstance implements Runnable {
try {
partitions.forEach((partitionId, partition) -> influxClient.writeLogicalPartition(partition));
} catch (NullPointerException npe) {
log.warn("writeMetricsForLogicalPartitions() - NPE: " + npe.toString(), npe);
log.warn("writeMetricsForLogicalPartitions() - NPE: " + npe.getMessage(), npe);
}
}
@ -235,7 +235,7 @@ class HmcInstance implements Runnable {
try {
systems.forEach((systemId, system) -> influxClient.writeSystemEnergy(system.energy));
} catch (NullPointerException npe) {
log.warn("writeMetricsForSystemEnergy() - NPE: " + npe.toString(), npe);
log.warn("writeMetricsForSystemEnergy() - NPE: " + npe.getMessage(), npe);
}
}

View file

@ -48,9 +48,9 @@ public class HmcRestClient {
private final OkHttpClient client;
// OkHttpClient timeouts
private final static int CONNECT_TIMEOUT = 2;
private final static int WRITE_TIMEOUT = 3;
private final static int READ_TIMEOUT = 3;
private final static int CONNECT_TIMEOUT = 15;
private final static int WRITE_TIMEOUT = 15;
private final static int READ_TIMEOUT = 15;
private final String baseUrl;
private final String username;
@ -114,6 +114,9 @@ public class HmcRestClient {
} catch (MalformedURLException e) {
log.error("login() - URL Error: " + e.getMessage());
throw e;
} catch (Exception e) {
log.error("login() - Error", e);
throw e;
}
}

View file

@ -107,9 +107,8 @@ class InfluxClient {
try {
influxDB.writeWithRetry(batchPoints);
} catch(Exception e) {
log.error("writeBatchPoints() error - " + e.getMessage());
log.warn("writeBatchPoints() " + e.getMessage());
if(++errorCounter > 5) {
log.info("writeBatchPoints() forcing logout / login");
errorCounter = 0;
logoff();
login();

View file

@ -1,6 +1,6 @@
org.slf4j.simpleLogger.logFile=System.out
org.slf4j.simpleLogger.showDateTime=true
org.slf4j.simpleLogger.showDateTime=false
org.slf4j.simpleLogger.showShortLogName=true
org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS
org.slf4j.simpleLogger.levelInBrackets=true
#org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.defaultLogLevel=info