cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

This product reached the end of support date on March 31, 2021.

get thresholds from MonitorEnvironment

ian_mcgilloway
Participant

Hi,

I've developed a custom monitor. The monitor measures the response time of a third party service. The monitor has a timeout set as a configuration parameter and if the response time reaches this timeout, the monitor disconnects from the third party and sets the response time measure to be the timeout value. The upper severe threshold for the measure is set manually to be the same as the timeout. This all works as expected but whenever I need to change the upper threshold, I also need to change the timeout configuration parameter in the monitor.

What I would like to do is have the monitor read the upper severe threshold value and set that to be the timeout. Is this possible? I can get the MonitorMeasure from the MonitorEnvironment but can't see where I'd go from there.

Thanks,

Ian

3 REPLIES 3

rick_boyd
Mentor

Hi Ian,

The most straightforward path is to return (as 1 or 0) a "boolean" for timeout exceeded and base your alert on that. Let me know if you need me to elaborate or look at your code 🙂

Rick B

or a more generic failure one which might include things like 500 errors or connection refused. I like this because you can scale charts like this to x100 and use it as a pseudo availability monitor also

ian_mcgilloway
Participant

Hi, Thanks for the response. That's effectively what I'm doing @Rick B.. What I want is for the monitor get the threshold for the measure at run time and use that value as the timeout, and not have to set a timeout in config.

try {
InetAddress host = InetAddress.getByName(hostName);
Future<FTPConnectResult> task = (Future<FTPConnectResult>) executorService
.submit(() -> {
FTPConnectResult result = new FTPConnectResult();
long startTime = Calendar.getInstance()
.getTimeInMillis();
ftpClient.connect(host, port);
ftpClient.login(username, password);
ftpClient.sendCommand(
FTPCommand.CHANGE_WORKING_DIRECTORY,
directory);
LOGGER.info(ftpClient.getReplyString());;
ftpClient.logout();
long responseTime = Calendar.getInstance()
.getTimeInMillis() - startTime;
result.setResponseTime(responseTime);
result.setStatus(STATUS.OK);
return result;
});
// The result is effectively final
FTPConnectResult taskResult = task.get(timeout,
TimeUnit.MILLISECONDS);
ftpConnectResult.setResponseTime(taskResult.getResponseTime());
ftpConnectResult.setStatus(taskResult.getStatus());
} catch (InterruptedException | ExecutionException | TimeoutException | UnknownHostException e) {
ftpConnectResult.setResponseTime(timeout);
ftpConnectResult.setStatus(STATUS.ERROR);
LOGGER.info(e.getMessage());
} finally {
try {
ftpClient.disconnect();
} catch (IOException e) {
ftpConnectResult.setResponseTime(timeout);
ftpConnectResult.setStatus(STATUS.ERROR);
LOGGER.info(e.getMessage());
}
executorService.shutdown();
}
Collection<MonitorMeasure> responseMeasures = env
.getMonitorMeasures(METRIC_GROUP_RESPONSE_TIME,
METRIC_NAME_RESPONSE_TIME);
responseMeasures.forEach(measure -> {
measure.setValue(ftpConnectResult.getResponseTime());
});

Collection<MonitorMeasure> responseStatuses = env.getMonitorMeasures(
METRIC_GROUP_RESPONSE_STATUS, METRIC_NAME_RESPONSE_STATUS);
responseStatuses.forEach(measure -> {
measure.setValue(ftpConnectResult.getStatusValue());
});