public void AddCounter(CounterDefinition counter) { _counters.Add(counter); if (DefinitionsChanged != null) { DefinitionsChanged(this, EventArgs.Empty); } }
public void AddDefinition(CounterDefinition definition) { if (definition.CollectIntervalSpan != _period) { throw new ArgumentException("definition.CollectionInterval is not equals to this interval period!"); } _readers.Add(new Reader(definition, _machineNameProvider, _counterIdentifierGenerator)); }
public void Add(CounterDefinition definition) { if (!_definitions.Contains(definition)) { _definitions.Add(definition); if (DefinitionsChanged != null) { DefinitionsChanged(this, EventArgs.Empty); } } }
public string Generate(IMachineNameProvider machineNameProvider, CounterDefinition counterDefinition) { var machineName = machineNameProvider.GetMachineName(); if (string.IsNullOrEmpty(counterDefinition.InstanceName)) { return string.Format("{0}.{1}.{2}", machineName, counterDefinition.CategoryName, counterDefinition.CounterName); } return string.Format("{0}.{1}.{2}.{3}", machineName, counterDefinition.CategoryName, counterDefinition.CounterName, counterDefinition.InstanceName); }
public void return_true_for_exists_when_counter_has_no_intance() { var counter = new CounterDefinition { CategoryName = "Memory", CollectInterval = 1000, CounterName = "Available MBytes", InstanceName = string.Empty }; Assert.True(counter.Exists()); }
internal Reader(CounterDefinition definition, IMachineNameProvider machineNameProvider, ICounterIdentifierGenerator counterIdentifierGenerator) { _definition = definition; _machineNameProvider = machineNameProvider; _counterIdentifierGenerator = counterIdentifierGenerator; if (_definition == null || _definition.CategoryName.IsEmpty() || _definition.CounterName.IsEmpty()) { Logger.Error("Invalid Counter Definition"); throw new ArgumentException("definition"); } _counter = new PerformanceCounter(definition.CategoryName, definition.CounterName, definition.InstanceName, true); }
when_passing_a_counter_name_with_spaces_should_expand_correctly () { var counter = new CounterDefinition { CategoryName = "PhysicalDisk", CollectInterval = 1000, CounterName = "% Idle Time", InstanceName = "_Total" }; var counters = counter.Expand().ToList(); Assert.Equal(1, counters.Count); Assert.Equal(counter.InstanceName, counters.First().InstanceName); Assert.Equal(counter.CategoryName, counters.First().CategoryName); Assert.Equal(counter.CounterName, counters.First().CounterName); }
when_passing_a_regex_to_return_all_instances_and_the_counter_has_no_instance_should_return_the_default_single_instance_name () { var counter = new CounterDefinition { CategoryName = "Memory", CollectInterval = 1000, CounterName = "Available MBytes", InstanceName = "/.*/" }; var counters = counter.Expand().ToList(); Assert.Equal(1,counters.Count); Assert.Equal(string.Empty,counters.First().InstanceName); Assert.Equal(counter.CategoryName, counters.First().CategoryName); Assert.Equal(counter.CounterName, counters.First().CounterName); }
private void AddReader(CounterDefinition definition, IEnumerable<ISendInfo> sinks) { foreach (var counterDefinition in definition.Expand()) { if (counterDefinition.Exists()) { Interval interval = null; if (!_counters.TryGetValue(counterDefinition.CollectIntervalSpan, out interval)) { interval = new Interval(counterDefinition.CollectIntervalSpan, sinks, _machineNameProvider, _counterIdentifierGenerator); _counters.Add(counterDefinition.CollectIntervalSpan, interval); } interval.AddDefinition(counterDefinition); } else { Logger.ErrorFormat( "received a counter definition for a non existente counter/instance: {@definition}. Ignoring it!", counterDefinition); } } }