public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var statsDConfig = new StatsDConfiguration { Host = Configuration.GetValue <string>("StatsdHost") }; var statsDPublisher = new StatsDPublisher(statsDConfig); app.Use(async(context, next) => { var stopWatch = Stopwatch.StartNew(); await next(); stopWatch.Stop(); if (context.Items["MetricName"] != null) { var statName = $"boilerplate-api.{((string)context.Items["MetricName"]).ToLower()}.{context.Request.Method.ToLower()}.{context.Response.StatusCode}"; statsDPublisher.Timing(stopWatch.Elapsed, statName); } }); app.UseMvc(); }
private StatsdSingleton() { var statsDConfig = new StatsDConfiguration { Host = Environment.GetEnvironmentVariable("StatsdHost") ?? "localhost" }; _publisher = new StatsDPublisher(statsDConfig); }
/// <summary> /// Send a gauge to the statsd server. /// </summary> /// <param name="statsdHost">The hostname of the StatsD server.</param> /// <param name="statsdPort">The port of the StatsD server.</param> /// <param name="value">The value of the gauge.</param> /// <param name="prefix">The gauge prefix.</param> public static void SendGauge(string statsdHost, int statsdPort, double value, string prefix = "mumble_server") { var statsDConfig = new StatsDConfiguration { Host = statsdHost, Port = statsdPort, Prefix = prefix }; IStatsDPublisher statsDPublisher = new StatsDPublisher(statsDConfig); statsDPublisher.Gauge(value, "connected_users"); }
internal BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } _onError = configuration.OnError; _transport = transport; _formatter = new StatsDUtf8Formatter(configuration.Prefix); }
public ValuesController(CLOUD_CSYEContext context, ILogger <ValuesController> log) { _log = log; _context = context; s3Client = new AmazonS3Client(bucketRegion); statsDConfig = new StatsDConfiguration { Host = "localhost", Port = 8125 }; statsDPublisher = new StatsDPublisher(statsDConfig); }
public static void Increment_Is_Noop_If_Bucket_Is_Null() { // Arrange var configuration = new StatsDConfiguration(); var transport = new Mock <IStatsDTransport>(); var publisher = new BufferBasedStatsDPublisher(configuration, transport.Object); // Act publisher.Increment(1, 1, null); // Assert transport.Verify((p) => p.Send(It.Ref <ArraySegment <byte> > .IsAny), Times.Never()); }
public static void EnableStatsdPerformanceCounters(this IBusFactoryConfigurator configurator, Action <StatsDConfiguration> action) { var statsDConfiguration = StatsDConfiguration.Defaults(); action(statsDConfiguration); if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var specification = new PerformanceCounterBusFactorySpecification(new StatsDCounterFactory(statsDConfiguration)); configurator.AddBusFactorySpecification(specification); }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _pooledTransport = new PooledUdpTransport(endpointSource); _unpooledTransport = new UdpTransport(endpointSource); }
public static void Increment_Sends_If_Default_Buffer_Is_Too_Small() { // Arrange var configuration = new StatsDConfiguration() { Prefix = new string('a', 513) }; var transport = new Mock <IStatsDTransport>(); var publisher = new BufferBasedStatsDPublisher(configuration, transport.Object); // Act publisher.Increment(1, 1, "foo"); // Assert transport.Verify((p) => p.Send(It.Ref <ArraySegment <byte> > .IsAny), Times.Once()); }
public void Setup() { var config = new StatsDConfiguration { // if you want to verify that stats are received, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndPointFactory.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); _ipTransport = new SocketTransport(endpointSource, SocketProtocol.IP); _ipSender = new BufferBasedStatsDPublisher(config, _ipTransport); _ipSender.Increment("startup.i"); _udpTransport = new SocketTransport(endpointSource, SocketProtocol.Udp); _udpSender = new BufferBasedStatsDPublisher(config, _udpTransport); _udpSender.Increment("startup.u"); }
public void Setup() { var config = new StatsDConfiguration { // if you want verify that stats are recevied, // you will need the IP of suitable local test stats server Host = "127.0.0.1", Prefix = "testmetric" }; var endpointSource = EndpointParser.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var udpTransport = new UdpTransport(endpointSource); var ipTransport = new IpTransport(endpointSource); _udpSender = new StatsDPublisher(config, udpTransport); _udpSender.Increment("startup.ud"); _ipSender = new StatsDPublisher(config, ipTransport); _udpSender.Increment("startup.ip"); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } var statsDConfig = new StatsDConfiguration { Host = "graphite" }; var statsDPublisher = new StatsDPublisher(statsDConfig); app.Use(async(context, next) => { using (var timer = statsDPublisher.StartTimer("thing")) { await next(); timer.StatName = $"response-api.code.{context.Response.StatusCode}"; } }); app.UseMvc(); }
public void Setup() { var config = new StatsDConfiguration { Host = "127.0.0.1", }; var endpointSource1 = EndPointFactory.MakeEndPointSource( config.Host, config.Port, config.DnsLookupInterval); var endpointSource2 = EndPointFactory.MakeEndPointSource( config.Host, config.Port + 1, config.DnsLookupInterval); var switcher = new MillisecondSwitcher(endpointSource1, endpointSource2); _transport = new SocketTransport(endpointSource1, SocketProtocol.Udp); _transportSwitched = new SocketTransport(switcher, SocketProtocol.Udp); }
public void StatD <TPipeline, TSettings>(TSettings settings, string pipeline, bool ignoreErrors = false) where TPipeline : AbstractPipeline where TSettings : StatsDSettings { _services.AddStatsD( provider => { var prefix = string.IsNullOrWhiteSpace(settings.Prefix) ? string.Empty : settings.Prefix.ToLowerInvariant(); if (prefix.Last() != '.') { prefix += "."; } var statsDConfiguration = new StatsDConfiguration { Host = settings.HostName, Port = settings.Port, Prefix = $"{prefix}{pipeline.ToLowerInvariant()}" }; if (ignoreErrors) { statsDConfiguration.OnError = ex => true; } else { var logger = provider.GetService <ILogger <TPipeline> >(); statsDConfiguration.OnError = ex => { logger.LogError(ex, ex.Message); return(false); }; } return(statsDConfiguration); }); }
public StatsDCounterFactory(StatsDConfiguration config) { _config = config; }
public BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport) { _onError = configuration.OnError; _transport = transport; _formatter = new StatsDUtf8Formatter(configuration.Prefix); }