/// <inheritdoc/>
 public void Start(long period, TimeUnit unit, MetricPredicate predicate)
 {
     period_      = period;
     period_unit_ = unit;
     predicate_   = predicate;
     Start();
 }
Beispiel #2
0
 /// <summary>
 /// Test given source tests against predicate. On fail throws assertion error with failed test description.
 /// </summary>
 /// <param name="predicate"></param>
 /// <param name="tests"></param>
 internal static void RunTests(MetricPredicate predicate, params SourceTest[] tests)
 {
     foreach (var test in tests)
     {
         RunTest(predicate, test);
     }
 }
Beispiel #3
0
        public override void Run(MetricPredicate predicate)
        {
            var registry = MetricsRegistry;
            var now      = DateTime.UtcNow;

            registry.Report(Report, now, predicate);
        }
Beispiel #4
0
 /// <summary>
 ///     Creates a new <seealso cref="ConsoleReporter" /> for a given metrics registry.
 /// </summary>
 /// <param name="metricsRegistry">the metrics registry</param>
 /// <param name="writer">the <seealso cref="TextWriter" /> to which output will be written</param>
 /// <param name="predicate">
 ///     the <seealso cref="MetricPredicate" /> used to determine whether a metric will be output
 /// </param>
 public ConsoleReporter(
     MetricsRegistry metricsRegistry,
     TextWriter writer,
     MetricPredicate predicate)
     : this(metricsRegistry, writer, predicate, Clock.DefaultClock, TimeZoneInfo.Utc)
 {
 }
Beispiel #5
0
        /// <summary>
        ///     Returns a grouped and sorted map of all registered metrics which match then given {@link
        ///     MetricPredicate}.
        /// </summary>
        /// <param name="predicate">a predicate which metrics have to match to be in the results</param>
        /// <returns>all registered metrics which match {@code predicate}, sorted by name</returns>
        public IDictionary<string, IDictionary<MetricName, Metric>> GroupedMetrics(MetricPredicate predicate)
        {
            IDictionary<string, IDictionary<MetricName, Metric>> groups =
                new SortedDictionary<string, IDictionary<MetricName, Metric>>();
            foreach (KeyValuePair<MetricName, Metric> entry in metrics)
            {
                var qualifiedTypeName = entry.Key.Group + "." + entry.Key
                                            .Type;
                if (predicate.Matches(entry.Key, entry.Value))
                {
                    string scopedName;
                    if (entry.Key.HasScope)
                    {
                        scopedName = qualifiedTypeName + "." + entry.Key.Scope;
                    }
                    else
                    {
                        scopedName = qualifiedTypeName;
                    }

                    IDictionary<MetricName, Metric> group = groups.Get(scopedName);
                    if (group == null)
                    {
                        group = new SortedDictionary<MetricName, Metric>();
                        groups.Put(scopedName, group);
                    }

                    group.Put(entry.Key, entry.Value);
                }
            }

            return new ReadOnlyDictionary<string, IDictionary<MetricName, Metric>>(groups);
        }
Beispiel #6
0
 /// <summary>
 ///     Creates a new <seealso cref="ConsoleReporter" /> for a given metrics registry.
 /// </summary>
 /// <param name="metricsRegistry">the metrics registry</param>
 /// <param name="writer">the <seealso cref="TextWriter" /> to which output will be written</param>
 /// <param name="predicate">
 ///     the <seealso cref="MetricPredicate" /> used to determine whether a metric will be output
 /// </param>
 /// <param name="clock">the <seealso cref="Clock" /> used to print time</param>
 /// <param name="timeZone">the <seealso cref="TimeZone" /> used to print time</param>
 public ConsoleReporter(
     MetricsRegistry metricsRegistry,
     TextWriter writer,
     MetricPredicate predicate,
     Clock clock,
     TimeZoneInfo timeZone)
     : this(metricsRegistry, writer, predicate, clock, timeZone, CultureInfo.CurrentCulture)
 {
 }
Beispiel #7
0
 /// <summary>
 ///     Creates a new <seealso cref="ConsoleReporter" /> for a given metrics registry.
 /// </summary>
 /// <param name="metricsRegistry">the metrics registry</param>
 /// <param name="writer">the <seealso cref="TextWriter" /> to which output will be written</param>
 /// <param name="predicate">
 ///     the <seealso cref="MetricPredicate" /> used to determine whether a metric will be output
 /// </param>
 /// <param name="clock">the <seealso cref="Clock" /> used to print time</param>
 /// <param name="timeZone">the <seealso cref="TimeZone" /> used to print time</param>
 /// <param name="locale">the <seealso cref="CultureInfo" /> used to print values</param>
 public ConsoleReporter(
     MetricsRegistry metricsRegistry,
     TextWriter writer,
     MetricPredicate predicate,
     Clock clock,
     TimeZoneInfo timeZone,
     CultureInfo locale)
     : base(metricsRegistry, "console-reporter")
 {
     _writer = writer;
     _predicate = predicate;
     _clock = clock;
     _timeZone = timeZone;
     _locale = locale;
 }
Beispiel #8
0
 /// <summary>
 /// Creates a new <seealso cref="CsvReporter" /> which will write metrics from the given
 /// <seealso cref="MetricsRegistry" /> which match the given <seealso cref="MetricPredicate" /> to CSV files in the
 /// given output directory.
 /// </summary>
 /// <param name="metricsRegistry">the <seealso cref="MetricsRegistry" /> containing the metrics this reporter will report
 /// </param>
 /// <param name="predicate">the <seealso cref="MetricPredicate" /> which metrics are required to match before being written to files
 /// </param>
 /// <param name="outputDir">the directory to which files will be written</param>
 /// <param name="clock">the clock used to measure time</param>
 public CsvReporter(MetricsRegistry metricsRegistry,
                    MetricPredicate predicate,
                    DirectoryInfo outputDir,
                    Clock clock) : base(metricsRegistry, "csv-reporter")
 {
     if (!outputDir.Exists)
     {
         throw new ArgumentException(outputDir + " does not exist (or is not a directory)");
     }
     this.outputDir = outputDir;
     this.predicate = predicate;
     this.streamMap = new Dictionary<MetricName, TextWriter>();
     this.startTime = 0L;
     this.clock = clock;
 }
Beispiel #9
0
 /// <summary>
 /// Test given source tests against predicate. On fail throws assertion error with failed test description.
 /// </summary>
 /// <param name="predicate"></param>
 /// <param name="tests"></param>
 internal static void RunTests(MetricPredicate predicate, IEnumerable <SourceTest> tests)
 {
     RunTests(predicate, tests.ToArray());
 }
Beispiel #10
0
        /// <summary>
        /// Test given source according to predicate. On fail throws assertion error with testDescription.
        /// </summary>
        /// <param name="predicate"></param>
        /// <param name="test"></param>
        internal static void RunTest(MetricPredicate predicate, SourceTest test)
        {
            var metricInfo = GetInfo(test);

            Assert.IsTrue(predicate(metricInfo), test.Description);
        }
Beispiel #11
0
 /// <summary>
 /// Get negation to given predicate.
 /// </summary>
 /// <param name="predicate"></param>
 /// <returns></returns>
 internal static MetricPredicate GetNegation(MetricPredicate predicate)
 {
     return((info) => !predicate(info));
 }
Beispiel #12
0
 /// <summary>
 /// Creates a new <seealso cref="CsvReporter" /> which will write metrics from the given
 /// <seealso cref="MetricsRegistry" /> which match the given <seealso cref="MetricPredicate" /> to CSV files in the
 /// given output directory.
 /// </summary>
 /// <param name="metricsRegistry">the <seealso cref="MetricsRegistry" /> containing the metrics this reporter will report
 /// </param>
 /// <param name="predicate">the <seealso cref="MetricPredicate" /> which metrics are required to match before being written to files
 /// </param>
 /// <param name="outputDir">the directory to which files will be written</param>
 public CsvReporter(MetricsRegistry metricsRegistry,
                    MetricPredicate predicate,
                    DirectoryInfo outputDir) :
     this(metricsRegistry, predicate, outputDir, Clock.DefaultClock)
 {
 }
Beispiel #13
0
 public override void Run(MetricPredicate predicate) {
   var registry = MetricsRegistry;
   var now = DateTime.UtcNow;
   registry.Report(Report, now, predicate);
 }
 /// <inheritdoc/>
 public void Start(long period, TimeUnit unit, MetricPredicate predicate) {
   period_ = period;
   period_unit_ = unit;
   predicate_ = predicate;
   Start();
 }