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

项目:photon-model    文件:StatsClient.java   
/**
 * Makes a PerfMetricId by looking up the counterId for the given group/name/rollupType/... params.
 *
 * https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.PerformanceManager.MetricId.html
 *
 * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/cpu_counters.html">cpu counters</a>
 * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/memory_counters.html>memory counters</a>
 * See <a href="https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/network_counters.html">network counters</a>
 *
 * @param group
 * @param name
 * @param rollupType
 * @return null if a PerfCoutner cannot be found for the given params
 */
private PerfMetricId findMetricId(String group, String name, PerfStatsType type,
        PerformanceManagerUnit unit, PerfSummaryType rollupType) {
    PerfMetricId res = new PerfMetricId();
    PerfCounterInfo counter = this.perfCounterLookup
            .getCounter(name, group, type, rollupType, unit);

    if (counter == null) {
        String msg = String
                .format("Cannot find metric for %s/%s/%s/%s/%s", group, name, type,
                        rollupType.value(),
                        unit.value());
        logger.warning(msg);
        throw new IllegalArgumentException(msg);
    }
    res.setCounterId(counter.getKey());
    res.setInstance("");
    return res;
}
项目:vijava    文件:RealtimePerfMonitor.java   
static PerfQuerySpec createPerfQuerySpec(ManagedEntity me, 
      PerfMetricId[] metricIds, int maxSample, int interval)
  {
    PerfQuerySpec qSpec = new PerfQuerySpec();
    qSpec.setEntity(me.getMOR());
    // set the maximum of metrics to be return
    // only appropriate in real-time performance collecting
    qSpec.setMaxSample(new Integer(maxSample));
//    qSpec.setMetricId(metricIds);
    // optionally you can set format as "normal"
    qSpec.setFormat("csv");
    // set the interval to the refresh rate for the entity
    qSpec.setIntervalId(new Integer(interval));

    return qSpec;
  }
项目: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;
}
项目:vmstats    文件:statsGrabber.java   
private static PerfQuerySpec createPerfQuerySpec(ManagedEntity me, PerfMetricId[] metricIds, int maxSample, int interval) {
    PerfQuerySpec qSpec = new PerfQuerySpec();
    qSpec.setEntity(me.getMOR());
    // set the maximum of metrics to be return
    // only appropriate in real-time performance collecting
    qSpec.setMaxSample(new Integer(maxSample));
    //    qSpec.setMetricId(metricIds);
    // optionally you can set format as "normal"
    qSpec.setFormat("normal");
    // set the interval to the refresh rate for the entity
    qSpec.setIntervalId(new Integer(interval));

    return qSpec;
}
项目:vijava    文件:RealtimePerfMonitor.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 4)
  {
    System.out.println("Usage: java RealtimePerfMonitor " 
      + "<url> <username> <password> <vmname>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  String vmname = args[3];
  ManagedEntity vm = new InventoryNavigator(
    si.getRootFolder()).searchManagedEntity(
      "VirtualMachine", vmname);

  if(vm == null)
  {
    System.out.println("Virtual Machine " + vmname 
        + " cannot be found.");
    si.getServerConnection().logout();
    return;
  }

  PerformanceManager perfMgr = si.getPerformanceManager();

  // find out the refresh rate for the virtual machine
  PerfProviderSummary pps = perfMgr.queryPerfProviderSummary(vm);
  int refreshRate = pps.getRefreshRate().intValue();

  // retrieve all the available perf metrics for vm
  PerfMetricId[] pmis = perfMgr.queryAvailablePerfMetric(
      vm, null, null, refreshRate);

  PerfQuerySpec qSpec = createPerfQuerySpec(
      vm, pmis, 3, refreshRate);

  while(true) 
  {
    PerfEntityMetricBase[] pValues = perfMgr.queryPerf(
      new PerfQuerySpec[] {qSpec});
    if(pValues != null)
    {
      displayValues(pValues);
    }
    System.out.println("Sleeping 60 seconds...");
    Thread.sleep(refreshRate*3*1000);
  }
}
项目:vijava    文件:GetMultiPerf.java   
public static void main(String[] args) throws Exception
{
  if(args.length != 4)
  {
    System.out.println("Usage: java GetMultiPerf " 
      + "<url> <username> <password> <vmname>");
    return;
  }

  ServiceInstance si = new ServiceInstance(
    new URL(args[0]), args[1], args[2], true);

  String vmname = args[3];
  VirtualMachine vm = (VirtualMachine) new InventoryNavigator(
    si.getRootFolder()).searchManagedEntity(
      "VirtualMachine", vmname);

  if(vm == null)
  {
    System.out.println("Virtual Machine " + vmname 
        + " cannot be found.");
    si.getServerConnection().logout();
    return;
  }

  PerformanceManager perfMgr = si.getPerformanceManager();

  int perfInterval = 1800; // 30 minutes for PastWeek

  // retrieve all the available perf metrics for vm
  PerfMetricId[] pmis = perfMgr.queryAvailablePerfMetric(
      vm, null, null, perfInterval);

  Calendar curTime = si.currentTime();

  PerfQuerySpec qSpec = new PerfQuerySpec();
  qSpec.setEntity(vm.getRuntime().getHost());
  //metricIDs must be provided, or InvalidArgumentFault 
  qSpec.setMetricId(pmis);
  qSpec.setFormat("normal"); //optional since it's default
  qSpec.setIntervalId(perfInterval); 

  Calendar startTime = (Calendar) curTime.clone();
  startTime.roll(Calendar.DATE, -4);
  System.out.println("start:" + startTime.getTime());
  qSpec.setStartTime(startTime);

  Calendar endTime = (Calendar) curTime.clone();
  endTime.roll(Calendar.DATE, -3);
  System.out.println("end:" + endTime.getTime());
  qSpec.setEndTime(endTime);

  PerfCompositeMetric pv = perfMgr.queryPerfComposite(qSpec);
  if(pv != null)
  {
    printPerfMetric(pv.getEntity());
    PerfEntityMetricBase[] pembs = pv.getChildEntity();
    for(int i=0; pembs!=null && i< pembs.length; i++)
    {
      printPerfMetric(pembs[i]);
    }
  }
  si.getServerConnection().logout();
}
项目:cloudstack    文件:PerfManagerMO.java   
public List<PerfMetricId> queryAvailablePerfMetric(ManagedObjectReference morEntity, Calendar beginTime, Calendar endTime, Integer intervalId) throws Exception {

        return _context.getService().queryAvailablePerfMetric(_mor, morEntity, calendarToXMLGregorianCalendar(beginTime), calendarToXMLGregorianCalendar(endTime),
                intervalId);
    }
项目:photon-model    文件:StatCollectionContext.java   
/**
 * Add a metric to the query and an aggregator to process it later.
 * @param metric
 * @param samplesAggregator
 */
public void addMetric(PerfMetricId metric, SamplesAggregator samplesAggregator) {
    this.aggregatorsByPerfCounterId.put(metric.getCounterId(), samplesAggregator);
    this.spec.getMetricId().add(metric);
}
项目:jcloud-vsphere    文件:PerformanceManagerApi.java   
List<PerfMetricId> queryAvailablePerfMetric(ManagedEntity entity, Calendar beginTime, Calendar endTime, Integer intervalId) throws RuntimeFault, RemoteException;