Ejemplo n.º 1
0
        public void Threshold_is_set_as_label()
        {
            timer = OkanshiMonitor.SlaTimer("name", TimeSpan.FromSeconds(2));
            var thresholdTag = timer.Config.Tags.Single(x => x.Key == SlaTimer.ThresholdKey).Value;

            thresholdTag.Should().Be("2000");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invoke the middleware.
        /// </summary>
        public async Task Invoke(IDictionary <string, object> environment)
        {
            long elapsed = 0;
            var  timer   = OkanshiTimer.StartNew(x => elapsed = x);
            await next.Invoke(environment);

            timer.Stop();
            var tags = EmptyTagList;

            if (options.AddStatusCodeTag)
            {
                object responseCode;
                var    found = environment.TryGetValue("owin.ResponseStatusCode", out responseCode);
                if (found)
                {
                    tags.Add(new Tag("responseCode", responseCode.ToString()));
                }
            }

            tags.Add(new Tag("path", environment["owin.RequestPath"].ToString()));
            tags.Add(new Tag("method", environment["owin.RequestMethod"].ToString()));
            var basicTimer = OkanshiMonitor.BasicTimer(options.MetricName, tags.ToArray());

            basicTimer.Register(elapsed);
        }
Ejemplo n.º 3
0
        public void Okanshimonitor_integration_returns_fresh_instance()
        {
            var monitor = OkanshiMonitor.MinMaxAvgGauge("Foo");

            monitor.Config.Name.Should().Be("Foo");
            monitor.GetValues().Select(x => x.ToString()).Should().BeEquivalentTo("min:0", "max:0", "avg:0");
        }
Ejemplo n.º 4
0
        // The point of this sample to is to showcase the use of the HTTP endpoint
        static void Main(string[] args)
        {
            // Get the default registry instance. This is the registry used when adding metrics
            // through OkanshiMonitor.
            var registry = DefaultMonitorRegistry.Instance;
            var poller   = new MetricMonitorRegistryPoller(registry, TimeSpan.FromMinutes(1));

            // Create a HTTP endpoint, this listens on the default registry instance, gets the values
            // every 10 seconds and keeps the last 100 samples in memory
            var httpEndpoint = new MonitorEndpoint(new EndpointOptions {
                NumberOfSamplesToStore = 100,
            }, poller, o => JsonConvert.SerializeObject(o, Formatting.Indented));

            httpEndpoint.Start();

            while (true)
            {
                Console.WriteLine("Monitor key presses. Start typing to measure");
                while (true)
                {
                    var    info = Console.ReadKey();
                    string measurementName;
                    if ((int)info.Modifiers == 0)
                    {
                        measurementName = info.Key.ToString();
                    }
                    else
                    {
                        measurementName = $"{info.Modifiers} + {info.Key}";
                    }
                    System.Console.WriteLine();
                    OkanshiMonitor.Counter("Key press", new[] { new Tag("combination", measurementName) }).Increment();
                }
            }
        }
Ejemplo n.º 5
0
        public static void Start()
        {
            Console.WriteLine("Enter 10 numbers");
            var count = 0;

            while (count < 10)
            {
                // Time how long the user takes to enter input.
                var value = OkanshiMonitor.Timer("TimeToEnterInput").Record(() => {
                    Console.Write("Enter an integer: ");
                    return(Console.ReadLine());
                });

                int result;
                if (!Int32.TryParse(value, out result))
                {
                    Console.WriteLine("Invalid number, try again...");
                    // Count the number of invalids numbers, using a tag to indicate that the
                    // number was invalid
                    OkanshiMonitor.Counter("Numbers", new[] { new Tag("state", "Invalid") }).Increment();
                    continue;
                }

                // Count the number of valids numbers, using a tag to indicate that the
                // number was valid
                OkanshiMonitor.Counter("Numbers", new[] { new Tag("state", "Valid") }).Increment();

                // Calculate the average value of the numbers
                OkanshiMonitor.AverageGauge("AverageNumber").Set(result);

                // Calculate the minimum value of the numbers
                OkanshiMonitor.MinGauge("MinimumNumber").Set(result);

                // Calculate the maximum value of the numbers
                OkanshiMonitor.MaxGauge("MaximumNumber").Set(result);
                count++;
            }
        }
Ejemplo n.º 6
0
 public void Can_get_timer_from_okanshimonitor()
 {
     timer = OkanshiMonitor.SlaTimer("name", TimeSpan.FromSeconds(2));
     timer.Should().NotBeNull();
 }
Ejemplo n.º 7
0
        public void Okanshimonitor_can_create_instance_with_tags()
        {
            PerformanceCounterMonitor p = OkanshiMonitor.PerformanceCounter(PerformanceCounterConfig.Build("Memory", "Available Bytes"), "name", new[] { new Tag("a", "b") });

            p.Should().NotBeNull();
        }
Ejemplo n.º 8
0
        public void Okanshimonitor_can_create_instance()
        {
            PerformanceCounterMonitor p = OkanshiMonitor.PerformanceCounter(PerformanceCounterConfig.Build("Memory", "Available Bytes"), "name");

            p.Should().NotBeNull();
        }
Ejemplo n.º 9
0
 public void Asking_for_monitor_with_same_names_always_return_same_monitor()
 {
     OkanshiMonitor.BasicTimer("Test").Should().BeSameAs(OkanshiMonitor.BasicTimer("Test"));
 }
Ejemplo n.º 10
0
 public void Asking_for_monitor_with_same_names_but_different_tags_returns_different_monitor()
 {
     OkanshiMonitor.BasicTimer("Test", new[] { new Tag("tag", "value") })
     .Should()
     .NotBeSameAs(OkanshiMonitor.BasicTimer("Test", new[] { new Tag("tag2", "value") }));
 }
Ejemplo n.º 11
0
        public void Asking_for_monitor_with_same_names_and_tags_returns_same_monitor()
        {
            var tag = new Tag("tag", "value");

            OkanshiMonitor.BasicTimer("Test", new[] { tag }).Should().BeSameAs(OkanshiMonitor.BasicTimer("Test", new[] { tag }));
        }
Ejemplo n.º 12
0
        public void Asking_for_monitor_with_different_names_but_same_tags_returns_different_monitors()
        {
            var tag = new Tag("tag", "value");

            OkanshiMonitor.BasicTimer("Test", new[] { tag }).Should().NotBeSameAs(OkanshiMonitor.BasicTimer("Test2", new[] { tag }));
        }
Ejemplo n.º 13
0
 public void Asking_for_monitor_with_different_names_returns_different_monitors()
 {
     OkanshiMonitor.BasicTimer("Test").Should().NotBeSameAs(OkanshiMonitor.BasicTimer("Test2"));
 }
Ejemplo n.º 14
0
 public int RegisterFuncUsingTimerFromRegistryWithTags() => OkanshiMonitor
 .Timer("RegisterFuncUsingTimerFromRegistryWithTags", new[] { new Tag("key", "val"), new Tag("Environment", "production"), new Tag("Tic", "Tac") })
 .Record(() => 1);
Ejemplo n.º 15
0
 public int RegisterFuncUsingTimerFromRegistry() => OkanshiMonitor.Timer("RegisterFuncUsingTimerFromRegistry").Record(() => 1);
Ejemplo n.º 16
0
 public void Setup()
 {
     OkanshiMonitor.Timer("RegisterFuncUsingTimerFromRegistry");
     OkanshiMonitor.Timer("RegisterFuncUsingTimerFromRegistryWithTags",
                          new[] { new Tag("key", "val"), new Tag("Environment", "production"), new Tag("Tic", "Tac") });
 }