-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add time series display to overview.
- Loading branch information
Showing
11 changed files
with
564 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 10 additions & 9 deletions
19
...s.vmoperator.vmconlet/resources/org/jdrupes/vmoperator/vmconlet/VmConlet-preview.ftl.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
<div class="jdrupes-vmoperator-vmconlet jdrupes-vmoperator-vmconlet-preview" | ||
data-conlet-grid-rows="5" | ||
data-jgwc-on-load="orgJDrupesVmOperatorVmConlet.initPreview" | ||
data-jgwc-on-unload="JGConsole.jgwc.unmountVueApps"> | ||
data-jgwc-on-unload="JGConsole.jgwc.unmountVueApps"> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<td>{{ localize("Total VMs") }}:</td> | ||
<td>{{ data.totalVms }}</td> | ||
</tr> | ||
<tr> | ||
<td>{{ localize("Running VMs") }}:</td> | ||
<td>{{ data.runningVms }}</td> | ||
<td>{{ localize("VMsSummary") }}:</td> | ||
<td>{{ vmSummary.runningVms }} / {{ vmSummary.totalVms }}</td> | ||
</tr> | ||
<tr> | ||
<td>{{ localize("Used CPUs") }}:</td> | ||
<td>{{ data.usedCpus }}</td> | ||
<td>{{ vmSummary.usedCpus }}</td> | ||
</tr> | ||
<tr> | ||
<td>{{ localize("Used RAM") }}:</td> | ||
<td>{{ formatMemory(data.usedRam) }}</td> | ||
<td>{{ formatMemory(BigInt(vmSummary.usedRam)) }}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div class="vmsChart-wrapper"> | ||
<canvas class="vmsChart"></canvas> | ||
</div> | ||
|
||
</div> |
2 changes: 2 additions & 0 deletions
2
org.jdrupes.vmoperator.vmconlet/resources/org/jdrupes/vmoperator/vmconlet/l10n.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
org.jdrupes.vmoperator.vmconlet/resources/org/jdrupes/vmoperator/vmconlet/l10n_de.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
org.jdrupes.vmoperator.vmconlet/src/org/jdrupes/vmoperator/vmconlet/TimeSeries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* VM-Operator | ||
* Copyright (C) 2023 Michael N. Lipp | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jdrupes.vmoperator.vmconlet; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* The Class TimeSeries. | ||
*/ | ||
@SuppressWarnings("PMD.DataflowAnomalyAnalysis") | ||
public class TimeSeries { | ||
|
||
private final List<Entry> data = new LinkedList<>(); | ||
private final Duration period; | ||
|
||
/** | ||
* Instantiates a new time series. | ||
* | ||
* @param series the number of series | ||
*/ | ||
public TimeSeries(Duration period) { | ||
this.period = period; | ||
} | ||
|
||
/** | ||
* Adds data to the series. | ||
* | ||
* @param time the time | ||
* @param numbers the numbers | ||
* @return the time series | ||
*/ | ||
@SuppressWarnings("PMD.AvoidLiteralsInIfCondition") | ||
public TimeSeries add(Instant time, Number... numbers) { | ||
var newEntry = new Entry(time, numbers); | ||
boolean adjust = false; | ||
if (data.size() >= 2) { | ||
var lastEntry = data.get(data.size() - 1); | ||
var lastButOneEntry = data.get(data.size() - 2); | ||
adjust = lastEntry.valuesEqual(lastButOneEntry) | ||
&& lastEntry.valuesEqual(newEntry); | ||
} | ||
if (adjust) { | ||
data.get(data.size() - 1).adjustTime(time); | ||
} else { | ||
data.add(new Entry(time, numbers)); | ||
} | ||
|
||
// Purge | ||
Instant limit = time.minus(period); | ||
while (data.size() > 2 | ||
&& data.get(0).getTime().isBefore(limit) | ||
&& data.get(1).getTime().isBefore(limit)) { | ||
data.remove(0); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns the entries. | ||
* | ||
* @return the list | ||
*/ | ||
public List<Entry> entries() { | ||
return data; | ||
} | ||
|
||
/** | ||
* The Class Entry. | ||
*/ | ||
public static class Entry { | ||
private Instant timestamp; | ||
private final Number[] values; | ||
|
||
/** | ||
* Instantiates a new entry. | ||
* | ||
* @param time the time | ||
* @param numbers the numbers | ||
*/ | ||
@SuppressWarnings("PMD.ArrayIsStoredDirectly") | ||
public Entry(Instant time, Number... numbers) { | ||
timestamp = time; | ||
values = numbers; | ||
} | ||
|
||
/** | ||
* Changes the entry's time. | ||
* | ||
* @param time the time | ||
*/ | ||
public void adjustTime(Instant time) { | ||
timestamp = time; | ||
} | ||
|
||
/** | ||
* Returns the entry's time. | ||
* | ||
* @return the instant | ||
*/ | ||
public Instant getTime() { | ||
return timestamp; | ||
} | ||
|
||
/** | ||
* Returns the values. | ||
* | ||
* @return the number[] | ||
*/ | ||
@SuppressWarnings("PMD.MethodReturnsInternalArray") | ||
public Number[] getValues() { | ||
return values; | ||
} | ||
|
||
/** | ||
* Returns `true` if both entries have the same values. | ||
* | ||
* @param other the other | ||
* @return true, if successful | ||
*/ | ||
public boolean valuesEqual(Entry other) { | ||
return Arrays.equals(values, other.values); | ||
} | ||
} | ||
} |
Oops, something went wrong.