Search in sources :

Example 16 with Statistic

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;
}
Also used : Statistic(org.ovirt.engine.api.model.Statistic) VdsStatistics(org.ovirt.engine.core.common.businessentities.VdsStatistics)

Example 17 with Statistic

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());
        }
    }
}
Also used : Statistic(org.ovirt.engine.api.model.Statistic)

Example 18 with Statistic

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;
}
Also used : V3Values(org.ovirt.engine.api.v3.types.V3Values) Statistic(org.ovirt.engine.api.model.Statistic) V3Statistic(org.ovirt.engine.api.v3.types.V3Statistic) V3Values(org.ovirt.engine.api.v3.types.V3Values) Values(org.ovirt.engine.api.model.Values)

Example 19 with Statistic

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;
}
Also used : Statistic(org.ovirt.engine.api.model.Statistic) Values(org.ovirt.engine.api.model.Values)

Example 20 with 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);
}
Also used : Statistic(org.ovirt.engine.api.model.Statistic) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

Statistic (org.ovirt.engine.api.model.Statistic)27 Statistics (org.ovirt.engine.api.model.Statistics)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Values (org.ovirt.engine.api.model.Values)3 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 BigDecimal (java.math.BigDecimal)1 MathContext (java.math.MathContext)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Host (org.ovirt.engine.api.model.Host)1 Value (org.ovirt.engine.api.model.Value)1 Vm (org.ovirt.engine.api.model.Vm)1 V3Statistic (org.ovirt.engine.api.v3.types.V3Statistic)1 V3Values (org.ovirt.engine.api.v3.types.V3Values)1 VdsStatistics (org.ovirt.engine.core.common.businessentities.VdsStatistics)1 GlusterVolumeTaskStatusForHost (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeTaskStatusForHost)1 Guid (org.ovirt.engine.core.compat.Guid)1