Java 类com.vmware.vim25.PerfMetricIntSeries 实例源码

项目:photon-model    文件:StatsClient.java   
/**
 * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.PerformanceManager.html#queryStats">queryStats method</a>
 * @param ctx
 * @return
 * @throws RuntimeFaultFaultMsg
 */
private List<ServiceStat> querySingleEntity(StatCollectionContext ctx)
        throws RuntimeFaultFaultMsg {
    List<PerfEntityMetricBase> metrics = getVimPort().queryPerf(PERF_MGR_MOREF,
            Collections.singletonList(ctx.getSpec()));

    List<ServiceStat> res = new ArrayList<>();

    if (metrics.isEmpty()) {
        // nothing fetched
        return Collections.emptyList();
    }

    // the metrics for the single entity
    PerfEntityMetric m = (PerfEntityMetric) metrics.get(0);

    for (PerfMetricSeries pms : m.getValue()) {
        PerfMetricId metricId = pms.getId();
        PerfMetricIntSeries series = (PerfMetricIntSeries) pms;
        SamplesAggregator factory = ctx.getFactory(metricId.getCounterId());

        PerfCounterInfo counter = this.perfCounterLookup
                .getCounterByKey(metricId.getCounterId());

        ServiceStat stat = factory.createStat(counter, m.getSampleInfo(), series.getValue());
        if (stat != null) {
            res.add(stat);
        }
    }

    return res;
}
项目:opennmszh    文件:VmwareViJavaAccess.java   
/**
 * This method queries performance values for a given managed entity.
 *
 * @param managedEntity the managed entity to query
 * @return the perfomance values
 * @throws RemoteException
 */
public VmwarePerformanceValues queryPerformanceValues(ManagedEntity managedEntity) throws RemoteException {

    VmwarePerformanceValues vmwarePerformanceValues = new VmwarePerformanceValues();

    int refreshRate = getPerformanceManager().queryPerfProviderSummary(managedEntity).getRefreshRate();

    PerfQuerySpec perfQuerySpec = new PerfQuerySpec();
    perfQuerySpec.setEntity(managedEntity.getMOR());
    perfQuerySpec.setMaxSample(Integer.valueOf(1));

    perfQuerySpec.setIntervalId(refreshRate);

    PerfEntityMetricBase[] perfEntityMetricBases = getPerformanceManager().queryPerf(new PerfQuerySpec[]{perfQuerySpec});

    if (perfEntityMetricBases != null) {
        for (int i = 0; i < perfEntityMetricBases.length; i++) {
            PerfMetricSeries[] perfMetricSeries = ((PerfEntityMetric) perfEntityMetricBases[i]).getValue();

            for (int j = 0; perfMetricSeries != null && j < perfMetricSeries.length; j++) {

                if (perfMetricSeries[j] instanceof PerfMetricIntSeries) {
                    long[] longs = ((PerfMetricIntSeries) perfMetricSeries[j]).getValue();

                    if (longs.length == 1) {

                        PerfCounterInfo perfCounterInfo = getPerfCounterInfoMap().get(perfMetricSeries[j].getId().getCounterId());
                        String instance = perfMetricSeries[j].getId().getInstance();
                        String name = getHumanReadableName(perfCounterInfo);

                        if (instance != null && !"".equals(instance)) {
                            vmwarePerformanceValues.addValue(name, instance, longs[0]);
                        } else {
                            vmwarePerformanceValues.addValue(name, longs[0]);
                        }
                    }
                }
            }
        }
    }

    return vmwarePerformanceValues;
}