private static Statsd CreateStatsd(StatsdConfiguration config) { var client = config.IsTCP ? (IStatsdClient) new StatsdTCPClient(config.Address, config.Port) : new StatsdUDPClient(config.Address, config.Port); return(new Statsd(client, new RandomGenerator(), new StopWatchFactory())); }
public MetricSender([CanBeNull] string service) { var connectionString = ApplicationConfiguration.Read <UlearnConfiguration>().StatsdConnectionString; if (string.IsNullOrEmpty(connectionString)) { return; } var config = StatsdConfiguration.CreateFrom(connectionString); prefix = config.Prefix; this.service = service ?? System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToLower(); statsd = CreateStatsd(config); }
public MetricSender(string service) { var connectionString = ApplicationConfiguration.Read <UlearnConfiguration>().StatsdConnectionString; if (string.IsNullOrEmpty(connectionString)) { return; } var config = StatsdConfiguration.CreateFrom(connectionString); prefix = config.Prefix; this.service = service; statsd = CreateStatsd(config); }
/// <summary> /// </summary> /// <param name="connectionString">e.g. "address=graphite-test;port=8125;transport=Tcp;prefixKey=ulearn.local"</param> /// <returns></returns> public static StatsdConfiguration CreateFrom(string connectionString) { var result = new StatsdConfiguration(); var connectionConfig = ParseConnectionString(connectionString); if (connectionConfig.TryGetValue("address", out var address)) { result.Address = address; } if (connectionConfig.TryGetValue("port", out var portString) && int.TryParse(portString, out var port)) { result.Port = port; } if (connectionConfig.TryGetValue("prefixKey", out var prefixKey)) { result.Prefix = prefixKey; } result.IsTCP = connectionConfig.TryGetValue("transport", out var transport) && string.Compare(transport, "tcp", StringComparison.InvariantCultureIgnoreCase) != 0; return(result); }