Esempio n. 1
0
        static void Main(string[] args)
        {
            var gw = new PushGateway();

            // Windows 8
            gw.Register(Platform.Windows, "https://bn1.notify.windows.com/?token=AgYAAAAmTOnAWNOSj5kPueLw54fLzVxtM27mSHwB79Obk%2fjv03e9MvnW0ZbR4eGdY4LoevOGJn8mmwNX2oLB2QHCxuUdmQ2SOQOCJWVaHS9Y6aHyPJt%2b2uvF%2f88WmzauL3hSkEM%3d", "all");
            var wNote = new PushNotification <WindowsPayload>();

            wNote.Payload.SetToast("Hello World");
            wNote.Tokens.Add("https://bn1.notify.windows.com/?token=AgYAAAAmTOnAWNOSj5kPueLw54fLzVxtM27mSHwB79Obk%2fjv03e9MvnW0ZbR4eGdY4LoevOGJn8mmwNX2oLB2QHCxuUdmQ2SOQOCJWVaHS9Y6aHyPJt%2b2uvF%2f88WmzauL3hSkEM%3d");
            gw.Send(wNote);

            // Android
            var aNote = new PushNotification <AndroidPayload>();

            aNote.Payload.Data.Add("message", "TEST4");
            aNote.Segments.Add("all");
            var res = gw.Send(aNote);

            Console.WriteLine(res.Count);

            // Windows Phone - Toast Message
            var wpNote = new PushNotification <WindowsPhonePayload>();

            wpNote.Segments.Add("all");
            wpNote.Payload.SetToast("Hello World!", "");
            gw.Send(wpNote);


            // Windows Phone - Tile Message
            var wpNote = new PushNotification <WindowsPhonePayload>();

            wpNote.Segments.Add("all");
            //wpNote.Payload.SetTile(9, "Kittens!", "", "", "http://placekitten.com/480/480");
            wpNote.Payload.SetTile(9, "Kittens!", "", "", "http://lorempixel.com/173/173/city");
            gw.Send(wpNote);


            // iOS - Alert
            gw.Register(Platform.iOS, "8B4AEB7E108BA1C4681520BF074F9ABB0AF9A26A2D9F5712D31B5B0B4B5BE1A3", "all", "ipods");
            var iosNote = new PushNotification <IosPayload>();

            iosNote.Segments.Add("all");
            iosNote.Payload.SetAlert("Hello World!");
            var res = gw.Send(iosNote);

            Console.WriteLine(res.Success);
            Console.WriteLine(res.Count);

            // iOS - badge # update
            var iosNote = new PushNotification <IosPayload>();

            iosNote.Segments.Add("all");
            //iosNote.Payload.SetBadge(0);
            iosNote.Payload.SetBadge(3);
            gw.Send(iosNote);
        }
        public void Passing_null_to_PushAsync_throws_ArgumentNullException()
        {
            var mh = new FakeMessageHandler();

            using (var pushgateway = new PushGateway(new HttpClient(mh)
            {
                BaseAddress = new Uri("http://example.com/")
            }))
            {
                var m = new PrometheusMetrics();

                Assert.ThrowsAsync <ArgumentNullException>(() => pushgateway.PushAsync(null, "jobname"));
                Assert.ThrowsAsync <ArgumentNullException>(() => pushgateway.PushAsync(m, null));
            }
        }
        public async Task Exposing_a_metric_includes_custom_metrics_without_timestamp()
        {
            var mh = new FakeMessageHandler();

            using (var pgw = new PushGateway(new HttpClient(mh)
            {
                BaseAddress = new Uri("http://example.com/")
            }))
            {
                var m = new PrometheusMetrics();
                var c = m.Counter().Name("test_counter").Help("This is the help text").Register();

                c.Increment();

                await pgw.PushAsync(m, "exampleapp");

                mh.Content.Should().Contain("# HELP test_counter This is the help text\n");
                mh.Content.Should().Contain("test_counter 1\n");
            }
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            IMetrics metrics = new PrometheusMetrics();

            var planningTime = metrics.Gauge()
                               .Name("planning_time").Help("The processing time in seconds").LabelNames("solver").Register();

            var planningCount = metrics.Counter()
                                .Name("planning_count").Help("The count of planning").LabelNames("solver").Register();

            var totalPlanningCount = metrics.Counter()
                                     .Name("plannning_count_total").Help("Total count of plannings").Register();

            var totalRunning = metrics.Gauge()
                               .Name("plannning_running_total").Help("Currently running plannings").Register();

            var planningStartTime = metrics.Gauge()
                                    .Name("planning_start_time").Help("Start time of last planning").Register();

            var planningTimeHistogram = metrics.Histogram()
                                        .LinearBuckets(0, 300, 10)
                                        .Name("planning_duration_times")
                                        .Help("Duration of plannings in ms")
                                        .Register();

            var planningTimeHistogramForSolver = metrics.Histogram()
                                                 .LinearBuckets(0, 300, 10)
                                                 .Name("planning_duration_times_for_solver")
                                                 .Help("Duration of plannings in ms for different solvers")
                                                 .LabelNames("solver")
                                                 .Register();


            var pgw = new PushGateway(
                new Uri("http://127.0.0.1:9091"),
                "example_app",
                new List <Tuple <string, string> > {
                Tuple.Create("environment", "test")
            }
                );

            Task.Run(async() =>
            {
                var pm     = metrics as PrometheusMetrics;
                var output = Console.OpenStandardOutput();

                for (;;)
                {
                    Console.WriteLine("# Waiting");
                    await Task.Delay(TimeSpan.FromSeconds(10));
                    Console.WriteLine("# Exposing");
                    await pm.Expose(output);
                    Console.WriteLine("# Done");

                    try
                    {
                        await pgw.PushAsync(pm, "example_app:9000");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            });

            foreach (var solver in new[] { "Static", "Dynamic" })
            {
                Task.Run(() =>
                {
                    var rnd = new Random(solver.GetHashCode());

                    for (;;)
                    {
                        using (planningTime.Labels(solver).Timer())
                        {
                            totalPlanningCount.Increment();
                            planningCount.Labels(solver).Increment();

                            planningStartTime.SetToCurrentTime();

                            totalRunning.TrackInProgress(() =>
                            {
                                var planningSleep = rnd.Next(5000);
                                Thread.Sleep(planningSleep);
                                planningTimeHistogram.Observe(planningSleep);
                                planningTimeHistogramForSolver.Labels(solver).Observe(planningSleep);
                            });
                        }
                    }
                });
            }

            Console.ReadLine();
        }