public void PropagateRetract(IExecutionContext context, TupleFactList tupleFactList) { if (tupleFactList.Count == 0) { return; } IBetaMemory memory = context.WorkingMemory.GetNodeMemory(this); var toRetract = new List <Tuple>(); using (var counter = PerfCounter.Retract(context, this)) { var enumerator = tupleFactList.GetEnumerator(); while (enumerator.MoveNext()) { Tuple childTuple = memory.FindTuple(enumerator.CurrentTuple, enumerator.CurrentFact); if (childTuple != null) { toRetract.Add(childTuple); } } counter.AddInputs(tupleFactList.Count); counter.AddOutputs(toRetract.Count); } PropagateRetractInternal(context, memory, toRetract); }
static void TestServer() { _counter = new PerfCounter(); // 实例化服务端,指定端口,同时在Tcp/Udp/IPv4/IPv6上监听 var svr = new NetServer { Port = 1234, Log = XTrace.Log, #if DEBUG SocketLog = XTrace.Log, LogSend = true, LogReceive = true, #endif }; //svr.Add(new LengthFieldCodec { Size = 4 }); svr.Add <StandardCodec>(); //svr.Add<EchoHandler>(); svr.Add(new EchoHandler { Counter = _counter }); svr.Start(); _server = svr; // 定时显示性能数据 _timer = new TimerX(ShowStat, svr, 100, 1000) { Async = true }; }
public void PerfCounter_SystemMemoryAutodetection_SystemMemoryAsMax() { var perfCounter = new PerfCounter("Memory", "Available MBytes", "none", "AvailableMBytes", "MB", "10%", "5%", "0", "automemory"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.GetMax(), GetTotalMemory("MB")); }
public void PropagateRetract(IExecutionContext context, List <Tuple> tuples) { var toRetract = new List <Fact>(tuples.Count); using (var counter = PerfCounter.Retract(context, this)) { foreach (var tuple in tuples) { var wrapperFact = context.WorkingMemory.GetStateOrThrow <WrapperFact>(this, tuple); toRetract.Add(wrapperFact); } counter.AddItems(tuples.Count); } foreach (var sink in _sinks) { sink.PropagateRetract(context, toRetract); } using (PerfCounter.Retract(context, this)) { foreach (var tuple in tuples) { context.WorkingMemory.RemoveStateOrThrow <WrapperFact>(this, tuple); } } }
public void PerfCounter_SimulateReverseWarning_StatusWarning() { var perfCounter = new PerfCounter("Memory", "Available MBytes", "none", "AvailableMBytes", "MB", "95%", "10%", "0", "automemory"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 1); }
public void PerfCounter_SimulateOnlyLessCritical_StatusCritical() { var perfCounter = new PerfCounter("Memory", "Available MBytes", "none", "AvailableMBytes", "MB", "none", "lt90%", "0", "automemory"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 2); }
public virtual void PropagateAssert(IExecutionContext context, List <Fact> facts) { var toAssert = new List <Fact>(); using (var counter = PerfCounter.Assert(context, this)) { foreach (var fact in facts) { if (IsSatisfiedBy(context, fact)) { toAssert.Add(fact); } } counter.AddInputs(facts.Count); counter.AddOutputs(toAssert.Count); } if (toAssert.Count > 0) { foreach (var childNode in ChildNodes) { childNode.PropagateAssert(context, toAssert); } MemoryNode?.PropagateAssert(context, toAssert); } }
public override void PropagateUpdate(IExecutionContext context, List <Tuple> tuples) { if (_isSubnetJoin) { return; } var toUpdate = new TupleFactList(); var toRetract = new TupleFactList(); using (var counter = PerfCounter.Update(context, this)) { var joinedSets = JoinedSets(context, tuples); foreach (var set in joinedSets) { foreach (var fact in set.Facts) { if (MatchesConditions(context, set.Tuple, fact)) { toUpdate.Add(set.Tuple, fact); } else { toRetract.Add(set.Tuple, fact); } } } counter.AddInputs(tuples.Count); counter.AddOutputs(toUpdate.Count + toRetract.Count); } MemoryNode.PropagateRetract(context, toRetract); MemoryNode.PropagateUpdate(context, toUpdate); }
public void PropagateUpdate(IExecutionContext context, List <Fact> facts) { IAlphaMemory memory = context.WorkingMemory.GetNodeMemory(this); var toUpdate = new List <Fact>(); var toAssert = new List <Fact>(); using (var counter = PerfCounter.Update(context, this)) { foreach (var fact in facts) { if (memory.Contains(fact)) { toUpdate.Add(fact); } else { toAssert.Add(fact); } } counter.AddItems(facts.Count); } if (toUpdate.Count > 0) { foreach (var sink in _sinks) { sink.PropagateUpdate(context, toUpdate); } } if (toAssert.Count > 0) { PropagateAssert(context, toAssert); } }
public void PropagateRetract(IExecutionContext context, List <Fact> facts) { IAlphaMemory memory = context.WorkingMemory.GetNodeMemory(this); var toRetract = new List <Fact>(facts.Count); using (var counter = PerfCounter.Retract(context, this)) { foreach (var fact in facts) { if (memory.Contains(fact)) { toRetract.Add(fact); } } counter.AddInputs(facts.Count); counter.AddOutputs(toRetract.Count); } if (toRetract.Count > 0) { foreach (var sink in _sinks) { sink.PropagateRetract(context, toRetract); } using (var counter = PerfCounter.Retract(context, this)) { memory.Remove(toRetract); counter.SetCount(memory.FactCount); } } }
public PerfCounter Groups; // # of entities tracked /// <summary> /// Initializes the service's performance counters from the performance /// counter set passed. /// </summary> /// <param name="perfCounters">The application's performance counter set (or <c>null</c>).</param> /// <param name="perfPrefix">The string to prefix any performance counter names (or <c>null</c>).</param> public Perf(PerfCounterSet perfCounters, string perfPrefix) { Install(perfCounters, perfPrefix); if (perfPrefix == null) { perfPrefix = string.Empty; } if (perfCounters != null) { IPGeocode = perfCounters[perfPrefix + IPGeocode_Name]; FixesReceived = perfCounters[perfPrefix + FixesReceived_Name]; FixesArchived = perfCounters[perfPrefix + FixesArchived_Name]; Runtime = perfCounters[perfPrefix + Runtime_Name]; Entities = perfCounters[perfPrefix + Entities_Name]; Groups = perfCounters[perfPrefix + Groups_Name]; } else { IPGeocode = FixesReceived = FixesArchived = Runtime = Entities = Groups = PerfCounter.Stub; } }
public override void PropagateUpdate(IExecutionContext context, List <Tuple> tuples) { var toAssert = new TupleFactList(); var toUpdate = new TupleFactList(); var toRetract = new TupleFactList(); using (var counter = PerfCounter.Update(context, this)) { foreach (var tuple in tuples) { var fact = context.WorkingMemory.GetState <Fact>(this, tuple); if (fact != null) { UpdateBinding(context, tuple, fact, toUpdate, toRetract); } else { AssertBinding(context, tuple, toAssert); } } counter.AddItems(tuples.Count); } MemoryNode.PropagateRetract(context, toRetract); MemoryNode.PropagateUpdate(context, toUpdate); MemoryNode.PropagateAssert(context, toAssert); }
public virtual void PropagateUpdate(IExecutionContext context, List <Fact> facts) { var toUpdate = new List <Fact>(); var toRetract = new List <Fact>(); using (var counter = PerfCounter.Update(context, this)) { foreach (var fact in facts) { if (IsSatisfiedBy(context, fact)) { toUpdate.Add(fact); } else { toRetract.Add(fact); } } counter.AddInputs(facts.Count); counter.AddOutputs(toUpdate.Count + toRetract.Count); } PropagateUpdateInternal(context, toUpdate); PropagateRetractInternal(context, toRetract); }
/// <summary>打开客户端</summary> public virtual Boolean Open() { if (Active) { return(true); } lock (Root) { if (Active) { return(true); } var ss = Servers; if (ss == null || ss.Length == 0) { throw new ArgumentNullException(nameof(Servers), "未指定服务端地址"); } if (Encoder == null) { Encoder = new JsonEncoder(); } //if (Encoder == null) Encoder = new BinaryEncoder(); if (Handler == null) { Handler = new ApiHandler { Host = this } } ; // 集群 Cluster = InitCluster(); WriteLog("集群:{0}", Cluster); Encoder.Log = EncoderLog; // 控制性能统计信息 var ms = StatPeriod * 1000; if (ms > 0) { if (StatSend == null) { StatSend = new PerfCounter(); } if (StatReceive == null) { StatReceive = new PerfCounter(); } _Timer = new TimerX(DoWork, null, ms, ms) { Async = true }; } return(Active = true); } }
public override void PropagateAssert(IExecutionContext context, List <Fact> facts) { var aggregationContext = new AggregationContext(context, NodeInfo); var aggregation = new Aggregation(); using (var counter = PerfCounter.Assert(context, this)) { var joinedSets = JoinedSets(context, facts); foreach (var set in joinedSets) { if (set.Facts.Count == 0) { continue; } IFactAggregator aggregator = GetFactAggregator(context, set.Tuple); if (aggregator == null) { aggregator = CreateFactAggregator(context, set.Tuple); var originalSet = JoinedSet(context, set.Tuple); var matchingOriginalFacts = originalSet.Facts; AddToAggregate(aggregationContext, aggregator, aggregation, originalSet.Tuple, matchingOriginalFacts); } AddToAggregate(aggregationContext, aggregator, aggregation, set.Tuple, set.Facts); } counter.AddInputs(facts.Count); counter.AddOutputs(aggregation.Count); } PropagateAggregation(context, aggregation); }
public void PropagateUpdate(IExecutionContext context, TupleFactList tupleFactList) { if (tupleFactList.Count == 0) { return; } IBetaMemory memory = context.WorkingMemory.GetNodeMemory(this); var toAssert = new List <Tuple>(); var toUpdate = new List <Tuple>(); using (var counter = PerfCounter.Update(context, this)) { var enumerator = tupleFactList.GetEnumerator(); while (enumerator.MoveNext()) { Tuple childTuple = memory.FindTuple(enumerator.CurrentTuple, enumerator.CurrentFact); if (childTuple == null) { childTuple = new Tuple(context.IdGenerator.NextTupleId(), enumerator.CurrentTuple, enumerator.CurrentFact); childTuple.GroupId = enumerator.CurrentTuple.Id; toAssert.Add(childTuple); } else { toUpdate.Add(childTuple); } } counter.AddItems(tupleFactList.Count); } PropagateAssertInternal(context, memory, toAssert); PropagateUpdateInternal(context, toUpdate); }
public override void PropagateRetract(IExecutionContext context, List <Fact> facts) { var aggregationContext = new AggregationContext(context, NodeInfo); var aggregation = new Aggregation(); using (var counter = PerfCounter.Retract(context, this)) { var joinedSets = JoinedSets(context, facts); foreach (var set in joinedSets) { if (set.Facts.Count == 0) { continue; } IFactAggregator aggregator = GetFactAggregator(context, set.Tuple); if (aggregator != null) { RetractFromAggregate(aggregationContext, aggregator, aggregation, set.Tuple, set.Facts); } } counter.AddInputs(facts.Count); counter.AddOutputs(aggregation.Count); } PropagateAggregation(context, aggregation); }
public void PerfCounter_SimulateWarning_StatusWarning() { var perfCounter = new PerfCounter("Processor", "% Processor Time", "_Total", "ProcessorTime", "%", "1", "99", "0", "100"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 1); }
public override void PropagateUpdate(IExecutionContext context, List <Tuple> tuples) { var aggregationContext = new AggregationContext(context, NodeInfo); var aggregation = new Aggregation(); using (var counter = PerfCounter.Update(context, this)) { var joinedSets = JoinedSets(context, tuples); foreach (var set in joinedSets) { IFactAggregator aggregator = GetFactAggregator(context, set.Tuple); if (aggregator != null) { if (_isSubnetJoin && set.Facts.Count > 0) { //Update already propagated from the right continue; } UpdateInAggregate(aggregationContext, aggregator, aggregation, set.Tuple, set.Facts); } else { var matchingFacts = set.Facts; aggregator = CreateFactAggregator(context, set.Tuple); AddToAggregate(aggregationContext, aggregator, aggregation, set.Tuple, matchingFacts); } } counter.AddInputs(tuples.Count); counter.AddOutputs(aggregation.Count); } PropagateAggregation(context, aggregation); }
public void PerfCounter_SimulateOnlyGreaterCritical_StatusCritical() { var perfCounter = new PerfCounter("Processor", "% Processor Time", "_Total", "ProcessorTime", "%", "none", "gt5", "0", "100"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 2); }
/// <summary> /// Returns a performance counter. /// </summary> public PerformanceCounter GetPerfCounter(PerfCounter counter, string instanceName, bool readOnly = false) { if (!testPerfCountersCreated) { try { CreatePerfCounters(); } catch (Exception ex) { Logger.Warn("Unable to create performance counters.", ex); } testPerfCountersCreated = true; } var perfCounter = new PerformanceCounter(); switch (counter) { case PerfCounter.NumRequestsHandled: perfCounter.CounterName = @"# requests handled"; perfCounter.CategoryName = PerfCounterCategoryRequestHandling; break; case PerfCounter.NumRequestsHandledPerSec: perfCounter.CounterName = @"# requests handled / sec"; perfCounter.CategoryName = PerfCounterCategoryRequestHandling; break; case PerfCounter.AverageDurationForRequestHandling: perfCounter.CounterName = @"average time per request handling"; perfCounter.CategoryName = PerfCounterCategoryRequestHandling; break; case PerfCounter.AverageDurationForRequestHandlingBase: perfCounter.CounterName = @"average time per request handling base"; perfCounter.CategoryName = PerfCounterCategoryRequestHandling; break; case PerfCounter.NumMessagesSent: perfCounter.CounterName = @"# messages sent"; perfCounter.CategoryName = PerfCounterCategoryMessageSending; break; case PerfCounter.NumMessagesSentPerSec: perfCounter.CounterName = @"# messages sent / sec"; perfCounter.CategoryName = PerfCounterCategoryMessageSending; break; case PerfCounter.AverageDurationForMessageSending: perfCounter.CounterName = @"average time per message sending"; perfCounter.CategoryName = PerfCounterCategoryMessageSending; break; case PerfCounter.AverageDurationForMessageSendingBase: perfCounter.CounterName = @"average time per message sending base"; perfCounter.CategoryName = PerfCounterCategoryMessageSending; break; default: throw new ColomboException(string.Format("Unable to create performance counter {0}", counter)); } perfCounter.MachineName = "."; perfCounter.InstanceName = instanceName; perfCounter.ReadOnly = readOnly; return perfCounter; }
public void PerfCounter_InterfaceSpeedAutodetection_InterfaceSpeedAsMax() { var perfCounter = new PerfCounter("Network Adapter", "Bytes Total/Sec", "autonetwork", "BytesTotalSec", "B", "80%", "90%", "0", "autonetwork"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.GetMax(), GetNetworkInterfaceSpeed(GetNetworkInterface())); }
public void PerfCounter_NotCheckWarningAndCritical_StatusOk() { var perfCounter = new PerfCounter("Processor", "% Processor Time", "_Total", "ProcessorTime", "%", "none", "none", "0", "100"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 0); }
public virtual void PropagateRetract(IExecutionContext context, List <Fact> facts) { using (var counter = PerfCounter.Retract(context, this)) { counter.AddItems(facts.Count); } PropagateRetractInternal(context, facts); }
/// <summary>打开</summary> /// <returns>是否成功</returns> public virtual Boolean Open() { if (Disposed) { throw new ObjectDisposedException(GetType().Name); } if (Active) { return(true); } LogPrefix = "{0}.".F((Name + "").TrimEnd("Server", "Session", "Client")); BufferSize = Setting.Current.BufferSize; // 估算完成时间,执行过长时提示 using (var tc = new TimeCost(GetType().Name + ".Open", 1500)) { tc.Log = Log; _RecvCount = 0; Active = OnOpen(); if (!Active) { return(false); } if (Timeout > 0) { Client.ReceiveTimeout = Timeout; } if (!Local.IsUdp) { // 管道 var pp = Pipeline; pp?.Open(pp.CreateContext(this)); } } // 统计 if (StatSend == null) { StatSend = new PerfCounter(); } if (StatReceive == null) { StatReceive = new PerfCounter(); } ReceiveAsync(); // 触发打开完成的事件 Opened?.Invoke(this, EventArgs.Empty); return(true); }
public static PerfCounter Read(BinaryReader reader) { PerfCounter result = new PerfCounter(); result.CounterId = Utilities.Read7BitEncodedInt(reader); result.TimeStamp = Utilities.Read7BitEncodedInt64(reader); result.Value = reader.ReadDouble(); return(result); }
public void PerfCounter_SimulateOkWithOnlyCriticalCheck_StatusOk() { var perfCounter = new PerfCounter("Processor", "% Processor Time", "_Total", "ProcessorTime", "%", "none", "gt90", "0", "100"); CalculatePerfCounter(perfCounter); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 0); var perfCounter2 = new PerfCounter("Memory", "Available MBytes", "none", "AvailableMBytes", "MB", "none", "lt10%", "0", "automemory"); CalculatePerfCounter(perfCounter2); Assert.AreEqual(perfCounter.CounterStatus.GetNagiosExitCode(), 0); }
public static void Main(string[] args) { if (!"114.114.114.114".GetIPLocation().Contains("南京")) { throw new Exception("IP地址库初始化失败,请重启应用!"); } InitOneDrive(); PerfCounter.Init(); CreateWebHostBuilder(args).Build().Run(); }
public void PropagateRetract(IExecutionContext context, List <Tuple> tuples) { using var counter = PerfCounter.Retract(context, this); foreach (var tuple in tuples) { var activation = context.WorkingMemory.RemoveStateOrThrow <Activation>(this, tuple); context.Agenda.Remove(activation); context.EventAggregator.RaiseActivationDeleted(context.Session, activation); } counter.AddItems(tuples.Count); }
/// <summary> /// Simulate performance counter calculation using 3 samples /// </summary> /// <param name="perfCounter"></param> private static void CalculatePerfCounter(PerfCounter perfCounter) { perfCounter.Initialize(); System.Threading.Thread.Sleep(1000); perfCounter.NextValue(); System.Threading.Thread.Sleep(1000); perfCounter.NextValue(); System.Threading.Thread.Sleep(1000); perfCounter.NextValue(); perfCounter.Calculate(); }
public static void WriteRows(StringBuilder sb, string text, Func <int> makeQuery) { var start = PerfCounter.Ticks; var result = makeQuery(); var end = PerfCounter.Ticks; var ts = TimeSpan.FromMilliseconds(PerfCounter.ToMilliseconds(start, end)); sb.AppendLine($"{text}: {result} rows affected in {ts.NiceToString()}"); }
public PerfCounter GetPerfCounter() { PerfCounter pc = new PerfCounter { Duration = this.Duration, CalcMethod = this.CalcMethod, Command = this.Command, CriticalMethod = this.CriticalMethod, CriticalValue = this.CriticalValue, WarningMethod = this.WarningMethod, WarningValue = this.WarningValue, Category = SelectedCounter != null ? SelectedCounter.CategoryName : "", Instance = SelectedCounter != null ? SelectedCounter.InstanceName : "", Counter = SelectedCounter != null ? SelectedCounter.CounterName : "" }; return pc; }
public static PerfCounter Read(BinaryReader reader) { PerfCounter result = new PerfCounter(); result.CounterId = Utilities.Read7BitEncodedInt(reader); result.TimeStamp = Utilities.Read7BitEncodedInt64(reader); result.Value = reader.ReadDouble(); return result; }
private void AddButton_Click(object sender, RoutedEventArgs e) { CounterEditor w = new CounterEditor(); PerfCounter c = new PerfCounter { Duration = 5 }; w.ViewModel.SetPerfCounter(c); if (w.ShowDialog() == true) { PerfCounter nc = w.ViewModel.GetPerfCounter(); this.Counters.Add(nc); this.countersGrid.SelectedItem = nc; } }
public void SetPerfCounter(PerfCounter val) { if (string.IsNullOrEmpty(val.Category) == false) this.SelectedCategory = Categories.Single(x => x.CategoryName == val.Category); if (string.IsNullOrEmpty(val.Instance) == false) this.SelectedInstance = val.Instance; if (string.IsNullOrEmpty(val.Counter) == false) this.SelectedCounter = Counters.Single(x => x.CounterName == val.Counter); this.Duration = val.Duration; this.CalcMethod = val.CalcMethod; this.Command = val.Command; this.CriticalMethod = val.CriticalMethod; this.CriticalValue = val.CriticalValue; this.WarningMethod = val.WarningMethod; this.WarningValue = val.WarningValue; }