use of org.ovirt.engine.api.model.Statistic in project ovirt-engine by oVirt.
the class HostStatisticalQuery method getStatistics.
public List<Statistic> getStatistics(VDS entity) {
VdsStatistics s = entity.getStatisticsData();
// if user queries host statistics before host installation completed, null values are possible (therefore added checks).
long memTotal = entity.getPhysicalMemMb() == null ? 0 : entity.getPhysicalMemMb() * Mb;
long memUsed = (s == null || s.getUsageMemPercent() == null) ? 0 : memTotal * s.getUsageMemPercent() / 100;
List<Statistic> statistics = asList(setDatum(clone(MEM_TOTAL), memTotal), setDatum(clone(MEM_USED), memUsed), setDatum(clone(MEM_FREE), memTotal - memUsed), setDatum(clone(MEM_SHARED), (s == null || s.getMemShared() == null) ? 0 : s.getMemShared() * Mb), setDatum(clone(MEM_BUFFERS), 0), setDatum(clone(MEM_CACHED), 0), setDatum(clone(SWAP_TOTAL), (s == null || s.getSwapTotal() == null) ? 0 : s.getSwapTotal() * Mb), setDatum(clone(SWAP_FREE), (s == null || s.getSwapFree() == null) ? 0 : s.getSwapFree() * Mb), setDatum(clone(SWAP_USED), getSwapUsed(s) * Mb), setDatum(clone(SWAP_CACHED), 0), setDatum(clone(CPU_KSM), (s == null || s.getKsmCpuPercent() == null) ? 0 : s.getKsmCpuPercent()), setDatum(clone(CPU_USER), (s == null || s.getCpuUser() == null) ? 0 : s.getCpuUser()), setDatum(clone(CPU_SYS), (s == null || s.getCpuSys() == null) ? 0 : s.getCpuSys()), setDatum(clone(CPU_IDLE), (s == null || s.getCpuIdle() == null) ? 0 : s.getCpuIdle()), setDatum(clone(CPU_LOAD), (s == null || s.getCpuLoad() == null) ? 0 : s.getCpuLoad() / 100), setDatum(clone(BOOT_TIME), (s == null || s.getBootTime() == null) ? 0 : s.getBootTime()));
if (s != null && s.getHugePages() != null) {
s.getHugePages().stream().filter(page -> page.getAmount() != null).map(this::createHugePagesFree).forEach(statistics::add);
}
return statistics;
}
use of org.ovirt.engine.api.model.Statistic in project ovirt-engine by oVirt.
the class AbstractBackendSubResourceTest method verifyStatistics.
protected void verifyStatistics(List<Statistic> statistics, String[] names, BigDecimal[] values) {
assertNotNull(statistics);
assertEquals(names.length, statistics.size());
for (Statistic statistic : statistics) {
assertTrue(statistic.isSetValues());
boolean found = false;
for (int i = 0; i < names.length; i++) {
if (names[i].equals(statistic.getName())) {
assertEquals("unexpected value for: " + names[i], values[i], getDatum(statistic));
found = true;
break;
}
}
if (!found) {
fail("unexpected statistic: " + statistic.getName());
}
}
}
use of org.ovirt.engine.api.model.Statistic in project ovirt-engine by oVirt.
the class V3StatisticInAdapter method adapt.
@Override
public Statistic adapt(V3Statistic from) {
Statistic to = new Statistic();
if (from.isSetLinks()) {
to.getLinks().addAll(adaptIn(from.getLinks()));
}
if (from.isSetActions()) {
to.setActions(adaptIn(from.getActions()));
}
if (from.isSetBrick()) {
to.setBrick(adaptIn(from.getBrick()));
}
if (from.isSetComment()) {
to.setComment(from.getComment());
}
if (from.isSetDescription()) {
to.setDescription(from.getDescription());
}
if (from.isSetDisk()) {
to.setDisk(adaptIn(from.getDisk()));
}
if (from.isSetGlusterVolume()) {
to.setGlusterVolume(adaptIn(from.getGlusterVolume()));
}
if (from.isSetHost()) {
to.setHost(adaptIn(from.getHost()));
}
if (from.isSetHostNic()) {
to.setHostNic(adaptIn(from.getHostNic()));
}
if (from.isSetHostNumaNode()) {
to.setHostNumaNode(adaptIn(from.getHostNumaNode()));
}
if (from.isSetId()) {
to.setId(from.getId());
}
if (from.isSetHref()) {
to.setHref(from.getHref());
}
if (from.getType() != null) {
switch(from.getType()) {
case COUNTER:
to.setKind(StatisticKind.COUNTER);
break;
case GAUGE:
to.setKind(StatisticKind.GAUGE);
break;
}
}
if (from.isSetName()) {
to.setName(from.getName());
}
if (from.isSetNic()) {
to.setNic(adaptIn(from.getNic()));
}
if (from.isSetStep()) {
to.setStep(adaptIn(from.getStep()));
}
if (from.isSetUnit()) {
switch(from.getUnit()) {
case NONE:
to.setUnit(StatisticUnit.NONE);
break;
case PERCENT:
to.setUnit(StatisticUnit.PERCENT);
break;
case BYTES:
to.setUnit(StatisticUnit.BYTES);
break;
case SECONDS:
to.setUnit(StatisticUnit.SECONDS);
break;
case BYTES_PER_SECOND:
to.setUnit(StatisticUnit.BYTES_PER_SECOND);
break;
case BITS_PER_SECOND:
to.setUnit(StatisticUnit.BITS_PER_SECOND);
break;
case COUNT_PER_SECOND:
to.setUnit(StatisticUnit.COUNT_PER_SECOND);
break;
}
}
if (from.isSetValues()) {
V3Values fromValues = from.getValues();
if (fromValues.isSetType()) {
switch(fromValues.getType()) {
case DECIMAL:
to.setType(ValueType.DECIMAL);
break;
case INTEGER:
to.setType(ValueType.INTEGER);
break;
case STRING:
to.setType(ValueType.STRING);
break;
}
}
to.setValues(new Values());
to.getValues().getValues().addAll(adaptIn(fromValues.getValues()));
}
if (from.isSetVm()) {
to.setVm(adaptIn(from.getVm()));
}
return to;
}
use of org.ovirt.engine.api.model.Statistic in project ovirt-engine by oVirt.
the class StatisticResourceUtils method create.
public static Statistic create(String name, String description, StatisticKind kind, StatisticUnit unit, ValueType valueType) {
Statistic statistic = new Statistic();
statistic.setId(asId(name));
statistic.setName(name);
statistic.setDescription(description);
statistic.setKind(kind);
statistic.setUnit(unit);
statistic.setValues(new Values());
statistic.setType(valueType);
return statistic;
}
use of org.ovirt.engine.api.model.Statistic in project ovirt-engine by oVirt.
the class BackendStatisticResource method get.
@Override
public Statistic get() {
try {
Q entity = query.resolve(subjectId);
List<Statistic> currentStats = query.getStatistics(entity);
for (Statistic statistic : currentStats) {
if (id.equals(statistic.getId())) {
return addLinks(statistic, query.getParentType());
}
}
} catch (BackendFailureException bfe) {
return handleError(bfe, false);
}
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
Aggregations