use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class AtsSystemMonitor method init.
@Override
public void init(ReadingBean[] readings) throws Exception {
log.info("Initializing the ATS System Monitor");
try {
this.systemInfo = SystemInformationFactory.get();
} catch (Exception e) {
String errorMessage = "Error initializing the provider of system information. System monitoring will not work.";
log.error(errorMessage, e);
throw new SystemInformationException(errorMessage, e);
}
List<ReadingBean> staticReadings = new ArrayList<ReadingBean>();
List<ReadingBean> dynamicReadings = new ArrayList<ReadingBean>();
for (ReadingBean reading : readings) {
if (!reading.isDynamicReading()) {
staticReadings.add(reading);
} else {
// check if this process has a parent
String parentProcessName = reading.getParameter(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_PARENT_NAME);
if (parentProcessName != null) {
final String parentProcessId = parentProcessName + "-" + reading.getName();
if (!parentProcessReadingInstances.containsKey(parentProcessId)) {
ParentProcessReadingBean prentProcessBean = new ParentProcessReadingBean(reading.getId(), reading.getMonitorName(), parentProcessName, reading.getName(), reading.getUnit());
prentProcessBean.setParameters(reading.getParameters());
parentProcessReadingInstances.put(parentProcessId, prentProcessBean);
}
}
dynamicReadings.add(reading);
}
}
ReadingInstancesFactory.init(systemInfo, getPollInterval());
// create the actual static reading instances
staticReadingInstances = ReadingInstancesFactory.createStaticReadingInstances(systemInfo, staticReadings);
// remember the initial dynamic readings
initialDynamicReadings = new ArrayList<ReadingBean>(dynamicReadings);
// calculations on the first poll
if (initialDynamicReadings.size() > 0) {
dynamicReadingInstances = ReadingInstancesFactory.createOrUpdateDynamicReadingInstances(systemInfo, parentProcessReadingInstances, initialDynamicReadings, dynamicReadingInstances);
}
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class RestSystemMonitor method scheduleSystemMonitoring.
public Set<ReadingBean> scheduleSystemMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "systemReadingTypes", type = ValidationType.NOT_NULL) String[] systemReadingTypes) {
// validate input parameters
monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
new Validator().validateMethodParameters("Could not schedule monitoring system statistics on '" + monitoredHost + "'", new Object[] { monitoredHost, systemReadingTypes });
Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
try {
log.debug("Scheduling system monitoring...");
readingTypes.addAll(systemMonitor.scheduleSystemMonitoring(systemReadingTypes));
logSystemStatistics = true;
log.info("System monitoring scheduled.");
} catch (Exception e) {
log.error("Could not schedule system monitoring.", e);
throw new MonitoringException("Could not schedule system monitoring. Did you initialize the monitoring context?", e);
}
return readingTypes;
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class RestSystemMonitor method scheduleJvmMonitoring.
public Set<ReadingBean> scheduleJvmMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "jvmPort", type = ValidationType.NUMBER_PORT_NUMBER) String jvmPort, @Validate(name = "alias", type = ValidationType.NOT_NULL) String alias, @Validate(name = "jvmReadingTypes", type = ValidationType.NOT_NULL) String[] jvmReadingTypes) {
// validate input parameters
monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
new Validator().validateMethodParameters("Could not schedule monitoring JVM statistics on '" + monitoredHost + "' at " + jvmPort + " port", new Object[] { monitoredHost, jvmPort, jvmReadingTypes });
Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
Map<String, String> readingParameters = new HashMap<String, String>();
readingParameters.put("JMX_PORT", jvmPort);
if (!StringUtils.isNullOrEmpty(alias)) {
readingParameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS, alias);
}
for (String readingType : jvmReadingTypes) {
ReadingBean reading = null;
try {
log.debug("Scheduling JVM monitoring...");
reading = systemMonitor.scheduleJvmMonitoring(readingType, readingParameters);
logSystemStatistics = true;
log.info("JVM monitoring scheduled.");
} catch (Exception e) {
log.error("Could not schedule JVM monitoring.", e);
throw new MonitoringException("Could not schedule JVM monitoring. Did you initialize the monitoring context?", e);
}
readingTypes.add(reading);
}
return readingTypes;
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class RestSystemMonitor method setScheduledReadingTypes.
public void setScheduledReadingTypes(Set<ReadingBean> readingTypes) {
if (this.readingTypes == null) {
this.readingTypes = new HashSet<>();
}
// see which readings are already scheduled and log a warning
// add those that are new
Iterator<ReadingBean> scheduledReadingsIretator = this.readingTypes.iterator();
Iterator<ReadingBean> newReadingsIretator = readingTypes.iterator();
while (newReadingsIretator.hasNext()) {
ReadingBean newReadingBean = newReadingsIretator.next();
while (scheduledReadingsIretator.hasNext()) {
ReadingBean scheduledReadingBean = scheduledReadingsIretator.next();
if (newReadingBean.equals(scheduledReadingBean)) {
log.warn("The requested reading '" + newReadingBean.toString() + "' has already being scheduled.");
}
}
// reset iterator by making the object again
scheduledReadingsIretator = this.readingTypes.iterator();
}
/*
* since this is a set, already presented readings, will be replaced, so
* we add only the new ones
*/
this.readingTypes.addAll(readingTypes);
}
use of com.axway.ats.common.performance.monitor.beans.ReadingBean in project ats-framework by Axway.
the class RestSystemMonitor method scheduleCustomJvmMonitoring.
public Set<ReadingBean> scheduleCustomJvmMonitoring(@Validate(name = "monitoredHost", type = ValidationType.STRING_SERVER_WITH_PORT) String monitoredHost, @Validate(name = "jmxPort", type = ValidationType.NUMBER_PORT_NUMBER) String jmxPort, @Validate(name = "alias", type = ValidationType.NOT_NULL) String alias, @Validate(name = "mbeanName", type = ValidationType.NOT_NULL) String mbeanName, @Validate(name = "unit", type = ValidationType.NOT_NULL) String unit, @Validate(name = "mbeanAttributes", type = ValidationType.NOT_NULL) String... mbeanAttributes) {
// validate input parameters
monitoredHost = HostUtils.getAtsAgentIpAndPort(monitoredHost);
Set<ReadingBean> readingTypes = new HashSet<ReadingBean>();
Map<String, String> readingParameters = new LinkedHashMap<String, String>();
readingParameters.put("JMX_PORT", jmxPort);
readingParameters.put("MBEAN_NAME", mbeanName);
if (!StringUtils.isNullOrEmpty(alias)) {
readingParameters.put(SystemMonitorDefinitions.PARAMETER_NAME__PROCESS_ALIAS, alias);
}
// already existing map
if (mbeanAttributes.length > 1) {
for (String att : mbeanAttributes) {
readingParameters.put(att, "");
}
}
// the first element in the array is always the mbean name
ReadingBean reading = new ReadingBean(ATS_JVM_MONITOR_CLASS_FULL_NAME, mbeanAttributes[0], unit);
try {
log.debug("Scheduling custom JVM monitoring...");
int newReadingId = systemMonitor.scheduleCustomJvmMonitoring();
reading.setDbId(newReadingId);
logSystemStatistics = true;
log.info("Custom JVM monitoring scheduled.");
} catch (Exception e) {
log.error("Could not schedule custom JVM monitoring.", e);
throw new MonitoringException("Could not schedule custom JVM monitoring. Did you initialize the monitoring context?", e);
}
reading.setParameters(readingParameters);
readingTypes.add(reading);
return readingTypes;
}
Aggregations