private static void ConfigureMetrics(IConfiguration configuration, IServiceCollection services) { var config = new MetricsConfiguration(); configuration.GetSection("metrics").Bind(config); var influx = config.InfluxDb; var serverBaseAddress = new Uri(influx.BaseUri); var client = new LineProtocolClient(serverBaseAddress, influx.Database, influx.Username, influx.Password); var collector = new QueuedMetricsCollector(client); services.AddHostedService(provider => { var timer = new HostedQueueTimer(collector, TimeSpan.FromSeconds(config.FlushInterval)); timer.OnError += e => Console.Error.WriteLine(e); return(timer); }); var predefinedTags = new Dictionary <string, string> { { "hostname", Environment.MachineName } }; services.AddSingleton(new MeasurementWriterFactory(predefinedTags, collector)); }
public StatsDMetricsClient(MetricsConfiguration configuration) { StatsdClient.Metrics.Configure(new MetricsConfig { StatsdServerName = configuration.Hostname, StatsdServerPort = configuration.Port, Prefix = configuration.MetricsPrefix }); }
/// <summary> /// Configure app pipeline /// </summary> public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MetricsConfiguration metricsConfiguration, IAntiforgery antiforgery) { app.UseResponseCompression(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); } app.UseRouting(); app.UseMetrics(metricsConfiguration); app.UseCsrf(); app.UseSpaStaticFiles(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapHub <WebRtcHub>("/ws/webrtc", o => { // zero for unlimited o.TransportMaxBufferSize = 0; }); endpoints.MapHub <ChatHub>("/ws/chat", o => { // zero for unlimited o.TransportMaxBufferSize = 0; }); endpoints.MapControllers(); if (env.IsDevelopment()) { endpoints.MapToVueCliProxy( "{*path}", new SpaOptions { SourcePath = "ClientApp" }, npmScript: "serve", regex: "Compiled successfully", forceKill: true ); } }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; }); }
public static void Initialize(string envPrefix, string configFile, Server serverInfo, NativeLogLevel logLevel, NativeLogKind logKind, Action <string> logFunction, MetricsConfiguration metricsConfig, ServiceDiscoveryListener serviceDiscoveryListener = null) { _serviceDiscoveryListener = serviceDiscoveryListener; _handleRpcCallback = new HandleRpcCallbackFunc(HandleRpcCallback); _clusterNotificationCallback = new ClusterNotificationCallbackFunc(ClusterNotificationCallback); _logFunctionCallback = new LogFunction(LogFunctionCallback); var logCtx = GCHandle.Alloc(logFunction, GCHandleType.Normal); var pitayaMetrics = IntPtr.Zero; if (metricsConfig.IsEnabled) { if (metricsConfig.CustomMetrics == null) { metricsConfig.CustomMetrics = new CustomMetrics(); } metricsConfig.CustomMetrics.AddHistogram( RPC_LATENCY_METRIC, new HistogramBuckets(HistogramBucketKind.Exponential, 0.0005, 2.0, 20) ); _metricsReporter = new MetricsReporter(metricsConfig); pitayaMetrics = _metricsReporter.GetPitayaPtr(); } IntPtr err = pitaya_initialize_with_nats( IntPtr.Zero, envPrefix, configFile, Marshal.GetFunctionPointerForDelegate(_handleRpcCallback), Marshal.GetFunctionPointerForDelegate(_clusterNotificationCallback), logLevel, logKind, Marshal.GetFunctionPointerForDelegate(_logFunctionCallback), GCHandle.ToIntPtr(logCtx), pitayaMetrics, serverInfo.Handle, out pitaya ); if (err != IntPtr.Zero) { var pitayaError = new PitayaError(pitaya_error_code(err), pitaya_error_message(err)); pitaya_error_drop(err); throw new PitayaException($"Initialization failed: code={pitayaError.Code} msg={pitayaError.Message}"); } _rpcClient = new RpcClient(pitaya, _serializer); _metricsReporter?.Start(); }
public IRequest Marshall(PutBucketMetricsConfigurationRequest PutBucketMetricsConfigurationRequest) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_0154: Unknown result type (might be due to invalid IL or missing references) IRequest val = new DefaultRequest(PutBucketMetricsConfigurationRequest, "AmazonS3"); val.set_HttpMethod("PUT"); val.set_ResourcePath("/" + S3Transforms.ToStringValue(PutBucketMetricsConfigurationRequest.BucketName)); val.AddSubResource("metrics"); val.AddSubResource("id", PutBucketMetricsConfigurationRequest.MetricsId); StringWriter stringWriter = new StringWriter(CultureInfo.InvariantCulture); using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Encoding = Encoding.UTF8, OmitXmlDeclaration = true })) { MetricsConfiguration metricsConfiguration = PutBucketMetricsConfigurationRequest.MetricsConfiguration; if (metricsConfiguration != null) { xmlWriter.WriteStartElement("MetricsConfiguration", "http://s3.amazonaws.com/doc/2006-03-01/"); if (metricsConfiguration != null) { if (metricsConfiguration.IsSetMetricsId()) { xmlWriter.WriteElementString("Id", "http://s3.amazonaws.com/doc/2006-03-01/", S3Transforms.ToXmlStringValue(metricsConfiguration.MetricsId)); } if (metricsConfiguration.IsSetMetricsFilter()) { xmlWriter.WriteStartElement("Filter", "http://s3.amazonaws.com/doc/2006-03-01/"); metricsConfiguration.MetricsFilter.MetricsFilterPredicate.Accept(new MetricsPredicateVisitor(xmlWriter)); xmlWriter.WriteEndElement(); } } xmlWriter.WriteEndElement(); } } try { string text = stringWriter.ToString(); val.set_Content(Encoding.UTF8.GetBytes(text)); val.get_Headers()["Content-Type"] = "application/xml"; string value = AmazonS3Util.GenerateChecksumForContent(text, fBase64Encode: true); val.get_Headers()["Content-MD5"] = value; return(val); } catch (EncoderFallbackException ex) { throw new AmazonServiceException("Unable to marshall request to XML", (Exception)ex); } }
private async Task OnExecuteAsync(CancellationToken ct) { MetricsConfiguration config = null; try { config = new MetricsConfiguration() { InfluxDbUri = InfluxDbUri, Network = Network, LndRestApiUri = LndRestApiUri, MacaroonHex = MacaroonHex, CertThumbprintHex = CertThumbprintHex, IntervalSeconds = IntervalSeconds, InfluxDbName = InfluxDbName, MetricPrefix = MetricPrefix, UseMempoolBackend = UseMempoolBackend, MempoolApiUri = MempoolApiUri }; config.Validate(); } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } try { var client = new MetricsClient(config); if (this.TestInfluxDb) { client.TestInfluxDb(); } else if (this.TestLndApi) { client.TestLndApi(); } else { var version = Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion; await client.Start(version, ct).ConfigureAwait(false); } } catch (Exception e) { Console.WriteLine(e.Message); Environment.Exit(1); } }
public static void Initialize(TestContext context) { var options = new TestClusterOptions(); options.ClusterConfiguration.Globals .RegisterBootstrapProvider <MetricsTrackerBootstrapProvider>("MetricsTracker"); Cluster = new TestCluster(options); Cluster.Deploy(); var metricsConfig = MetricsConfiguration.CreateUnitTestConfig(); ClusterMetricsGrain = Cluster.GrainFactory.GetGrain <IClusterMetricsGrain>(Guid.Empty); ClusterMetricsGrain.Configure(metricsConfig).Wait(); }
private static string GetCustomControllerName(this HttpContext context, MetricsConfiguration configuration) { var path = context.Request.Path.Value; if (path.StartsWith("/ws/")) { return("signalR"); } if (path.StartsWith(configuration.Endpoint)) { return("prometheus"); } return("spa"); }
public LnrpcChannelBalanceResponseMetric(MetricsConfiguration configuration, MetricsCollector metrics) { this.configuration = configuration; this.metrics = metrics; }
public MetricsService(ILogger <MetricsService> logger, MetricsConfiguration configuration) { _logger = logger; _configuration = configuration; }
public PendingChannelsResponsePendingOpenChannelMetric(MetricsConfiguration configuration, MetricsCollector metrics, NodeAliasCache nodeAliasCache) { this.configuration = configuration; this.metrics = metrics; this.nodeAliasCache = nodeAliasCache; }
public LnrpcChannelMetrics(MetricsConfiguration configuration, MetricsCollector metrics, NodeAliasCache nodeAliasCache) { this.configuration = configuration; this.metrics = metrics; this.nodeAliasCache = nodeAliasCache; }
static void Main(string[] args) { Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); var constantTags = new Dictionary<string, string> { {"game", "game"}, {"serverType", "svType"} }; AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs args) => { Console.WriteLine("shutting down pitaya cluster"); PitayaCluster.Terminate(); }; var customMetrics = new CustomMetrics(); customMetrics.AddHistogram( "my_histogram", new HistogramBuckets(HistogramBucketKind.Linear, 1, 2, 10), "Some test histogram", new []{"my_label"}); var metricsParameters = new MetricsConfiguration( true, "127.0.0.1", "8000", "myns", customMetrics); try { PitayaCluster.Initialize( "exampleapp", "csharp.toml", new Server( id: Guid.NewGuid().ToString(), kind: "csharp", metadata: "{}", hostname: "ololo", frontend: false ), NativeLogLevel.Debug, NativeLogKind.Console, (msg) => { Console.Write($"C# Log: {msg}"); }, metricsParameters, new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Console.WriteLine("Server was added"); Console.WriteLine(" id: " + server.Id); Console.WriteLine(" kind: " + server.Kind); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Console.WriteLine("Server was removed"); Console.WriteLine(" id: " + server.Id); Console.WriteLine(" kind: " + server.Kind); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } })); } catch (PitayaException exc) { Logger.Error("Failed to create cluster: {0}", exc.Message); Environment.Exit(1); } Logger.Info("pitaya lib initialized successfully :)"); PitayaCluster.RegisterRemote(new TestRemote()); PitayaCluster.RegisterHandler(new TestHandler()); TrySendRpc(); PitayaCluster.WaitShutdownSignal(); }
public LnrpcPendingHtlcMetrics(MetricsConfiguration configuration, MetricsCollector metrics) { this.configuration = configuration; this.metrics = metrics; }
public MetricsService(MetricsConfiguration config) { _config = config; }
public static IApplicationBuilder UseMetrics(this IApplicationBuilder builder, MetricsConfiguration configuration) { if (!configuration.Enabled) { return(builder); } return(builder.Map(configuration.Endpoint, metricsApp => { if (configuration.BasicAuth) { metricsApp.UseMiddleware <BasicAuthMiddleware>(configuration); } metricsApp.UseMetricServer(string.Empty); }) .Use(async(context, next) => { if (!context.IsStaticFiles()) { var routeData = context.GetRouteData(); if (string.IsNullOrEmpty(routeData.Values["controller"] as string)) { context.GetRouteData().Values.Add("controller", context.GetCustomControllerName(configuration)); } if (string.IsNullOrEmpty(routeData.Values["action"] as string)) { context.GetRouteData().Values.Add("action", context.Request.Path.Value); } } await next(); }) .UseHttpMetrics());; }
public LnrpcNetworkInfoMetric(MetricsConfiguration configuration, MetricsCollector metrics) { this.configuration = configuration; this.metrics = metrics; }
public BasicAuthMiddleware(RequestDelegate next, MetricsConfiguration metricsConfiguration) { _next = next; _metricsConfiguration = metricsConfiguration; }
public PendingChannelsResponseForceClosedChannelMetrics(MetricsConfiguration configuration, MetricsCollector metrics) { this.configuration = configuration; this.metrics = metrics; }