Exemplo n.º 1
0
 /// <summary>
 /// Displays the values timestamps, intervals, instances etc.
 /// </summary>
 /// <param name="values"></param>
 /// <param name="pci"></param>
 /// <param name="pmid"></param>
 /// <param name="interval"></param>
 private void displayValues(PerfEntityMetricBase[] values,
                            PerfCounterInfo pci,
                            PerfMetricId pmid,
                            int interval)
 {
     for (int i = 0; i < values.Length; ++i)
     {
         PerfMetricSeries[] vals  = ((PerfEntityMetric)values[i]).value;
         PerfSampleInfo[]   infos = ((PerfEntityMetric)values[i]).sampleInfo;
         if (infos == null || infos.Length == 0)
         {
             Console.WriteLine("No Samples available. Continuing.");
             continue;
         }
         Console.WriteLine("Sample time range: "
                           + infos[0].timestamp.TimeOfDay.ToString() + " - " +
                           infos[infos.Length - 1].timestamp.TimeOfDay.ToString() +
                           ", read every " + interval + " seconds");
         for (int vi = 0; vi < vals.Length; ++vi)
         {
             if (pci != null)
             {
                 if (pci.key != vals[vi].id.counterId)
                 {
                     continue;
                 }
                 Console.WriteLine(pci.nameInfo.summary
                                   + " - Instance: " + pmid.instance);
             }
             if (vals[vi].GetType().Name.Equals("PerfMetricIntSeries"))
             {
                 PerfMetricIntSeries val = (PerfMetricIntSeries)vals[vi];
                 long[] longs            = val.value;
                 for (int k = 0; k < longs.Length; ++k)
                 {
                     Console.WriteLine(longs[k] + " ");
                 }
                 Console.WriteLine();
             }
         }
     }
 }
Exemplo n.º 2
0
  /// <summary>
  /// Displays the values timestamps, intervals, instances etc.
  /// </summary>
  /// <param name="values"></param>
  /// <param name="pci"></param>
  /// <param name="pmid"></param>
  /// <param name="interval"></param>
 private void displayValues(PerfEntityMetricBase[] values, 
                            PerfCounterInfo pci, 
                            PerfMetricId pmid,
                            int interval) {
    for(int i=0; i<values.Length; ++i) {
       PerfMetricSeries[] vals = ((PerfEntityMetric)values[i]).value;
       PerfSampleInfo[]  infos = ((PerfEntityMetric)values[i]).sampleInfo;
       if (infos == null || infos.Length == 0) {
          Console.WriteLine("No Samples available. Continuing.");
          continue;
       }
       Console.WriteLine("Sample time range: " 
                         + infos[0].timestamp.TimeOfDay.ToString() + " - " +
                          infos[infos.Length-1].timestamp.TimeOfDay.ToString() +
                          ", read every "+interval+" seconds");
       for(int vi=0; vi<vals.Length; ++vi) {
          if(pci != null) {
             if(pci.key != vals[vi].id.counterId)
             continue;
             Console.WriteLine(pci.nameInfo.summary 
                              + " - Instance: " + pmid.instance);
          }
          if(vals[vi].GetType().Name.Equals("PerfMetricIntSeries")){
             PerfMetricIntSeries val = (PerfMetricIntSeries)vals[vi];
             long[] longs = val.value;
             for(int k=0; k<longs.Length; ++k) {
                Console.WriteLine(longs[k] + " ");
             }
             Console.WriteLine();
          }
       }
    }
 }
Exemplo n.º 3
0
        /// <summary>
        ///Displays the performance measurements of specified counter of specified
        ///Host System.
        /// </summary>
        private void displayHistory()
        {
            ManagedObjectReference hostmor
                = cb.getServiceUtil().GetDecendentMoRef(null, "HostSystem",
                                                        cb.get_option("hostname"));

            if (hostmor == null)
            {
                Console.WriteLine("Host " + cb.get_option("hostname") + " not found");
                return;
            }
            ManagedObjectReference pmRef
                = cb.getConnection()._sic.perfManager;

            CounterInfo(pmRef);

            //Retrieves all configured historical archive sampling intervals.
            PerfInterval[] intervals
                = (PerfInterval[])cb.getServiceUtil().GetDynamicProperty(pmRef,
                                                                         "historicalInterval");
            int     interval = (int.Parse(cb.get_option("interval")));
            Boolean valid    = checkInterval(intervals, interval);

            if (!valid)
            {
                Console.WriteLine("Invalid inerval, Specify one from above");
                return;
            }

            PerfCounterInfo pci = getCounterInfo(cb.get_option("groupname"),
                                                 cb.get_option("countername"),
                                                 PerfSummaryType.average);

            if (pci == null)
            {
                Console.WriteLine("Incorrect Group Name and Counters Specified");
                return;
            }

            //specifies the query parameters to be used while retrieving statistics.
            //e.g. entity, maxsample etc.
            PerfQuerySpec qSpec = new PerfQuerySpec();

            qSpec.entity             = hostmor;
            qSpec.maxSample          = 10;
            qSpec.maxSampleSpecified = true;
            PerfQuerySpec[] qSpecs = new PerfQuerySpec[] { qSpec };

            DateTime sTime;
            DateTime eTime = cb.getConnection()._service.CurrentTime(
                cb.getConnection().ServiceRef);

            double duration  = double.Parse(cb.get_option("duration"));
            double startTime = double.Parse(cb.get_option("starttime"));


            sTime = eTime.AddMinutes(-duration);

            Console.WriteLine("Start Time " + sTime.TimeOfDay.ToString());
            Console.WriteLine("End Time   " + eTime.TimeOfDay.ToString());

            Console.WriteLine();
            //Retrieves the query available of performance metric for a host.
            PerfMetricId[] aMetrics
                = cb.getConnection()._service.QueryAvailablePerfMetric(pmRef,
                                                                       hostmor,
                                                                       sTime,
                                                                       true,
                                                                       eTime,
                                                                       true,
                                                                       interval, true);
            PerfMetricId ourCounter = null;

            for (int index = 0; index < aMetrics.Length; ++index)
            {
                if (aMetrics[index].counterId == pci.key)
                {
                    ourCounter = aMetrics[index];
                    break;
                }
            }
            if (ourCounter == null)
            {
                Console.WriteLine("No data on Host to collect. "
                                  + "Has it been running for at least "
                                  + cb.get_option("duration") + " minutes");
            }
            else
            {
                qSpec                     = new PerfQuerySpec();
                qSpec.entity              = hostmor;
                qSpec.startTime           = sTime;
                qSpec.endTime             = eTime;
                qSpec.metricId            = (new PerfMetricId[] { ourCounter });
                qSpec.intervalId          = interval;
                qSpec.intervalIdSpecified = true;
                qSpec.startTimeSpecified  = true;
                qSpec.endTimeSpecified    = true;
                qSpecs                    = new PerfQuerySpec[] { qSpec };
                //
                PerfEntityMetricBase[] samples
                    = cb.getConnection()._service.QueryPerf(pmRef, qSpecs);
                if (samples != null)
                {
                    displayValues(samples, pci, ourCounter, interval);
                }
                else
                {
                    Console.WriteLine("No Smaples Found");
                }
            }
        }