-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathMetricsModels.cs
More file actions
148 lines (124 loc) · 4.23 KB
/
Copy pathMetricsModels.cs
File metadata and controls
148 lines (124 loc) · 4.23 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using StackifyLib.Utils;
namespace StackifyLib.Models
{
public enum MetricType : short
{
MetricLast = 134,
Counter = 129,
MetricAverage = 132,
CounterTime = 131
}
public class MetricSetting
{
public bool AutoReportZeroIfNothingReported { get; set; }
public bool AutoReportLastValueIfNothingReported { get; set; }
public bool AllowNegativeGauge { get; set; }
}
public class Metric
{
public Metric(string category, string name, MetricType metricType)
{
Category = category;
MetricType = metricType;
Name = name;
Occurred = DateTime.UtcNow;
IsIncrement = false;
Settings = new MetricSetting() { AutoReportZeroIfNothingReported = false };
}
public MetricSetting Settings { get; set; }
public bool IsIncrement { get; set; }
public string Category { get; set; }
public string Name { get; set; }
public MetricType MetricType { get; set; }
public double Value { get; set; }
public DateTime Occurred { get; internal set; }
public string AggregateKey { get; set; }
public void CalcAndSetAggregateKey()
{
AggregateKey = $"{Category.ToLower()}-{(Name ?? "Missing Name").ToLower()}-{MetricType}-{GetRoundedTime():s}";
}
public string CalcNameKey()
{
return $"{Category.ToLower()}-{(Name ?? "Missing Name").ToLower()}-{MetricType}";
}
public DateTime GetRoundedTime()
{
DateTime rounded;
rounded = Occurred.Floor(TimeSpan.FromMinutes(1));
return rounded;
}
}
public class LatestAggregate
{
public string Category { get; set; }
public string Name { get; set; }
public int? MetricID { get; set; }
public DateTime OccurredUtc { get; set; }
public double Value { get; set; }
public int Count { get; set; }
public MetricType MetricType { get; set; }
}
internal class MetricAggregate
{
public MetricAggregate(Metric metric)
{
Name = metric.Name;
Category = metric.Category;
MetricType = metric.MetricType;
Value = 0;
Count = 0;
NameKey = metric.CalcNameKey();
OccurredUtc = metric.GetRoundedTime();
IsIncrement = metric.IsIncrement;
}
public MetricAggregate(string category, string name, MetricType metricType, bool isIncrement)
{
Value = 0;
Name = name;
Category = category;
MetricType = metricType;
IsIncrement = isIncrement;
}
public int Count { get; set; }
public string Category { get; private set; }
public string Name { get; private set; }
public double Value { get; set; }
public DateTime OccurredUtc { get; set; }
public int? MonitorID { get; set; }
public MetricType MetricType { get; private set; }
public string NameKey { get; set; }
public bool IsIncrement { get; set; }
public string AggregateKey()
{
var r = $"{(Category ?? "Missing Category").ToLower()}-{(Name ?? "Missing Name").ToLower()}-{MetricType}-{OccurredUtc.Floor(TimeSpan.FromMinutes(1)):s}";
return r;
}
}
internal class GetMetricRequest
{
public string Category { get; set; }
public string MetricName { get; set; }
public int? DeviceID { get; set; }
public int? DeviceAppID { get; set; }
public Guid? AppNameID { get; set; }
public int MetricTypeID { get; set; }
}
internal class GetMetricResponse
{
public int? MonitorID { get; set; }
}
public class SubmitMetricByIDModel
{
public int MonitorID { get; set; }
public double Value { get; set; }
public int Count { get; set; }
public DateTime OccurredUtc { get; set; }
public short? MonitorTypeID { get; set; }
public int? ClientDeviceID { get; set; }
}
}