示例#1
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            AppDomain.CurrentDomain.ProcessExit += StaticClass_Dtor;

            services = new Services(new ScreenshotService("screens"));

            //for (int i = 0; i < 50; i++)
            //{
            //    var text = await services.AccessPage("https://blog.umbler.com/br");
            //    Console.WriteLine(text);
            //}

            foreach (var domain in Domains)
            {
                //var text = await services.AccessPage(domain.NormalizeUrl());
                var text = await services.AccessPageAndGetResourcesFull(domain.NormalizeUrl(), false, true, false, false, false);

                Console.WriteLine($"{domain,50} | {text.SiteStatus}");
            }

            Console.WriteLine("FIM");
            var tabs = await services.GetTabsAsync();

            if (tabs != null)
            {
                Console.WriteLine("Tabs remaining: " + tabs.Length);
                foreach (var tab in tabs)
                {
                    Console.WriteLine(tab.Url);
                }
            }
            Console.ReadKey();
        }
示例#2
0
        public async Task <IActionResult> IndexAsync(string url)
        {
            if (string.IsNullOrWhiteSpace(url))
            {
                return(Json(""));
            }

            var siteMetrics = await _services.AccessPageAndGetResourcesFull(url.NormalizeUrl(), false, false, true, Startup.TakeSnapshootOnError, false);

            StringBuilder sb = new StringBuilder();

            var name = "site_up";

            sb.AppendLine($"# TYPE {name} gauge");
            sb.AppendLine($"{name}{{response=\"{siteMetrics.SiteStatus}\",screenshot=\"{siteMetrics.ScreenShotPath}\"}} {siteMetrics.IsSiteUp}");

            name = "site_up_raw";
            sb.AppendLine($"# TYPE {name} gauge");
            sb.AppendLine($"{name} {siteMetrics.IsSiteUp}");

            name = "site_5xx";
            sb.AppendLine($"# TYPE {name} gauge");
            sb.AppendLine($"{name} {siteMetrics.IsSiteStatus5xx}");

            if (siteMetrics.Assets != null)
            {
                foreach (var metric in siteMetrics.Assets)
                {
                    var fields = typeof(AssetPerformance).GetProperties()
                                 .Where(methodInfo => methodInfo.GetCustomAttributes(typeof(PrometheusAttribute), true).Length > 0)
                                 .ToList();
                    foreach (var field in fields)
                    {
                        name = field.GetCustomAttributes(typeof(PrometheusAttribute), true)[0].ToString();

                        sb.AppendLine($"# HELP {name} (SystemDriverResidentBytes)");
                        sb.AppendLine($"# TYPE {name} gauge");
                        sb.AppendLine($"{name}{{asset=\"{metric.name}\",type=\"{metric.entryType}\"}} {field.GetValue(metric)}");
                    }
                }
            }
            return(Ok(sb.ToString()));
        }