loop shutdown preparation

This commit is contained in:
Wolfgang Hottgenroth 2020-09-07 22:34:24 +02:00
parent 65791ae804
commit dd0b223348
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
4 changed files with 46 additions and 10 deletions

View File

@ -14,7 +14,8 @@ import org.apache.logging.log4j.Logger;
public class ConfigProperties extends Properties {
static final String DEFAULT_PROPS_FILENAME = "mbusMaster.props";
static final String PROPS_VERBOSE = "verbose";
static final String PRPOS_MAINCONFIGFILE = "mainConfigFile";
static final String PROPS_MAINCONFIGFILE = "mainConfigFile";
static final String PROPS_ERRORRATIOTHRESHOLD = "errorRatioThreshold";
static final Logger logger = LogManager.getRootLogger();
@ -23,7 +24,7 @@ public class ConfigProperties extends Properties {
public ConfigProperties() throws ConfigPropertiesException {
super();
String propsFilename = System.getProperty(PRPOS_MAINCONFIGFILE, DEFAULT_PROPS_FILENAME);
String propsFilename = System.getProperty(PROPS_MAINCONFIGFILE, DEFAULT_PROPS_FILENAME);
try {
try (FileInputStream propsFileInputStream = new FileInputStream(propsFilename)) {
load(propsFileInputStream);

View File

@ -57,11 +57,8 @@ abstract public class MbusDevice {
this.errorCnt++;
}
public void resetSuccessCnt() {
public void resetCounter() {
this.successCnt = 0;
}
public void resetErrorCnt() {
this.errorCnt = 0;
}

View File

@ -11,19 +11,22 @@ import org.apache.logging.log4j.Logger;
public class MbusScheduledQuerier extends Thread {
static final Logger logger = LogManager.getRootLogger();
static final double DEFAULT_ERRORRATIOTHRESHOLD = 0.5;
static final Logger logger = LogManager.getRootLogger();
private ArrayList<MbusDevice> devices;
private boolean stopSignal = false;
private ConfigProperties config;
private BlockingQueue<ADataObject> queue;
public MbusScheduledQuerier(ConfigProperties config, BlockingQueue<ADataObject> queue) {
super("MbusScheduledQuerier");
this.config = config;
this.queue = queue;
this.devices = new ArrayList<>();
this.devices.add(new FinderThreePhasePowerMeter("Total Electricity", (byte)80, 0));
this.devices.add(new FinderOnePhasePowerMeter("Dryer", (byte)81, 0));
@ -47,6 +50,11 @@ public class MbusScheduledQuerier extends Thread {
int cnt = 0;
int errCnt = 0;
int successCnt = 0;
int shutdownCnt = 0;
double maxErrorRatio = 0;
int timeSinceLastLoopShutdown = 0;
int meantimeBetweenLoopShutdowns = 0;
while (! this.stopSignal) {
cnt++;
@ -67,9 +75,32 @@ public class MbusScheduledQuerier extends Thread {
errCnt++;
logger.error("Error " + e.toString() + " in Meterbus dialog for device " + device.shortString());
}
this.maxErrorRatio = (this.maxErrorRatio > device.getErrorRatio()) ? this.maxErrorRatio : device.getErrorRatio();
}
if (this.maxErrorRatio > config.getDoubleProperties(ConfigProperties.PROPS_ERRORRATIOTHRESHOLD, DEFAULT_ERRORRATIOTHRESHOLD)) {
// disable loop
shutdownCnt++;
// reset counters in devices
for (MbusDevice device : this.devices) {
device.resetCounter();
}
// reset local counters
errCnt = 0;
successCnt = 0;
// remember time of loop shutdown
// calculate time since last shutdown
// calculate mean time between shutdowns
}
logger.info("CycleCnt: " + cnt + ", SuccessCnt: " + successCnt + ", ErrCnt: " + errCnt);
this.queue.add(new MbusStatisticsDataObject("MbusgwChild", errCnt, successCnt, ((double)errCnt / (double)(errCnt+successCnt))));
this.queue.add(new MbusStatisticsDataObject("MbusgwChild", errCnt, successCnt, shutdownCnt,
((double)errCnt / (double)(errCnt+successCnt))),
timeSinceLastLoopShutdown, meantimeBetweenLoopShutdowns);
try {
Thread.sleep(5*1000);
} catch (InterruptedException e) {

View File

@ -7,15 +7,22 @@ public class MbusStatisticsDataObject extends ADataObject {
static final String ERROR_CNT_KEY = "error";
static final String SUCCESS_CNT_KEY = "success";
static final String ERROR_RATIO_KEY = "errorRatio";
static final String TIME_SINCE_LAST_SHUTDOWN_KEY = "timeSinceLastShutdown";
static final String MEANTIME_BETWEEN_SHUTDOWNS_KEY = "meantimeBetweenShutdowns";
static final String SHUTDOWNS_KEY = "shutdowns";
static final String TABLE_NAME = "Statistics";
static final String KIND_NAME = "Statistics";
public MbusStatisticsDataObject(String name, int error, int success, double errorRatio) {
public MbusStatisticsDataObject(String name, int error, int success, int shutdowns,
double errorRatio, int timeSinceLastShutdown, int meantimeBetweenShutdowns) {
super(name, KIND_NAME);
HashMap<String, Object> values = new HashMap<String, Object>();
values.put(ERROR_CNT_KEY, error);
values.put(SUCCESS_CNT_KEY, success);
values.put(ERROR_RATIO_KEY, errorRatio);
values.put(TIME_SINCE_LAST_SHUTDOWN_KEY, timeSinceLastShutdown);
values.put(MEANTIME_BETWEEN_SHUTDOWNS_KEY, meantimeBetweenShutdowns);
values.put(SHUTDOWNS_KEY, shutdowns);
setValues(values);
}