static void Run(string config, UInt16 prometheusPort = 8080, bool noPrometheus = false, bool noConsole = false) { var rawConfig = RawConfig.Create(config); var configObj = Config.Create(rawConfig); var netInfo = NetworkHelpers.PrimaryNetUpdates; var usePrometheus = !noPrometheus; if (usePrometheus) { PrometheusPublisher.StartMetrics(prometheusPort); System.Console.WriteLine($"Prometheus endpoint listening on port {prometheusPort}"); } var vizSubscription = InitMetricsAndViz(configObj, netInfo, usePrometheus, noConsole); NetworkHelpers.AddressChanged.Subscribe(_ => { if (vizSubscription != null) { vizSubscription.Dispose(); } vizSubscription = InitMetricsAndViz(configObj, netInfo, usePrometheus, noConsole); }); if (noPrometheus && noConsole) { System.Console.WriteLine("Warning: Checks are being performed, but both console visualization and prometheus endpoint are disabled!"); System.Console.WriteLine(" This is a pointless waste of CPU and bandwidth."); } Thread.Sleep(Timeout.Infinite); }
static IDisposable?InitMetricsAndViz( IEnumerable <HostConfig> configObj, IObservable <NetInfo> netInfo, bool usePrometheus = true, bool noConsole = false) { var reports = CheckerBuilder.Build(configObj); if (usePrometheus) { PrometheusPublisher.SetReportSource(reports); } IDisposable?vizSubscription = null; if (!noConsole) { var viz = new VizEngine(reports, netInfo); vizSubscription = viz.Frames .Subscribe(frame => { Console.Clear(); System.Console.WriteLine(frame); }); } reports.Connect(); return(vizSubscription); }
public EndpointMonitor(IHttpClientFactory httpClientFactory, EndpointService service, ILogger <EndpointMonitor> logger, ITokenService tokenService, PrometheusPublisher prometheusPublisher, ApplicationInsightsPublisher aiPublisher) { _httpClientFactory = httpClientFactory; _tokenService = tokenService; _service = service; _logger = logger; _prometheusPublisher = prometheusPublisher; _aiPublisher = aiPublisher; }