Exemplo n.º 1
0
 ///<summary>
 ///Displays the values of sample time range.
 ///</summary>
 ///<param name="values"></param>
 ///<param name="counters"></param>
 void displayValues(PerfEntityMetricBase[] values, Hashtable counters)
 {
     for (int i = 0; i < values.Length; ++i)
     {
         PerfMetricSeries[] vals  = ((PerfEntityMetric)values[i]).value;
         PerfSampleInfo[]   infos = ((PerfEntityMetric)values[i]).sampleInfo;
         Console.WriteLine("Sample time range: " +
                           infos[0].timestamp.TimeOfDay.ToString() + " - " +
                           infos[infos.Length - 1].timestamp.TimeOfDay.ToString());
         for (int vi = 0; vi < vals.Length; vi++)
         {
             PerfCounterInfo pci
                 = (PerfCounterInfo)counters[vals[vi].id.counterId];
             if (pci != null)
             {
                 Console.WriteLine(pci.nameInfo.summary);
             }
             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>
 ///Retrieves counter information.
 ///</summary>
 ///<param name="pmRef"></param>
 private void CounterInfo(ManagedObjectReference pmRef)
 {
     PerfCounterInfo[] cInfos
         = (PerfCounterInfo[])cb.getServiceUtil().GetDynamicProperty(pmRef,
                                                                     "perfCounter");
     for (int i = 0; i < cInfos.Length; ++i)
     {
         PerfCounterInfo cInfo   = cInfos[i];
         String          group   = cInfo.groupInfo.key;
         Hashtable       nameMap = null;
         if (!_pci.ContainsKey(group))
         {
             nameMap = new Hashtable();
             _pci.Add(group, nameMap);
         }
         else
         {
             nameMap = (Hashtable)_pci[group];
         }
         String    name     = cInfo.nameInfo.key;
         ArrayList counters = null;
         if (!nameMap.ContainsKey(name))
         {
             counters = new ArrayList();
             nameMap.Add(name, counters);
         }
         else
         {
             counters = (ArrayList)nameMap[name];
         }
         counters.Add(cInfo);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves counter information for given groupname and countername and rolluptype.
        /// </summary>
        /// <param name="groupName"></param>
        /// <param name="counterName"></param>
        /// <param name="rollupType"></param>
        /// <returns>
        /// Returns the object type with the current information of performance counter
        /// </returns>
        private PerfCounterInfo getCounterInfo(String groupName,
                                               String counterName,
                                               PerfSummaryType rollupType)
        {
            ArrayList counters = getCounterInfos(groupName, counterName);

            if (counters != null)
            {
                for (IEnumerator i = counters.GetEnumerator(); i.MoveNext();)
                {
                    PerfCounterInfo pci = (PerfCounterInfo)i.Current;
                    if (rollupType == null || rollupType.Equals(pci.rollupType))
                    {
                        return(pci);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 4
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.º 5
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.º 6
0
        private void printEntityCounters(String entityType)
        {
            ManagedObjectReference mor = getManagedObjectReference(entityType);
            ManagedObjectReference pmRef
                = cb.getConnection()._sic.perfManager;

            PerfCounterInfo[] cInfo
                = (PerfCounterInfo[])cb.getServiceUtil().GetDynamicProperty(pmRef,
                                                                            "perfCounter");
            if (mor != null)
            {
                ArrayList    ids = getPerfIdsAvailable(pmRef, mor);
                StreamWriter sw  = new StreamWriter(cb.get_option("filename"));
                if (cInfo != null)
                {
                    sw.Write("<perf-counters>");
                    for (int c = 0; c < cInfo.Length; ++c)
                    {
                        PerfCounterInfo pci = cInfo[c];
                        int             id  = pci.key;
                        if (ids.Contains(id))
                        {
                            sw.Write("  <perf-counter key=\"");
                            sw.Write(id);
                            sw.Write("\" ");

                            sw.Write("rollupType=\"");
                            sw.Write(pci.rollupType.ToString());
                            sw.Write("\" ");

                            sw.Write("statsType=\"");
                            sw.Write(pci.statsType.ToString());
                            sw.Write("\">");
                            printElementDescription(sw, "groupInfo", pci.groupInfo);
                            printElementDescription(sw, "nameInfo", pci.nameInfo);
                            printElementDescription(sw, "unitInfo", pci.unitInfo);

                            sw.Write("    <entity type=\"" + entityType + "\"/>");
                            int[] ac = pci.associatedCounterId;
                            if (ac != null)
                            {
                                for (int a = 0; a < ac.Length; ++a)
                                {
                                    sw.Write("    <associatedCounter>" + ac[a]
                                             + "</associatedCounter>");
                                }
                            }
                            sw.Write("  </perf-counter>");
                        }
                    }
                    sw.Write("</perf-counters>");
                    sw.Flush();
                    sw.Close();
                }
                Console.WriteLine("Check " + cb.get_option("filename")
                                  + " for Print Counters");
            }
            else
            {
                Console.WriteLine(entityType + " " + cb.get_option("entityname")
                                  + " not found.");
            }
        }
Exemplo n.º 7
0
        private void doRealTime()
        {
            ManagedObjectReference vmmor
                = cb.getServiceUtil().GetDecendentMoRef(null,
                                                        "VirtualMachine",
                                                        cb.get_option("vmname"));

            if (vmmor != null)
            {
                ManagedObjectReference pmRef
                    = cb.getConnection()._sic.perfManager;
                PerfCounterInfo[] cInfo
                    = (PerfCounterInfo[])cb.getServiceUtil().GetDynamicProperty(pmRef,
                                                                                "perfCounter");
                ArrayList vmCpuCounters = new ArrayList();
                for (int i = 0; i < cInfo.Length; ++i)
                {
                    if ("cpu".Equals(cInfo[i].groupInfo.key))
                    {
                        vmCpuCounters.Add(cInfo[i]);
                    }
                }
                Hashtable counters = new Hashtable();
                while (true)
                {
                    int index = 0;
                    for (IEnumerator it = vmCpuCounters.GetEnumerator(); it.MoveNext();)
                    {
                        PerfCounterInfo pcInfo = (PerfCounterInfo)it.Current;
                        Console.WriteLine(++index + " - " + pcInfo.nameInfo.summary);
                    }
                    index = cb.getUtil().getIntInput("Please select a counter from"
                                                     + " the above list" + "\nEnter 0 to end: ", 1);
                    if (index > vmCpuCounters.Count || index <= 0)
                    {
                        Console.WriteLine("*** Value out of range!");
                    }
                    else
                    {
                        --index;
                        if (index < 0)
                        {
                            return;
                        }
                        PerfCounterInfo pcInfo = (PerfCounterInfo)vmCpuCounters[index];
                        counters.Add((pcInfo.key), pcInfo);
                        break;
                    }
                }
                PerfMetricId[] aMetrics
                    = cb.getConnection()._service.QueryAvailablePerfMetric(pmRef,
                                                                           vmmor,
                                                                           DateTime.MinValue,
                                                                           false,
                                                                           DateTime.MaxValue,
                                                                           false,
                                                                           20, true);
                ArrayList mMetrics = new ArrayList();
                if (aMetrics != null)
                {
                    for (int index = 0; index < aMetrics.Length; ++index)
                    {
                        if (counters.ContainsKey(aMetrics[index].counterId))
                        {
                            mMetrics.Add(aMetrics[index]);
                        }
                    }
                }
                if (mMetrics.Count > 0)
                {
                    monitorPerformance(pmRef, vmmor, mMetrics, counters);
                }
                else
                {
                    Console.WriteLine("Data for selected counter is not available");
                }
            }
            else
            {
                Console.WriteLine("Virtual Machine " + cb.get_option("vmname") + " not found");
            }
        }
Exemplo n.º 8
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");
                }
            }
        }