Added count display in uptime view.

This commit is contained in:
Christian P. MOMON 2021-06-11 23:01:37 +02:00
parent 4f054e39dd
commit a5cfd2f8d5
5 changed files with 146 additions and 3 deletions

View file

@ -32,6 +32,7 @@ import fr.devinsy.statoolinfos.core.Services;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.statoolinfos.uptime.UptimeStat;
import fr.devinsy.statoolinfos.uptime.UptimeStatus;
import fr.devinsy.strings.StringList;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
@ -45,6 +46,66 @@ public class UptimeView
{
private static Logger logger = LoggerFactory.getLogger(UptimeView.class);
/**
* Gets the stat.
*
* @param services
* the services
* @param date
* the date
* @return the stat
*/
public static UptimeStat getStat(final UptimeJournal journal, final Services services, final LocalDate date)
{
UptimeStat result;
result = new UptimeStat();
if ((services != null) || (date != null))
{
for (Service service : services.sortByName())
{
UptimeStat stat = journal.getStat(service.getWebsiteURL(), date);
if (stat.getStatus() == UptimeStatus.OK)
{
result.incOk();
}
else if (stat.getStatus() == UptimeStatus.WARNING)
{
result.incWarning();
}
else if (stat.getStatus() == UptimeStatus.ALERT)
{
result.incAlert();
}
else if (stat.getStatus() == UptimeStatus.ERROR)
{
result.incError();
}
else if (stat.getStatus() == UptimeStatus.VOID)
{
result.incVoid();
}
}
if (result.getCount() == 0)
{
result.setStatus(UptimeStatus.VOID);
}
else if (result.getOkCount() != result.getCount())
{
result.setStatus(UptimeStatus.ERROR);
}
else
{
result.setStatus(UptimeStatus.OK);
}
}
//
return result;
}
/**
* Htmlize.
*
@ -65,6 +126,15 @@ public class UptimeView
TagDataManager data = new TagDataManager();
LocalDate now = LocalDate.now();
UptimeStat last = getStat(journal, services, now);
data.setContent("okCount", last.getOkCount());
data.setContent("warningCount", last.getWarningCount());
data.setContent("alertCount", last.getAlertCount());
data.setContent("errorCount", last.getErrorCount());
data.setContent("voidCount", last.getVoidCount());
for (int dayCount = 0; dayCount < 22; dayCount++)
{
LocalDate date = now.minusDays(dayCount);

View file

@ -847,6 +847,32 @@ table > tfoot > tr > th.danger
width: 50px;
}
/************************************************/
.uptimeCounts
{
text-align: center;
}
.uptimeCounts ul li
{
display: inline-block;
list-style-type:none;
padding: 0 5px 5px 5px;
}
.uptimeCounts img
{
height: 18px;
width: 11px;
vertical-align: bottom;
}
.uptimeCounts ul li span
{
padding-left : 5px;
padding-right : 5px;
width: 50px;
}
.uptimeTable
{
}

View file

@ -26,6 +26,15 @@
</div>
</div>
<div class="uptimeCounts">
<ul>
<li><img src="status-ok.png" title="" /><span id="okCount">n/a</span></li>
<li><img src="status-warning.png" title="" /><span id="warningCount">n/a</span></li>
<li><img src="status-alert.png" title="" /><span id="alertCount">n/a</span></li>
<li><img src="status-error.png" title="" /><span id="errorCount">n/a</span></li>
<li><img src="status-void.png" title="" /><span id="voidCount">n/a</span></li>
</ul>
</div>
<table class="center_table table_classic left uptimeTable">
<tr id="lineHeader">
<th id="lineName" style="padding-top: 0; padding-bottom: 0;">Service</th>

View file

@ -131,7 +131,7 @@ public class UptimeJournal
}
if (older != null)
{
result.setLastStatus(older.getStatus());
result.setStatus(older.getStatus());
}
}

View file

@ -30,7 +30,10 @@ public class UptimeStat
private int count;
private int okCount;
private int warningCount;
private int alertCount;
private int errorCount;
private int voidCount;
private UptimeStatus last;
/**
@ -39,11 +42,19 @@ public class UptimeStat
public UptimeStat()
{
this.count = 0;
this.warningCount = 0;
this.alertCount = 0;
this.okCount = 0;
this.errorCount = 0;
this.voidCount = 0;
this.last = null;
}
public int getAlertCount()
{
return this.alertCount;
}
public int getCount()
{
return this.count;
@ -96,6 +107,22 @@ public class UptimeStat
return result;
}
public int getVoidCount()
{
return this.voidCount;
}
public int getWarningCount()
{
return this.warningCount;
}
public void incAlert()
{
this.count += 1;
this.alertCount += 1;
}
public void incError()
{
this.count += 1;
@ -108,9 +135,20 @@ public class UptimeStat
this.okCount += 1;
}
public void setLastStatus(final UptimeStatus status)
public void incVoid()
{
this.count += 1;
this.voidCount += 1;
}
public void incWarning()
{
this.count += 1;
this.warningCount += 1;
}
public void setStatus(final UptimeStatus status)
{
this.last = status;
}
}