//https://github.com/etsy/statsd /* * Key / value pair - gorets 12345 timestamp * it doesn't appear statsd has native support for kv pairs and its not documented * Etsys parsing code lives here found other code to suggest it works like this - it appears from the code that a key * https://raw.github.com/etsy/statsd/master/stats.js * * Timing - glork:320|ms * The glork took 320ms to complete this time. StatsD figures out 90th percentile, average (mean), lower and upper bounds for the flush interval. The percentile threshold can be tweaked with config.percentThreshold. * * Counting - gorets:1|c * This is a simple counter. Add 1 to the "gorets" bucket. It stays in memory until the flush interval config.flushInterval. * * Sampling - gorets:1|c|@0.1 * Tells StatsD that this counter is being sent sampled every 1/10th of the time. */ private static string ToStatsDString(this IMetric metric) { Type t = metric.GetType(); if (t == typeof(KeyValue)) { //TODO: 1-19-2012 - this may be entirely wrong - we need to find a statsd to test against - eat timestamp KeyValue keyValue = (KeyValue)metric; return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|g", keyValue.Key, keyValue.Value)); } else if (t == typeof(Timing)) { Timing timing = (Timing)metric; return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|ms", timing.Key, timing.Duration)); } else if (t == typeof(Counter)) { Counter counter = (Counter)metric; return(string.Format(CultureInfo.InvariantCulture, "{0}:{1}|c", counter.Key, counter.Adjustment)); } Sample sample = (Sample)metric; //last option return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|c|@{2:f}", sample.Key, sample.Value, sample.Frequency)); }
//https://github.com/kiip/statsite //key:value|type[|@flag] /* * Key / Value pair - mysql.queries:1381|kv|@1313107325 * Reporting how many queries we've seen in the last second on MySQL: * * Counting - rewards:1|c * Increments the "rewards" counter by 1 (use -1 to decrement by 1) * * Timing - api.session_created:114|ms * timing the response speed of an API call: * * Sampling - api.session_created:114|ms|@0.1 * Saying we sample this data in 1/10th of the API requests. */ private static string ToStatSiteString(this IMetric metric) { Type t = metric.GetType(); if (t == typeof(KeyValue)) { KeyValue keyValue = (KeyValue)metric; if (keyValue.Timestamp.HasValue) { return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|kv|@{2}", keyValue.Key, keyValue.Value, keyValue.Timestamp.Value.AsUnixTime())); } return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|kv", keyValue.Key, keyValue.Value)); } else if (t == typeof(Counter)) { Counter counter = (Counter)metric; return(string.Format(CultureInfo.InvariantCulture, "{0}:{1}|c", counter.Key, counter.Adjustment)); } else if (t == typeof(Timing)) { Timing timing = (Timing)metric; return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|ms", timing.Key, timing.Duration)); } Sample sample = (Sample)metric; //last option return(string.Format(CultureInfo.InvariantCulture, "{0}:{1:0.###}|c|@{2:f}", sample.Key, sample.Value, sample.Frequency)); }
private void OnMetricRemoved(MetricName name, IMetric metric) { Type metricType = metric.GetType(); if (metricType.IsSubclassOf(typeof(Gauge))) { handler.onGaugeRemoved(name); } else if (metric is Counter) { handler.onCounterRemoved(name); } else if (metric is Histogram) { handler.onHistogramRemoved(name); } else if (metric is Meter) { handler.onMeterRemoved(name); } else if (metric is Timer) { handler.onTimerRemoved(name); } else { throw new ArgumentException("Unknown metric type: " + metricType); } }
/// <summary> /// Adds a <see cref="MetricRegistryListener"/> to a collection of listeners that will be notified on /// metric creation.Listeners will be notified in the order in which they are added. /// <para /> /// The listener will be notified of all existing metrics when it first registers. /// </summary> /// <param name="listener"></param> public void AddListener(MetricRegistryListener listener) { handler.RegisterListener(listener); // TODO: Figure out how to notify listener of existing metrics efficiently foreach (KeyValuePair <MetricName, IMetric> entry in this._metrics) { MetricName name = entry.Key; IMetric metric = entry.Value; Type metricType = metric.GetType(); if (metricType.IsSubclassOf(typeof(Gauge))) { handler.onGaugeAdded(name, (Gauge)metric); } else if (metric is Counter) { handler.onCounterAdded(name, (Counter)metric); } else if (metric is Histogram) { handler.onHistogramAdded(name, (Histogram)metric); } else if (metric is Meter) { handler.onMeterAdded(name, (Meter)metric); } else if (metric is Timer) { handler.onTimerAdded(name, (Timer)metric); } else { continue; } } }
private static void RunFor3Sets(double trainingToTestDataRatio, int stopListWordNumber, IMetric metric, bool IdfOn) { int[] ks = { 2, 3, 5, 7, 10, 15, 20 }; string algo = ""; if (IdfOn) { algo = "IDF"; } else { algo = "TF"; } for (var i = 0; i < ks.Count(); i++) { Console.WriteLine(ks[i]); double p = Math.Round(Run(validPlaces, CategoryNamePlaces, trainingToTestDataRatio, stopListWordNumber, metric, ks[i], IdfOn), 1); double t = Math.Round(Run(validTopics, CategoryNameTopics, trainingToTestDataRatio, stopListWordNumber, metric, ks[i], IdfOn), 1); double m = Math.Round(Run(validNames, CategoryNameMedium, trainingToTestDataRatio, 20, metric, ks[i], IdfOn), 1); File.AppendAllText($@"C:\Users\Bartosz\Desktop\{algo}_{metric.GetType().Name}.txt", $"{ks[i]} & {p} & {t} & {m} \\\\ \n"); } }