Beispiel #1
0
        static void Main(string[] args)
        {
            var db1Metrics = new MetricRegistry();
            var reporter   = ConsoleReporter.ForRegistry(db1Metrics).build();
            var meter      = db1Metrics.Meter("testMeter");
            var randomHist = db1Metrics.Histogram("testHist");
            //var machineMetrics = MachineMetrics.Create(MachineMetricsCategory.All);
            //db1Metrics.Register("MachineMetrics", machineMetrics);

            //reporter.Start(1, TimeUnit.Seconds);
            CsvReporter creporter = CsvReporter.forRegistry(db1Metrics).build("c:\\merchlog");
            //creporter.Start(1, TimeUnit.Seconds);

            Graphite         sender    = new Graphite("ttolley-lap3", 2003);
            GraphiteReporter greporter = GraphiteReporter.ForRegistry(db1Metrics).Build(sender);

            greporter.Start(10, TimeUnit.Seconds);



            //var docsTimedCounterPerSec = db1Metrics.TimedCounter("db1", "docs new indexed/sec", "new Indexed Documents");
            int i = 0;

            db1Metrics.Gauge <int>("testGauge", () => i);
            Random r       = new Random();
            var    counter = db1Metrics.Counter("testCounter");

            for (; i < 10000; i++)
            {
                meter.Mark();
                counter.Increment(i);
                randomHist.Update(r.Next(101));
                Thread.Sleep(100);
            }
            Console.WriteLine("Done counting");
            for (i = 0; i < 10; i++)
            {
                Thread.Sleep(60000);
            }


            //Console.WriteLine(docsTimedCounterPerSec.CurrentValue);

            /*var RequestsPerSecondHistogram = db1Metrics.Histogram("db1.Request Per Second Histogram");
             * for (int i = 0; i < 100; i++)
             * {
             *  RequestsPerSecondCounter.Mark();
             *  RequestsPerSecondHistogram.Update((long)RequestsPerSecondCounter.CurrentValue);
             *  Thread.Sleep(10);
             * }
             * StringBuilder sb = new StringBuilder();
             * double[] res;
             * var perc = RequestsPerSecondHistogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999);
             * res = perc;
             * RequestsPerSecondHistogram.LogJson(sb,perc);
             * Console.WriteLine(sb);
             * Console.WriteLine(RequestsPerSecondHistogram.Percentiles(0.5, 0.75, 0.95, 0.98, 0.99, 0.999));
             * // RequestsPerSecondHistogram.Update((long)documentDatabase.WorkContext.MetricsCounters.RequestsPerSecondCounter.CurrentValue); //??
             */
        }
        // Returns source code of a demo file
        public static string GetSourceCode(string suffix, bool dicFiles, int intActiveIndex, string path, Graphite.Internal.Config config)
        {
            string strFileName = "default";
            if (dicFiles == false)
            {
                int intMenuItemActive = intActiveIndex;
                strFileName = config.Type(intMenuItemActive);
            }

            string strRoot = HttpContext.Current.Server.MapPath(path) + "\\";
            StringBuilder sbCode = new StringBuilder();

            try
            {
                System.IO.StreamReader sr = new System.IO.StreamReader(strRoot + strFileName + suffix);
                string line;

                while (sr.Peek() != -1)
                {
                    line = sr.ReadLine();
                    sbCode.AppendLine(line);
                }

                sr.Close();
                sr.Dispose();
            }
            catch (Exception exp)
            {
                //
            }
            return sbCode.ToString();
        }
Beispiel #3
0
        public override void Init()
        {
            // Setup Graphite reporting
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.codahale.metrics.graphite.Graphite graphite = new com.codahale.metrics.graphite.Graphite(hostnamePort.getHost(), hostnamePort.getPort());
            Graphite graphite = new Graphite(_hostnamePort.Host, _hostnamePort.Port);

            _graphiteReporter = GraphiteReporter.forRegistry(_registry).prefixedWith(_prefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite);
        }
Beispiel #4
0
        public void FailingSend_ThrowsException()
        {
            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <double>())).Throws <Exception>();
            var graphite = new Graphite(_log, _settings, mockClient.Object);

            Assert.Throws <Exception>(() => { graphite.Send("test", 1); });
        }
Beispiel #5
0
        public void Send_Datapoint_Works()
        {
            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <Datapoint[]>()));
            _settings.ThrowExceptions = true;
            var graphite = new Graphite(_log, _settings, mockClient.Object);

            Assert.DoesNotThrow(() => { graphite.Send(new Datapoint("test", 1, DateTime.UtcNow)); });
        }
Beispiel #6
0
        public void Send_Works()
        {
            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <double>()));
            _settings.ThrowExceptions = true;
            var graphite = new Graphite(_log, _settings, mockClient.Object);

            Assert.DoesNotThrow(() => { graphite.Send("test", 1); });
        }
Beispiel #7
0
        public ShapeSelector(Graphite.Shapes.Manager shapeMan)
        {
            _shapeMan = shapeMan;

            foreach (Graphite.Core.Shape sh in _shapeMan.Shapes)
                Items.Add (sh.name ());

            DropDownStyle = ComboBoxStyle.DropDownList;
            SelectedIndex = 0;
        }
Beispiel #8
0
        public void NullHost_ThrowsException()
        {
            _settings.ThrowExceptions = true;
            _settings.Host            = null;
            var cakeLog = new FakeLog();

            Assert.Throws <ArgumentNullException>(() =>
            {
                _graphite = new Graphite(cakeLog, _settings);
            });
        }
Beispiel #9
0
        public void Setup()
        {
            _settings = new GraphiteSettings()
            {
                Host            = "192.0.2.0",
                HttpApiPort     = 10,
                BatchSize       = 500,
                ThrowExceptions = true
            };
            var cakeLog = new FakeLog();

            _graphite = new Graphite(cakeLog, _settings);
        }
        public static string GetCodeBehind(string ascxSource, string cssClass, string path, Graphite.Internal.Config config, int activeIndex)
        {
            string strCode = "";

            // Get URL to Codebehind
            string strCodeBehindURL = "";
            int intCodeFileStart = ascxSource.IndexOf("CodeFile=", StringComparison.OrdinalIgnoreCase);
            int intIgnoreCodeFile = ascxSource.IndexOf("<!-- Graphite: Ignore Codefile -->", StringComparison.OrdinalIgnoreCase);
            int intStartQuote = ascxSource.IndexOf("\"", intCodeFileStart);
            int intEndQuote = ascxSource.IndexOf("\"", (intStartQuote + 1));
            if (intStartQuote >= 0)
            {
                strCodeBehindURL = ascxSource.Substring((intStartQuote + 1), (intEndQuote - intStartQuote - 1));
            }

            string strRoot = HttpContext.Current.Server.MapPath(path) + "\\";

            if (intIgnoreCodeFile >= 0)
            {
                // Get Codebehind code
                try
                {
                    StringBuilder sbCode = new StringBuilder();
                    System.IO.StreamReader sr = new System.IO.StreamReader(strRoot + strCodeBehindURL);

                    while (sr.Peek() != -1)
                    {
                        string line = sr.ReadLine();
                        sbCode.AppendLine(line);
                    }
                    sr.Close();
                    sr.Dispose();

                    strCode = sbCode.ToString();

                    // Insert class into private variable _strRootClass
                    int rootClassStart = strCode.IndexOf("_strRootClass", StringComparison.OrdinalIgnoreCase);
                    int rootClassValueStart = strCode.IndexOf("\"\"", rootClassStart);
                    strCode = strCode.Insert(rootClassValueStart + 1, config.CssClass(activeIndex));
                }
                catch (Exception exp)
                {
                    // No Codebehind available
                }
            }
            return strCode;
        }
Beispiel #11
0
        public static void Main(string[] args)
        {
            Console.WriteLine(typeof(Exception).IsAssignableFrom(typeof(ArgumentNullException)));
            Console.WriteLine(typeof(ArgumentNullException).IsAssignableFrom(typeof(Exception)));


            IKernel        kernel   = new StandardKernel();
            MetricRegistry registry = new MetricRegistry();

            kernel.Bind <MetricRegistry>().ToConstant <MetricRegistry>(registry);


            Tryout          t        = kernel.Get <Tryout>();
            ConsoleReporter reporter = ConsoleReporter.ForRegistry(registry).build();

            reporter.Start(1, TimeUnit.Seconds);

            Graphite         sender    = new Graphite("ttolley-lap3", 2003);
            GraphiteReporter greporter = GraphiteReporter.ForRegistry(registry).Build(sender);

            greporter.Start(10, TimeUnit.Seconds);

            int    i = 0;
            Random r = new Random();

            for (; i < 10000; i++)
            {
                try {
                    t.Test(r.Next(101));
                }
                catch
                {
                    // Do nothing
                }
            }

            Console.WriteLine("Done counting");
            for (i = 0; i < 10; i++)
            {
                Thread.Sleep(60000);
            }
        }
Beispiel #12
0
        public void SendingWithPrefix_Works()
        {
            const string prefix         = "prefix_test";
            const string testMetricName = "test";
            string       returnValue    = null;
            var          expectedName   = $"{prefix}.{testMetricName}";

            _settings.Prefix = prefix;

            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <string>(), It.IsAny <double>()))
            .Callback((string metricName, double value) => { returnValue = metricName; });

            var graphite = new Graphite(_log, _settings, mockClient.Object);

            graphite.Send(testMetricName, 1);

            Assert.IsNotNull(returnValue);
            Assert.AreEqual(returnValue, expectedName);
        }
Beispiel #13
0
        public void SendingDatapointWithPrefix_Works()
        {
            const string prefix         = "prefix_test";
            const string testMetricName = "test";
            string       returnValue    = null;
            var          expectedName   = $"{prefix}.{testMetricName}";

            _settings.Prefix = prefix;

            var mockClient = new Mock <IGraphiteClient>();

            mockClient.Setup(x => x.Send(It.IsAny <ICollection <Datapoint> >()))
            .Callback((ICollection <Datapoint> x) => { returnValue = x.First().Series; });
            mockClient.Setup(x => x.Send(It.IsAny <Datapoint>()))
            .Callback((Datapoint[] x) => { returnValue = x[0].Series; });

            var graphite = new Graphite(_log, _settings, mockClient.Object);

            graphite.Send(new Datapoint(testMetricName, 1, DateTime.Now));

            Assert.IsNotNull(returnValue);
            Assert.AreEqual(expectedName, returnValue);
        }
Beispiel #14
0
 public Idle(Graphite.Core.Document doc, Graphite.Core.IUISet ui)
     : base(doc, ui)
 {
 }
Beispiel #15
0
 public Edge(Graphite.Core.Edge edge)
 {
     _assignedEdge = edge;
 }
Beispiel #16
0
 public void VertexRemoved(Graphite.Core.Vertex v)
 {
     var element = _vertexVisuals.First (x => x.AssignedTo == v);
     _vertexVisuals.Remove (element);
     Refresh ();
 }
Beispiel #17
0
 public void VertexDisconnected(Graphite.Core.Vertex a, Graphite.Core.Vertex b)
 {
     UpdateEdges ();
     Refresh ();
 }
Beispiel #18
0
 public void VertexAdded(Graphite.Core.Vertex v)
 {
     _vertexVisuals.Add (new Graphite.Scene.Elements.Vertex (v));
     Refresh ();
 }
Beispiel #19
0
 public System.Drawing.Color Color(Graphite.Scene.Elements.Vertex v)
 {
     if (v.Marked)
         return System.Drawing.Color.Red;
     else
         return (v.Selected ? SystemColors.Highlight : System.Drawing.Color.Black);
 }
Beispiel #20
0
 public State(Graphite.Core.Document doc, Graphite.Core.IUISet ui)
 {
     _document = doc;
     _ui = ui;
 }
Beispiel #21
0
 public Deleting(Graphite.Core.Document doc, Graphite.Core.IUISet ui)
     : base(doc, ui)
 {
 }
Beispiel #22
0
 public Disconnecting(Graphite.Core.Document doc, Graphite.Core.IUISet ui)
     : base(doc, ui)
 {
 }
Beispiel #23
0
 protected void RenderId(Graphite.Scene.Elements.Vertex v, Graphics g)
 {
     var text = v.AssignedTo.Id.ToString ();
     TextRenderer.DrawText (g, text, Font,
                            boundingBox(v), Color (v),
                            TextFormatFlags.HorizontalCenter |
                            TextFormatFlags.VerticalCenter);
 }
Beispiel #24
0
 protected virtual Rectangle boundingBox(Graphite.Scene.Elements.Vertex v)
 {
     var vertex = (v as Graphite.Scene.Elements.Vertex).AssignedTo;
     return Graphite.Math.Geom.Square (vertex.Position, radius);
 }
Beispiel #25
0
 public Vertex(Graphite.Core.Vertex vertex)
 {
     _assignedVertex = vertex;
 }
Beispiel #26
0
 protected override Rectangle boundingBox(Graphite.Scene.Elements.Vertex v)
 {
     var r = base.boundingBox (v);
     r.Offset (0, radius / 3);
     return r;
 }