-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (56 loc) · 2.12 KB
/
Program.cs
File metadata and controls
65 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.IO;
using System.Threading;
using Metrics;
namespace EventStore.TestClientAPI
{
class Program
{
static void Main(string[] args)
{
int exitCode = 0;
TimeSpan metricsInterval = TimeSpan.FromSeconds(10);
InitializeMetrics(metricsInterval, "WriteFlood");
try
{
var client = new Client(new ClientOptions(args));
exitCode = client.Run();
}
catch (Exception exception)
{
Console.WriteLine("Oops: {0}", exception);
}
if (exitCode == 0)
{
PrintMetrics();
// wait for the metrics to be reported one last time
Console.Write("waiting {0} for final metrics to be written...", metricsInterval);
Thread.Sleep(metricsInterval);
}
Environment.Exit(exitCode);
}
private static void InitializeMetrics(TimeSpan interval, string filenamePrefix)
{
string directory = string.Format("{0}-metrics-{1}", filenamePrefix, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
string path = Path.GetTempPath();
string filename = Path.Combine(path, directory);
Console.WriteLine("Performance metrics will be written every {1} to {0}", filename, interval);
Metric.Config
.WithSystemCounters()
.WithAppCounters()
.WithReporting(report => report.WithCSVReports(filename, interval));
}
private static void PrintMetrics()
{
var data = Metric.Context(null).DataProvider.CurrentMetricsData;
foreach (var meter in data.Meters)
{
Console.WriteLine("{0} : {1:0.00} {2}/{3}", meter.Name, meter.Value.MeanRate, meter.Unit, meter.RateUnit);
}
foreach (var timer in data.Timers)
{
Console.WriteLine("{0} : {1:0.00000} {2}", timer.Name, timer.Value.Rate.MeanRate, timer.DurationUnit);
}
}
}
}