Пример #1
0
        public void MultiIncrement_Exec_SourceInstance()
        {
            var counters = new List <Counter>
            {
                new Counter("MyService1.MyCommand1.exec_time", CounterType.Increment)
                {
                    Count = 2,
                    Last  = 3,
                    Time  = DateTime.MinValue
                },
                new Counter("MyService2.MyCommand2.exec_time", CounterType.Increment)
                {
                    Count = 5,
                    Last  = 10,
                    Time  = DateTime.MinValue
                }
            };
            var          body     = PrometheusCounterConverter.ToString(counters, "MyApp", "MyInstance");
            const string expected = "# TYPE exec_time gauge\nexec_time{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService1\",command=\"MyCommand1\"} 2\n"
                                    + "# TYPE exec_time gauge\nexec_time{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService2\",command=\"MyCommand2\"} 5\n";

            Assert.Equal(expected, body);
        }
Пример #2
0
        public void MultiIncrement_ExecWithOnlyTwo_SourceInstance()
        {
            var counters = new List <Counter>
            {
                new Counter("MyCounter1.exec_time", CounterType.Increment)
                {
                    Count = 2,
                    Last  = 3,
                    Time  = DateTime.MinValue
                },
                new Counter("MyCounter2.exec_time", CounterType.Increment)
                {
                    Count = 5,
                    Last  = 10,
                    Time  = DateTime.MinValue
                }
            };
            var          body     = PrometheusCounterConverter.ToString(counters, "MyApp", "MyInstance");
            const string expected = "# TYPE mycounter1_exec_time gauge\nmycounter1_exec_time{source=\"MyApp\",instance=\"MyInstance\"} 2\n"
                                    + "# TYPE mycounter2_exec_time gauge\nmycounter2_exec_time{source=\"MyApp\",instance=\"MyInstance\"} 5\n";

            Assert.Equal(expected, body);
        }
        public void MultiStatistics_Exec_SourceInstance()
        {
            var counters = new List <Counter>
            {
                new Counter("MyService1.MyCommand1.exec_time", CounterType.Statistics)
                {
                    Min     = 1,
                    Max     = 3,
                    Average = 2,
                    Count   = 2,
                    Last    = 3,
                    Time    = DateTime.MinValue
                },
                new Counter("MyService2.MyCommand2.exec_time", CounterType.Statistics)
                {
                    Min     = 2,
                    Max     = 4,
                    Average = 3,
                    Count   = 5,
                    Last    = 10,
                    Time    = DateTime.MinValue
                }
            };
            var body = PrometheusCounterConverter.ToString(counters, "MyApp", "MyInstance");

            const string expected =
                "# TYPE exec_time_max gauge\nexec_time_max{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService1\",command=\"MyCommand1\"} 3\n"
                + "# TYPE exec_time_min gauge\nexec_time_min{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService1\",command=\"MyCommand1\"} 1\n"
                + "# TYPE exec_time_average gauge\nexec_time_average{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService1\",command=\"MyCommand1\"} 2\n"
                + "# TYPE exec_time_count gauge\nexec_time_count{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService1\",command=\"MyCommand1\"} 2\n"
                + "# TYPE exec_time_max gauge\nexec_time_max{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService2\",command=\"MyCommand2\"} 4\n"
                + "# TYPE exec_time_min gauge\nexec_time_min{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService2\",command=\"MyCommand2\"} 2\n"
                + "# TYPE exec_time_average gauge\nexec_time_average{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService2\",command=\"MyCommand2\"} 3\n"
                + "# TYPE exec_time_count gauge\nexec_time_count{source=\"MyApp\",instance=\"MyInstance\",service=\"MyService2\",command=\"MyCommand2\"} 5\n";

            Assert.Equal(expected, body);
        }
Пример #4
0
        public void KnownCounter_Exec_QueueMetrics_Good(string counterName, string expectedName)
        {
            var counters = new List <Counter>
            {
                new Counter(counterName, CounterType.Increment)
                {
                    Count = 1, Time = DateTime.MinValue
                },
                new Counter(counterName, CounterType.Interval)
                {
                    Count = 11, Max = 13, Min = 3, Average = 3.5, Time = DateTime.MinValue
                },
                new Counter(counterName, CounterType.LastValue)
                {
                    Last = 2, Time = DateTime.MinValue
                },
                new Counter(counterName, CounterType.Statistics)
                {
                    Count = 111, Max = 113, Min = 13, Average = 13.5, Time = DateTime.MinValue
                }
            };

            var body = PrometheusCounterConverter.ToString(counters, "MyApp", "MyInstance");

            var expected = $"# TYPE {expectedName} gauge\n{expectedName}{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 1\n"
                           + $"# TYPE {expectedName}_max gauge\n{expectedName}_max{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 13\n"
                           + $"# TYPE {expectedName}_min gauge\n{expectedName}_min{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 3\n"
                           + $"# TYPE {expectedName}_average gauge\n{expectedName}_average{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 3.5\n"
                           + $"# TYPE {expectedName}_count gauge\n{expectedName}_count{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 11\n"
                           + $"# TYPE {expectedName} gauge\n{expectedName}{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 2\n"
                           + $"# TYPE {expectedName}_max gauge\n{expectedName}_max{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 113\n"
                           + $"# TYPE {expectedName}_min gauge\n{expectedName}_min{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 13\n"
                           + $"# TYPE {expectedName}_average gauge\n{expectedName}_average{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 13.5\n"
                           + $"# TYPE {expectedName}_count gauge\n{expectedName}_count{{source=\"MyApp\",instance=\"MyInstance\",queue=\"default\"}} 111\n";

            Assert.Equal(expected, body);
        }
        public void NullValues()
        {
            var body = PrometheusCounterConverter.ToString(null, null, null);

            Assert.Equal(string.Empty, body);
        }