Skip to content

Commit

Permalink
instances statuses table in report
Browse files Browse the repository at this point in the history
  • Loading branch information
matjaz99 committed Feb 10, 2024
1 parent ced60e5 commit 21119be
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Working on timeline
* [CHANGE] Removed separate alert.log (introduced in 2.3.0)
* [ENHANCEMENT] Status of instances in report view

## 2.4.5-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ public int getNumberOfAlertsInLastHour() {
MongoCollection<Document> collection = db.getCollection("journal");

Bson filter = Filters.gte("timestamp", System.currentTimeMillis() - 3600 * 1000);
// TODO filter by provider?

DAO.getInstance().removeWarningFromAllProviders("mongo");
AmMetrics.alertmonitor_db_queries_total.labels("journal").inc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ public boolean synchronizeAlerts(List<DEvent> alertList, boolean sync) {
for (DEvent e : alertList) {
if (activeAlerts.containsKey(e.getCorrelationId())) {
logger.debug("SYNC[" + providerConfig.getName() + "]: alert exists: {uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertname=" + e.getAlertname() + ", instance=" + e.getInstance() + "}");
// activeAlerts.get(e.getCorrelationId()).setToBeDeleted(false);
// activeAlerts.get(e.getCorrelationId()).setLastTimestamp(e.getTimestamp());
e.setToBeDeleted(false);
// e.setFirstTimestamp(activeAlerts.get(e.getCorrelationId()).getFirstTimestamp());
// activeAlerts.put(e.getCorrelationId(), e);
updateActiveAlert(e);
} else {
logger.info("SYNC[" + providerConfig.getName() + "]: new alert: {uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertname=" + e.getAlertname() + ", instance=" + e.getInstance() + "}");
Expand All @@ -170,8 +166,9 @@ public boolean synchronizeAlerts(List<DEvent> alertList, boolean sync) {

// remove active alerts which were not received (toBeDeleted=true)
for (String cid : cidToDelete) {
logger.info("SYNC[" + providerConfig.getName() + "]: removing active alert: {cid=" + cid + "}");
removeActiveAlert(activeAlerts.get(cid));
DEvent de = activeAlerts.get(cid);
logger.info("SYNC[" + providerConfig.getName() + "]: removing active alert: {uid=" + de.getUid() + ", cid=" + de.getCorrelationId() + ", alertname=" + de.getAlertname() + ", instance=" + de.getInstance() + "}");
removeActiveAlert(de);
}
addToJournal(newAlertsList);

Expand All @@ -193,16 +190,15 @@ public boolean synchronizeAlerts(List<DEvent> alertList, boolean sync) {
if (activeAlerts.containsKey(e.getCorrelationId())) {
if (e.getSeverity().equalsIgnoreCase(DSeverity.CLEAR)) {
removeActiveAlert(activeAlerts.get(e.getCorrelationId()));
logger.info("SYNC[" + providerConfig.getName() + "]: clear alert: uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertName: " + e.getAlertname());
logger.info("SYNC[" + providerConfig.getName() + "]: clear alert: {uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertname=" + e.getAlertname() + ", instance=" + e.getInstance() + "}");
} else {
updateActiveAlert(e);
logger.info("SYNC[" + providerConfig.getName() + "]: updating alert: uid=" + e.getUid() + ", counter=" + e.getCounter() + ", cid=" + e.getCorrelationId() + ", alertName: " + e.getAlertname());
logger.info("SYNC[" + providerConfig.getName() + "]: updating alert: {uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertname=" + e.getAlertname() + ", instance=" + e.getInstance() + ", counter=" + e.getCounter() + "}");
}
} else {
if (!e.getSeverity().equalsIgnoreCase(DSeverity.CLEAR)) {
// e.setFirstTimestamp(e.getTimestamp());
addActiveAlert(e);
logger.info("SYNC[" + providerConfig.getName() + "]: new alert: uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertName: " + e.getAlertname());
logger.info("SYNC[" + providerConfig.getName() + "]: new alert: {uid=" + e.getUid() + ", cid=" + e.getCorrelationId() + ", alertname=" + e.getAlertname() + ", instance=" + e.getInstance() + "}");
}
}

Expand Down Expand Up @@ -317,12 +313,11 @@ private void removeObsoleteTags() {
}

public double calculateAlertsBalanceFactor() {
if (activeAlerts.size() == 0) return 0;
double d = (5 * getActiveAlarmsList("critical").size()
if (activeAlerts.isEmpty()) return 0;
return (5 * getActiveAlarmsList("critical").size()
+ 4 * getActiveAlarmsList("major").size()
+ 3 * getActiveAlarmsList("minor").size()
+ 2 * getActiveAlarmsList("warning").size()) * 1.0 / activeAlerts.size();
return d;
}

/**
Expand All @@ -346,10 +341,12 @@ public List<DEvent> getActiveAlarmsList(String severity) {

}

public List<DEvent> getNumberOfAlertsInLastHour() {
// DAO.getInstance().getDataManager().addToJournal(events);
// TODO
return null;
/**
* Used from report.xhtml
* @return number of alerts in last hour
*/
public int getNumberOfAlertsInLastHour() {
return DAO.getInstance().getDataManager().getNumberOfAlertsInLastHour();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ public static void loadProps() {

// set development environment, override default configuration
if (DEV_ENV) {
ALERTMONITOR_PROMETHEUS_SERVER = "https://elasticvm/prometheus";
//ALERTMONITOR_PROMETHEUS_SERVER = "https://elasticvm/prometheus";
ALERTMONITOR_PROMETHEUS_SERVER = "https://ubuntu-vm/prometheus";
ALERTMONITOR_MONGODB_ENABLED = true;
ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@lionvm:27017/?authSource=admin";
//ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@elasticvm:27017/?authSource=admin";
ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@ubuntu-vm:27017/?authSource=admin";
ALERTMONITOR_MONGODB_DB_NAME = "alertmonitor-dev";
// ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE = "providers.yml";
ALERTMONITOR_DATAPROVIDERS_CONFIG_FILE = "/Users/matjaz/Library/CloudStorage/Dropbox/monis/config/alertmonitor-providers.yml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import com.google.gson.Gson;
import si.matjazcerkvenik.alertmonitor.model.DEvent;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Calendar;

Expand Down Expand Up @@ -93,6 +95,12 @@ public static String convertScientificNotationToString(String scientificNumber)
return String.format("%.0f", Double.parseDouble(scientificNumber));
}

public static Double roundDouble(Double value, int decimalPlaces) {
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(decimalPlaces, RoundingMode.HALF_UP);
return bd.doubleValue();
}

/**
* Remove leading protocol (eg. http://) and trailing port (eg. :8080).
* @param instance
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package si.matjazcerkvenik.alertmonitor.web.uibeans;

public class InstanceStatuses {

private String instance;
private String job;
private String scrapeInterval;
private String status;
private String downTime;
private String availability;
private String MTBF;

public String getInstance() {
return instance;
}

public void setInstance(String instance) {
this.instance = instance;
}

public String getJob() {
return job;
}

public void setJob(String job) {
this.job = job;
}

public String getScrapeInterval() {
return scrapeInterval;
}

public void setScrapeInterval(String scrapeInterval) {
this.scrapeInterval = scrapeInterval;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
if (status.equalsIgnoreCase("0")) this.status = "DOWN";
if (status.equalsIgnoreCase("1")) this.status = "UP";
}

/**
* Return red if DOWN and green if UP.
* @return color
*/
public String getStatusColor() {
if (status == null) return "black";
if (status.equals("UP")) return "green";
return "red";
}

public String getDownTime() {
return downTime;
}

public void setDownTime(String downTime) {
this.downTime = downTime;
}

public String getAvailability() {
return availability;
}

public void setAvailability(String availability) {
this.availability = availability;
}

public String getMTBF() {
return MTBF;
}

public void setMTBF(String MTBF) {
this.MTBF = MTBF;
}
}
Loading

0 comments on commit 21119be

Please sign in to comment.