//Rule signing code, don't modify:0544BCE9DB946675 using System; using Perytons.Analyzer.Core; using System.Collections.Generic; using System.Drawing; using Perytons.Analyzer.Core.Graphs; using ZedGraph; namespace Perytons.Analyzer.Core.Monitoring { // This is an example for a rule that public class AckLatency : RuleBase { Dictionary MessageTime = new Dictionary();// will hold a list of messages that expect ack // ack time latency histogram int AckMessageCount = 0; double[] AckHistogram = new double[200]; BarGraphData barGraph; // init chart properties (line thickness, symbol properties etc.) public AckLatency(GraphBuilder builder) : base(builder) { barGraph = new BarGraphData(); barGraph.Title = "Ack latency histogram"; barGraph.XLabel = "Time (msec)"; barGraph.YLabel = "% of messages"; barGraph.GraphType = GraphType.XY; barGraph.Symbols = new SymbolType[] { SymbolType.None }; barGraph.LineThickness = new int[] { 2 }; builder.Add(barGraph); } // this method is called per every received message public override void DoRule(Packet packet) { packet.AddToTimeView(); // add this message to time view if (packet.Field("InfoRelatedMessagesAckAt").Exist)// this packet expects ack, and ack message was found { MessageTime[(int)packet.Field("InfoRelatedMessagesAckAt").Value] = packet.Field("InfoStartTime").Value;//add message to list packet.AddToTimeView(Color.Blue); // add this message to time view } else if (packet.Field("InfoRelatedMessagesAckTo").Exist) // this is an ack message { packet.AddToTimeView(Color.Pink); // add this message to time view long time = packet.Field("InfoStartTime").Value; if (MessageTime.ContainsKey(packet.Index)) // find original message in the list { double timeDiff = ((double)(time - MessageTime[packet.Index])) / 1000;//msec if ((timeDiff > 0) && (timeDiff < 20)) { AckHistogram[(int)(timeDiff * 10)]++; AckMessageCount++; } if (timeDiff > 10.0) // more than 10msec { packet.AddToMessageView();// add this message to message view // issue an event, severity "info" //log4net.LogManager.GetLogger("EventsLogger").Info("Long ack latency, Message#" + packet.Index + " " + timeDiff + "msec"); packet.AddToTimeView(Color.Black); Loggers.EventsLogger.Info("Long ack latency, Message#" + packet.Index + " " + timeDiff + "msec"); } } } base.DoRule(packet); } // this is called when statistics charts are built public override void Process() { // build chart if (AckMessageCount > 0) { double[] xValues = new double[200]; double[] values = new double[200]; for (int i = 0; i < 200; i++) { xValues[i] = (double)i / 10.0; values[i] = 100.0 * AckHistogram[i] / AckMessageCount; } // build chart barGraph.X_values = xValues; barGraph.ScalarValues = values; } base.Process(); } } }