Example #1
0
        public checkPerfCount(performanceCounter config)
        {
            this.config = config;
            pluginName  = String.Format("perf_{0}", this.config.name);

            openCounters();

            NodeService.log(String.Format("{0} initialized", pluginName));
        }
Example #2
0
		public checkPerfCount(performanceCounter config)
		{
			this.config = config;
			pluginName = String.Format("perf_{0}", this.config.name);

			openCounters();

			NodeService.log(String.Format("{0} initialized", pluginName));
		}
Example #3
0
        private void openCounters()
        {
            try
            {
                switch (config.perfInstance)
                {
                case "":
                {
                    PerformanceCounter pc = new PerformanceCounter(config.perfObject, config.perfCounter, true);
                    pc.NextValue();
                    counters.Add(pc);
                }
                break;

                case "*":
                {
                    String[] skip = config.skipInstances.Split(new Char[] { ';' });
                    PerformanceCounterCategory category = new PerformanceCounterCategory(config.perfObject);
                    Boolean found = false;
                    foreach (String instance in category.GetInstanceNames())
                    {
                        found = false;
                        NodeService.log(String.Format("Adding instance {0}\\{1}", category.CategoryName, instance));
                        if (skip.Length > 0)
                        {
                            foreach (String s in skip)
                            {
                                if (s.Equals(instance))
                                {
                                    NodeService.log(String.Format("Skipping instance {0}\\{1}", category.CategoryName, instance));
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            PerformanceCounter pc = new PerformanceCounter(config.perfObject, config.perfCounter, instance, true);
                            pc.NextValue();
                            if (counters.Count > 0)
                            {
                                int i = 0;
                                foreach (PerformanceCounter p in counters)
                                {
                                    if (p.InstanceName.CompareTo(pc.InstanceName) > 0)
                                    {
                                        counters.Insert(i, pc);
                                        i = -1;
                                        break;
                                    }
                                    i++;
                                }
                                if (i > 0)
                                {
                                    counters.Add(pc);
                                }
                            }
                            else
                            {
                                counters.Add(pc);
                            }
                        }
                    }
                }
                break;

                default:
                {
                    try
                    {
                        PerformanceCounter pc = new PerformanceCounter(config.perfObject, config.perfCounter, config.perfInstance, true);
                        pc.NextValue();
                        counters.Add(pc);
                    }
                    catch (Exception ex)
                    {
                        NodeService.log(ex.Message);
                    }
                }
                break;
                }
            }
            catch (Exception ex)
            {
                NodeService.log(ex.Message);
                config = null;
            }
        }
Example #4
0
		private void openCounters()
		{
			try
			{
				switch (config.perfInstance)
				{
					case "":
					{
						PerformanceCounter pc = new PerformanceCounter(config.perfObject, config.perfCounter, true);
						pc.NextValue();
						counters.Add(pc);
					}
						break;
					case "*":
					{
						String[] skip = config.skipInstances.Split(new Char[] {';'});
						PerformanceCounterCategory category = new PerformanceCounterCategory(config.perfObject);
						Boolean found = false;
						foreach (String instance in category.GetInstanceNames())
						{
							found = false;
							NodeService.log(String.Format("Adding instance {0}\\{1}", category.CategoryName, instance));
							if (skip.Length > 0)
							{
								foreach (String s in skip)
								{
									if (s.Equals(instance))
									{
										NodeService.log(String.Format("Skipping instance {0}\\{1}", category.CategoryName, instance));
										found = true;
										break;
									}
								}
							}
							if (!found)
							{
								PerformanceCounter pc = new PerformanceCounter(config.perfObject, config.perfCounter, instance, true);
								pc.NextValue();
								if (counters.Count > 0)
								{
									int i = 0;
									foreach (PerformanceCounter p in counters)
									{
										if (p.InstanceName.CompareTo(pc.InstanceName) > 0)
										{
											counters.Insert(i, pc);
											i = -1;
											break;
										}
										i++;
									}
									if (i > 0)
									{
										counters.Add(pc);
									}
								}
								else
								{
									counters.Add(pc);
								}
							}
						}
					}
						break;
					default:
					{
						try
						{
							PerformanceCounter pc = new PerformanceCounter(config.perfObject, config.perfCounter, config.perfInstance, true);
							pc.NextValue();
							counters.Add(pc);
						}
						catch (Exception ex)
						{
							NodeService.log(ex.Message);
						}
					}
						break;
				}
			}
			catch (Exception ex)
			{
				NodeService.log(ex.Message);
				config = null;
			}
		}