예제 #1
0
        static void Main(string[] args)
        {
            try
            {
                var correlationId = "123";
                var config        = ConfigParams.FromTuples(
                    "connection.type", "http",
                    "connection.host", "localhost",
                    "connection.port", 8080
                    );
                var client = new PerfMonHttpClientV1();
                client.Configure(config);
                CounterV1 counter1 = new CounterV1("counter1", "source1", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);
                CounterV1 counter2 = new CounterV1("counter2", "source2", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);
                client.OpenAsync(correlationId);
                //var counter = client.WriteCounterAsync(correlationId, counter1);
                client.WriteCountersAsync(null, new CounterV1[] { counter1, counter2 });
                var page = client.ReadCountersAsync(null, FilterParams.FromTuples("name", "counter1"), null);
                Console.WriteLine("Read counters: ");

                Console.WriteLine("Press ENTER to exit...");
                Console.ReadLine();

                client.CloseAsync(string.Empty);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        public async Task TestCrudOperationsAsync()
        {
            CounterV1 counter = new CounterV1("counter1", "source1", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);

            counter.Count   = 1;
            counter.Max     = 10;
            counter.Min     = 1;
            counter.Average = 5;

            var test_counter = await this._client.WriteCounterAsync(null, counter);

            Assert.NotNull(test_counter);

            CounterV1 counter1 = new CounterV1("counter1", "source1", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);

            counter1.Count   = 2;
            counter1.Max     = 7;
            counter1.Min     = 0;
            counter1.Average = 5;

            CounterV1 counter2 = new CounterV1("counter2", "source2", CounterTypeV1.Statistics, 5, 2, 2, 5, 3.5);

            counter2.Count = 1;

            await this._client.WriteCountersAsync(null, new CounterV1[] { counter1, counter2 });

            var page = await this._client.ReadCountersAsync(null, FilterParams.FromTuples("name", "counter1"), null);

            Assert.Single(page.Data);

            var new_counter = page.Data[0];

            Assert.Equal(3, new_counter.Count);
            Assert.Equal(0, new_counter.Min);
            Assert.Equal(10, new_counter.Max);
            Assert.Equal(5, new_counter.Average);
        }