Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
matjaz99 committed Aug 16, 2023
1 parent a10bffd commit ced60e5
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 2.4.6-SNAPSHOT

Working on timeline
* [CHANGE] Removed separate alert.log (introduced in 2.3.0)

## 2.4.5-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public List<DEvent> getJournal() {
.sort(Sorts.descending("timestamp"))
.limit(5000)
.into(new ArrayList<>());
// TODO add provider as filter

logger.info("MongoDbDataManager: docsResultList size=" + docsResultList.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/
package si.matjazcerkvenik.alertmonitor.model;

public class DTag {
import java.io.Serializable;

public class DTag implements Serializable {

private static final long serialVersionUID = 111885037L;

private String name;
private String color;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/si/matjazcerkvenik/alertmonitor/model/DWarning.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2021 Matjaž Cerkvenik
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package si.matjazcerkvenik.alertmonitor.model;

public class DWarning {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ public void addActiveAlert(DEvent event) {

activeAlerts.put(event.getCorrelationId(), event);
raisingEventCount++;
LogFactory.getAlertLog().write(event.toString());

// parse tags from tags label
String[] array = event.getTags().split(",");
Expand Down Expand Up @@ -281,7 +280,6 @@ public void removeActiveAlert(DEvent activeAlert) {
addToJournal(list);

clearingEventCount++;
LogFactory.getAlertLog().write(activeAlert.toString());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void loadProps() {
if (DEV_ENV) {
ALERTMONITOR_PROMETHEUS_SERVER = "https://elasticvm/prometheus";
ALERTMONITOR_MONGODB_ENABLED = true;
ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@elasticvm:27017/?authSource=admin";
ALERTMONITOR_MONGODB_CONNECTION_STRING = "mongodb://admin:mongodbpassword@lionvm: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
30 changes: 15 additions & 15 deletions src/main/java/si/matjazcerkvenik/alertmonitor/util/LogFactory.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2021 Matjaž Cerkvenik
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package si.matjazcerkvenik.alertmonitor.util;

import si.matjazcerkvenik.simplelogger.SimpleLogger;
Expand All @@ -24,19 +39,4 @@ public static SimpleLogger getLogger() {
return logger;
}

public static SimpleLogger getAlertLog() {
if (alertLog == null) {
if (AmProps.DEV_ENV) {
// write file in local working directory
alertLog = new SimpleLogger("./alerts.log");
} else {
// in production environment (aka when running inside container)
alertLog = new SimpleLogger("/opt/alertmonitor/log/alerts.log");
}
alertLog.setVerbose(false);
}
return alertLog;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,49 @@ public TimelineModel<DEvent, String> getModel() {
// get journal alerts for this instance from db
List<DEvent> journalEvents = getInstanceJournalAlarms();

HashMap<String, List<DEvent>> tempMap = new HashMap<>();
// sort series of alerts into lists by correlation id (key)
Map<String, List<DEvent>> journalEventsMap = new HashMap<>();

for (DEvent e : journalEvents) {
if (e.getSeverity().equalsIgnoreCase("clear")) continue;
List<DEvent> list = tempMap.getOrDefault(e.getCorrelationId(), new ArrayList<>());
List<DEvent> list = journalEventsMap.getOrDefault(e.getCorrelationId(), new ArrayList<>());
System.out.println("== " + e.toString());
list.add(e);
tempMap.put(e.getCorrelationId(), list);
journalEventsMap.put(e.getCorrelationId(), list);
}

// filter journal alerts:
// remove clear alerts
// if alert was cleared, leave only the first one
// if alert was not cleared yet, take the last one in series
for (String key: journalEventsMap.keySet()) {
List<DEvent> tempList = journalEventsMap.get(key);

Map<Long, DEvent> tempEventsMapByFirstTimestamp = new HashMap<>();
for (DEvent te : tempList) {
if (te.getSeverity().equalsIgnoreCase("clear")
&& te.getClearTimestamp() != 0) continue;
if (tempEventsMapByFirstTimestamp.containsKey(te.getFirstTimestamp())) {
if (te.getCounter() > tempEventsMapByFirstTimestamp.get(te.getFirstTimestamp()).getCounter()) {
tempEventsMapByFirstTimestamp.put(te.getFirstTimestamp(), te);
}
} else {
tempEventsMapByFirstTimestamp.put(te.getFirstTimestamp(), te);
}
}

for (Iterator<DEvent> it = tempList.iterator(); it.hasNext();) {
DEvent e = it.next();
// ignore clears
if (e.getSeverity().equalsIgnoreCase("clear")) it.remove();
// ignore cleared alerts (all except the first one)
if (e.getClearTimestamp() != 0 && e.getCounter() > 1) it.remove();
// ignore uncleared alerts except the last one in series (for each runtime id)
for (Long l : tempEventsMapByFirstTimestamp.keySet()) {
if (!tempEventsMapByFirstTimestamp.get(l).getUid().equalsIgnoreCase(e.getUid())) {
it.remove();
}
}
}
}

// create timeline model
Expand All @@ -159,22 +195,14 @@ public TimelineModel<DEvent, String> getModel() {

long now = System.currentTimeMillis();

for (String s : tempMap.keySet()) {
for (String s : journalEventsMap.keySet()) {

TimelineGroup<String> group = new TimelineGroup<>(s, tempMap.get(s).get(0).getAlertname(), 1);
TimelineGroup<String> group = new TimelineGroup<>(s, journalEventsMap.get(s).get(0).getAlertname(), 1);
model.addGroup(group);

for (DEvent e : tempMap.get(s)) {
for (DEvent e : journalEventsMap.get(s)) {
LocalDateTime startEvent = Instant.ofEpochMilli(e.getFirstTimestamp()).atZone(ZoneId.systemDefault()).toLocalDateTime();
long endEventMillis = 0;
if (e.getClearTimestamp() == 0) {
endEventMillis = e.getTimestamp();
} else if (e.getFirstTimestamp() == e.getTimestamp()) {
endEventMillis = now;
} else {
endEventMillis = e.getClearTimestamp();
}
LocalDateTime endEvent = Instant.ofEpochMilli(endEventMillis).atZone(ZoneId.systemDefault()).toLocalDateTime();
LocalDateTime endEvent = Instant.ofEpochMilli(e.getTimestamp()).atZone(ZoneId.systemDefault()).toLocalDateTime();


TimelineEvent event = TimelineEvent.<DEvent>builder()
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<location>/error</location>
</error-page>

<!-- Session timeout in minutes -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>

<!-- Define the JSF servlet (manages the request processing life cycle for JavaServer Faces) -->
<servlet>
<servlet-name>faces-servlet</servlet-name>
Expand Down
74 changes: 37 additions & 37 deletions src/main/webapp/targets/instance.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,53 @@
</p:panelGrid>

<h:form>
<p:accordionPanel dynamic="true" cache="true">
<p:tab title="Active alerts (#{uiInstanceBean.instanceActiveAlarms.size()})">
<p:dataTable id="tAlertsTable" widgetVar="notifsTable"
value="#{uiInstanceBean.instanceActiveAlarms}" var="a"
rowStyleClass="#{a.severity}"
cellpadding="0" cellspacing="0" width="100%">

<p:column headerText="Time" sortBy="#{a.timestamp}">
<h:outputText value="#{a.formatedTimestamp}" />
</p:column>
<p:outputLabel value="Showing (#{uiInstanceBean.instanceActiveAlarms.size()}) active alerts"/>

<p:column headerText="Alert name" sortBy="#{a.alertname}">
<h:link value = "#{a.alertname}" outcome = "/alert/alert">
<f:param name="uid" value="#{a.uid}" />
</h:link>
</p:column>
<p:panelGrid columns="1" cellspacing="5" width="100%" styleClass="ui-noborder">

<p:column headerText="Info" sortBy="#{a.info}">
<h:outputText value="#{a.info}" />
</p:column>
<p:dataTable id="tAlertsTable" widgetVar="notifsTable"
value="#{uiInstanceBean.instanceActiveAlarms}" var="a"
rowStyleClass="#{a.severity}"
cellpadding="0" cellspacing="0" width="100%">

<p:column headerText="Severity" sortBy="#{a.severity}">
<h:outputText value="#{a.severity}" />
</p:column>
<p:column headerText="Time">
<h:outputText value="#{a.formatedTimestamp}" />
</p:column>

<p:column headerText="Priority" sortBy="#{a.priority}">
<h:outputText value="#{a.priority}" />
</p:column>
<p:column headerText="Alert name">
<h:link value = "#{a.alertname}" outcome = "/alert/alert">
<f:param name="uid" value="#{a.uid}" />
</h:link>
</p:column>

<p:column headerText="Counter" sortBy="#{a.counter}">
<h:outputText value="#{a.counter}" />
</p:column>
<p:column headerText="Info">
<h:outputText value="#{a.info}" />
</p:column>

<p:column headerText="Value" sortBy="#{a.currentValue}">
<h:outputText value="#{a.currentValue}" />
</p:column>
<p:column headerText="Severity">
<h:outputText value="#{a.severity}" />
</p:column>

<p:column headerText="Job" sortBy="#{a.job}" >
<h:outputText value="#{a.job}" />
</p:column>
<p:column headerText="Priority">
<h:outputText value="#{a.priority}" />
</p:column>

<p:column headerText="Description" sortBy="#{a.description}">
<h:outputText value="#{a.description}" />
</p:column>
<p:column headerText="Value">
<h:outputText value="#{a.currentValue}" />
</p:column>

<p:column headerText="Description">
<h:outputText value="#{a.description}" />
</p:column>

</p:dataTable>

</p:panelGrid>


<p:accordionPanel dynamic="true" cache="true">

</p:dataTable>
</p:tab>
<p:tab title="Journal">
<p:dataTable id="tJournalTable" widgetVar="journalTable"
value="#{uiInstanceBean.instanceJournalAlarms}" var="j"
Expand Down

0 comments on commit ced60e5

Please sign in to comment.