public async Task Run(TextReader input, CancellationToken cancellationToken) { metricServer.Start(); await input.ReadLineAsync(); while (true) { if (cancellationToken.IsCancellationRequested) { break; } if (!(await input.ReadLineAsync() is { } line)) { break; } var fields = line.Split(","); try { updateMetrics(fields); } catch (FormatException ex) { Console.Error.WriteLine($"Couldn't parse line: '{line}'\n{ex.ToStringDemystified()}"); } } metricServer.Stop(); }
public Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("Starting metric service for prometheus"); _server.Start(); return(Task.CompletedTask); }
private void OnStarted() { _metricServer.Start(); _logger.LogInformation("Started metrics listener, Listening on {0}:{1}{2}", _options.Host, _options.Port, _options.MapPath); // Perform post-startup activities here }
/// <summary> /// Start metric server /// </summary> /// <returns></returns> public static void StartWhenEnabled(this IMetricServer server, IModuleConfig config, Serilog.ILogger logger) { if (config.EnableMetrics) { server.Start(); logger.Information("Prometheus metric server started."); } else { logger.Information("Metrics Collection is disabled. Not starting prometheus metric server."); } }
public Task StartAsync(CancellationToken cancellationToken) { _logger.Debug($"Starting metrics server on :{_options.MetricsEndpointPort} {_options.MetricsEndpointPath}"); try { _server.Start(); } catch (Exception ex) { _logger.Error("Error starting metrics server", ex); } return(Task.CompletedTask); }
/// <summary> /// Start metric server /// </summary> /// <returns></returns> public static void StartWhenEnabled(this IMetricServer server, IModuleConfig config, Serilog.ILogger logger) { if (config.EnableMetrics) { try { server.Start(); logger.Information("Prometheus metric server started."); } catch (HttpListenerException e) { logger.Error(e, "Unable to start metric server. For more info, please check troubleshooting guide for edge metrics collection"); } } else { logger.Information("Metrics Collection is disabled. Not starting prometheus metric server."); } }
/// <summary> /// Initializes a new instance of the type /// </summary> /// <param name="hostName">The host name that will server the data</param> /// <param name="port">The port that the metrics server willb exposed on</param> /// <param name="url">The URL suffix the metrics server will be exposed on (default: metrics/)</param> /// <param name="bufferSize">The number of metrics in a bucket, use multiples of 500 for optimal performance</param> /// <param name="ageBuckets">The number of buckets to keep before aging out</param> /// <param name="pulseDuration">The duration in seconds of a pulse summary</param> public PrometheusMetricsProvider(string hostName, int port, string url = "metrics/", int bufferSize = 1500, int ageBuckets = 5, int pulseDuration = 10) { _bufferSize = bufferSize; _ageBuckets = ageBuckets; _pulseDuration = pulseDuration; if (string.IsNullOrWhiteSpace(hostName)) { _metricServer = new MetricServer(port, url); } else { _metricServer = new MetricServer(hostName, port, url); } _metricServer.Start(); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); _metricServer = new MetricServer("localhost", 9091); _metricServer.Start(); }
public static void Start() { _Server = new MetricServer(50505, new IOnDemandCollector[] { new DotNetStatsCollector(), new PerfCounterCollector() }); _Server.Start(); }
public static void Main(string[] args) { #if DEBUG if (Debugger.IsAttached) { args = args.Skip(1).ToArray(); } #endif var env = (Environment.GetEnvironmentVariable("VSTORE_ENVIRONMENT") ?? "Production").ToLower(); var basePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var configuration = new ConfigurationBuilder() .SetBasePath(basePath) .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{env}.json") .AddEnvironmentVariables("VSTORE_") .Build(); var container = Bootstrap(configuration); var loggerFactory = container.Resolve <ILoggerFactory>(); var logger = loggerFactory.CreateLogger <Program>(); var cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, eventArgs) => { logger.LogInformation("Application is shutting down..."); cts.Cancel(); container.Dispose(); eventArgs.Cancel = true; }; var app = new CommandLineApplication { Name = "VStore.Worker" }; app.HelpOption(CommandLine.HelpOptionTemplate); app.OnExecute( () => { Console.WriteLine("VStore job runner."); app.ShowHelp(); return(0); }); var jobRunner = container.Resolve <JobRunner>(); app.Command( CommandLine.Commands.Collect, config => { config.Description = "Run cleanup job. See available arguments for details."; config.HelpOption(CommandLine.HelpOptionTemplate); config.Command( CommandLine.Commands.Binaries, commandConfig => { commandConfig.Description = "Collect unrefenced and expired binary files."; commandConfig.HelpOption(CommandLine.HelpOptionTemplate); commandConfig.Argument(CommandLine.Arguments.BatchSize, "Maximun amount of events to process for one iteration."); commandConfig.Argument(CommandLine.Arguments.Delay, "Delay between collections."); commandConfig.OnExecute(() => Run(commandConfig, jobRunner, cts)); }); config.OnExecute(() => { config.ShowHelp(); return(0); }); }); app.Command( CommandLine.Commands.Produce, config => { config.Description = "Run produce events job. See available arguments for details."; config.HelpOption(CommandLine.HelpOptionTemplate); config.Command( CommandLine.Commands.Events, commandConfig => { commandConfig.Description = "Produce events of created versions of objects and/or binary files references."; commandConfig.HelpOption(CommandLine.HelpOptionTemplate); commandConfig.Argument(CommandLine.Arguments.Mode, $"Set '{CommandLine.ArgumentValues.Versions}' to produce events of created versions of objects, " + $"and '{CommandLine.ArgumentValues.Binaries}' to produce events of binary files references."); commandConfig.OnExecute(() => Run(commandConfig, jobRunner, cts)); }); }); var exitCode = 0; try { logger.LogInformation("VStore Worker started with options: {workerOptions}.", args.Length != 0 ? string.Join(" ", args) : "N/A"); MetricServer.Start(); exitCode = app.Execute(args); } catch (CommandParsingException ex) { ex.Command.ShowHelp(); exitCode = 1; } catch (JobNotFoundException) { exitCode = 2; } catch (Exception ex) { logger.LogCritical(new EventId(), ex, "Unexpected error occured. See logs for details."); exitCode = -1; } finally { MetricServer.Stop(); logger.LogInformation("VStore Worker is shutting down with code {workerExitCode}.", exitCode); } Environment.Exit(exitCode); }
public static void Start() { _Server = new MetricServer(50505); _Server.Start(); }
public PrometheusMetricsProvider(string hostname, int port, string url, CollectorRegistry registry = null, bool useHttps = false) { _server = new MetricServer(hostname, port, url, registry, useHttps); _server.Start(); }
public void Start() { metricServer.Start(); _logger.Information("Metric server started"); }