Skip to content

Commit 802ee7c

Browse files
authored
Merge pull request #136 from PrometheusClientNet/counter-incTo
IncTo and DecTo method for counter and gauge
2 parents cc85720 + 57598c8 commit 802ee7c

27 files changed

+2552
-5
lines changed

src/Prometheus.Client.Abstractions/CounterExtensions.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public static void Inc(this ICounter counter, double increment, DateTimeOffset t
1212
counter.Inc(increment, timestamp.ToUnixTimeMilliseconds());
1313
}
1414

15+
public static void IncTo(this ICounter counter, double value, DateTimeOffset timestamp)
16+
{
17+
counter.IncTo(value, timestamp.ToUnixTimeMilliseconds());
18+
}
19+
1520
public static void Inc(this IMetricFamily<ICounter> metricFamily, double increment = 1)
1621
{
1722
metricFamily.Unlabelled.Inc(increment);
@@ -27,6 +32,21 @@ public static void Inc(this IMetricFamily<ICounter> metricFamily, double increme
2732
metricFamily.Unlabelled.Inc(increment, timestamp);
2833
}
2934

35+
public static void IncTo(this IMetricFamily<ICounter> metricFamily, double value)
36+
{
37+
metricFamily.Unlabelled.IncTo(value);
38+
}
39+
40+
public static void IncTo(this IMetricFamily<ICounter> metricFamily, double value, long timestamp)
41+
{
42+
metricFamily.Unlabelled.IncTo(value, timestamp);
43+
}
44+
45+
public static void IncTo(this IMetricFamily<ICounter> metricFamily, double value, DateTimeOffset timestamp)
46+
{
47+
metricFamily.Unlabelled.IncTo(value, timestamp);
48+
}
49+
3050
public static void Inc<TLabels>(this IMetricFamily<ICounter, TLabels> metricFamily, double increment = 1)
3151
#if HasITuple
3252
where TLabels : struct, ITuple, IEquatable<TLabels>
@@ -57,6 +77,36 @@ public static void Inc<TLabels>(this IMetricFamily<ICounter, TLabels> metricFami
5777
metricFamily.Unlabelled.Inc(increment, timestamp);
5878
}
5979

80+
public static void IncTo<TLabels>(this IMetricFamily<ICounter, TLabels> metricFamily, double value)
81+
#if HasITuple
82+
where TLabels : struct, ITuple, IEquatable<TLabels>
83+
#else
84+
where TLabels : struct, IEquatable<TLabels>
85+
#endif
86+
{
87+
metricFamily.Unlabelled.IncTo(value);
88+
}
89+
90+
public static void IncTo<TLabels>(this IMetricFamily<ICounter, TLabels> metricFamily, double value, long timestamp)
91+
#if HasITuple
92+
where TLabels : struct, ITuple, IEquatable<TLabels>
93+
#else
94+
where TLabels : struct, IEquatable<TLabels>
95+
#endif
96+
{
97+
metricFamily.Unlabelled.IncTo(value, timestamp);
98+
}
99+
100+
public static void IncTo<TLabels>(this IMetricFamily<ICounter, TLabels> metricFamily, double value, DateTimeOffset timestamp)
101+
#if HasITuple
102+
where TLabels : struct, ITuple, IEquatable<TLabels>
103+
#else
104+
where TLabels : struct, IEquatable<TLabels>
105+
#endif
106+
{
107+
metricFamily.Unlabelled.IncTo(value, timestamp);
108+
}
109+
60110
public static IMetricFamily<ICounter, ValueTuple<string>> CreateCounter(this IMetricFactory factory, string name, string help, string labelName, bool includeTimestamp = false)
61111
{
62112
return factory.CreateCounter(name, help, ValueTuple.Create(labelName), includeTimestamp);

src/Prometheus.Client.Abstractions/CounterInt64Extensions.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public static void Inc(this ICounter<long> counter, long increment, DateTimeOffs
1212
counter.Inc(increment, timestamp.ToUnixTimeMilliseconds());
1313
}
1414

15+
public static void IncTo(this ICounter<long> counter, long value, DateTimeOffset timestamp)
16+
{
17+
counter.IncTo(value, timestamp.ToUnixTimeMilliseconds());
18+
}
19+
1520
public static void Inc(this IMetricFamily<ICounter<long>> metricFamily, long increment = 1)
1621
{
1722
metricFamily.Unlabelled.Inc(increment);
@@ -27,6 +32,21 @@ public static void Inc(this IMetricFamily<ICounter<long>> metricFamily, long inc
2732
metricFamily.Unlabelled.Inc(increment, timestamp);
2833
}
2934

35+
public static void IncTo(this IMetricFamily<ICounter<long>> metricFamily, long value)
36+
{
37+
metricFamily.Unlabelled.IncTo(value);
38+
}
39+
40+
public static void IncTo(this IMetricFamily<ICounter<long>> metricFamily, long value, long timestamp)
41+
{
42+
metricFamily.Unlabelled.IncTo(value, timestamp);
43+
}
44+
45+
public static void IncTo(this IMetricFamily<ICounter<long>> metricFamily, long value, DateTimeOffset timestamp)
46+
{
47+
metricFamily.Unlabelled.IncTo(value, timestamp);
48+
}
49+
3050
public static void Inc<TLabels>(this IMetricFamily<ICounter<long>, TLabels> metricFamily, long increment = 1)
3151
#if HasITuple
3252
where TLabels : struct, ITuple, IEquatable<TLabels>
@@ -57,6 +77,36 @@ public static void Inc<TLabels>(this IMetricFamily<ICounter<long>, TLabels> metr
5777
metricFamily.Unlabelled.Inc(increment, timestamp);
5878
}
5979

80+
public static void IncTo<TLabels>(this IMetricFamily<ICounter<long>, TLabels> metricFamily, long value)
81+
#if HasITuple
82+
where TLabels : struct, ITuple, IEquatable<TLabels>
83+
#else
84+
where TLabels : struct, IEquatable<TLabels>
85+
#endif
86+
{
87+
metricFamily.Unlabelled.IncTo(value);
88+
}
89+
90+
public static void IncTo<TLabels>(this IMetricFamily<ICounter<long>, TLabels> metricFamily, long value, long timestamp)
91+
#if HasITuple
92+
where TLabels : struct, ITuple, IEquatable<TLabels>
93+
#else
94+
where TLabels : struct, IEquatable<TLabels>
95+
#endif
96+
{
97+
metricFamily.Unlabelled.IncTo(value, timestamp);
98+
}
99+
100+
public static void IncTo<TLabels>(this IMetricFamily<ICounter<long>, TLabels> metricFamily, long value, DateTimeOffset timestamp)
101+
#if HasITuple
102+
where TLabels : struct, ITuple, IEquatable<TLabels>
103+
#else
104+
where TLabels : struct, IEquatable<TLabels>
105+
#endif
106+
{
107+
metricFamily.Unlabelled.IncTo(value, timestamp);
108+
}
109+
60110
public static IMetricFamily<ICounter<long>, ValueTuple<string>> CreateCounterInt64(this IMetricFactory factory, string name, string help, string labelName, bool includeTimestamp = false)
61111
{
62112
return factory.CreateCounterInt64(name, help, ValueTuple.Create(labelName), includeTimestamp);

src/Prometheus.Client.Abstractions/GaugeExtensions.cs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ public static void Inc(this IGauge gauge, double increment, DateTimeOffset times
1212
gauge.Inc(increment, timestamp.ToUnixTimeMilliseconds());
1313
}
1414

15+
public static void IncTo(this IGauge gauge, double value, DateTimeOffset timestamp)
16+
{
17+
gauge.IncTo(value, timestamp.ToUnixTimeMilliseconds());
18+
}
19+
1520
public static void Inc(this IMetricFamily<IGauge> metricFamily, double increment = 1)
1621
{
1722
metricFamily.Unlabelled.Inc(increment);
@@ -27,21 +32,61 @@ public static void Inc(this IMetricFamily<IGauge> metricFamily, double increment
2732
metricFamily.Unlabelled.Inc(increment, timestamp.ToUnixTimeMilliseconds());
2833
}
2934

35+
public static void IncTo(this IMetricFamily<IGauge> metricFamily, double value)
36+
{
37+
metricFamily.Unlabelled.IncTo(value);
38+
}
39+
40+
public static void IncTo(this IMetricFamily<IGauge> metricFamily, double value, long timestamp)
41+
{
42+
metricFamily.Unlabelled.IncTo(value, timestamp);
43+
}
44+
45+
public static void IncTo(this IMetricFamily<IGauge> metricFamily, double value, DateTimeOffset timestamp)
46+
{
47+
metricFamily.Unlabelled.IncTo(value, timestamp.ToUnixTimeMilliseconds());
48+
}
49+
3050
public static void Dec(this IGauge gauge, double decrement, DateTimeOffset timestamp)
3151
{
3252
gauge.Dec(decrement, timestamp.ToUnixTimeMilliseconds());
3353
}
3454

55+
public static void DecTo(this IGauge gauge, double value, DateTimeOffset timestamp)
56+
{
57+
gauge.DecTo(value, timestamp.ToUnixTimeMilliseconds());
58+
}
59+
3560
public static void Dec(this IMetricFamily<IGauge> metricFamily, double decrement = 1)
3661
{
3762
metricFamily.Unlabelled.Dec(decrement);
3863
}
3964

65+
public static void Dec(this IMetricFamily<IGauge> metricFamily, double decrement, long timestamp)
66+
{
67+
metricFamily.Unlabelled.Dec(decrement, timestamp);
68+
}
69+
4070
public static void Dec(this IMetricFamily<IGauge> metricFamily, double decrement, DateTimeOffset timestamp)
4171
{
4272
metricFamily.Unlabelled.Dec(decrement, timestamp);
4373
}
4474

75+
public static void DecTo(this IMetricFamily<IGauge> metricFamily, double value)
76+
{
77+
metricFamily.Unlabelled.DecTo(value);
78+
}
79+
80+
public static void DecTo(this IMetricFamily<IGauge> metricFamily, double value, long timestamp)
81+
{
82+
metricFamily.Unlabelled.DecTo(value, timestamp);
83+
}
84+
85+
public static void DecTo(this IMetricFamily<IGauge> metricFamily, double value, DateTimeOffset timestamp)
86+
{
87+
metricFamily.Unlabelled.DecTo(value, timestamp);
88+
}
89+
4590
public static void Set(this IGauge gauge, double val, DateTimeOffset timestamp)
4691
{
4792
gauge.Set(val, timestamp.ToUnixTimeMilliseconds());
@@ -92,6 +137,36 @@ public static void Inc<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily
92137
metricFamily.Unlabelled.Inc(increment, timestamp);
93138
}
94139

140+
public static void IncTo<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value)
141+
#if HasITuple
142+
where TLabels : struct, ITuple, IEquatable<TLabels>
143+
#else
144+
where TLabels : struct, IEquatable<TLabels>
145+
#endif
146+
{
147+
metricFamily.Unlabelled.IncTo(value);
148+
}
149+
150+
public static void IncTo<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value, long timestamp)
151+
#if HasITuple
152+
where TLabels : struct, ITuple, IEquatable<TLabels>
153+
#else
154+
where TLabels : struct, IEquatable<TLabels>
155+
#endif
156+
{
157+
metricFamily.Unlabelled.IncTo(value, timestamp);
158+
}
159+
160+
public static void IncTo<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value, DateTimeOffset timestamp)
161+
#if HasITuple
162+
where TLabels : struct, ITuple, IEquatable<TLabels>
163+
#else
164+
where TLabels : struct, IEquatable<TLabels>
165+
#endif
166+
{
167+
metricFamily.Unlabelled.IncTo(value, timestamp);
168+
}
169+
95170
public static void Dec<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double decrement = 1)
96171
#if HasITuple
97172
where TLabels : struct, ITuple, IEquatable<TLabels>
@@ -102,6 +177,16 @@ public static void Dec<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily
102177
metricFamily.Unlabelled.Dec(decrement);
103178
}
104179

180+
public static void Dec<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double decrement, long timestamp)
181+
#if HasITuple
182+
where TLabels : struct, ITuple, IEquatable<TLabels>
183+
#else
184+
where TLabels : struct, IEquatable<TLabels>
185+
#endif
186+
{
187+
metricFamily.Unlabelled.Dec(decrement, timestamp);
188+
}
189+
105190
public static void Dec<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double decrement, DateTimeOffset timestamp)
106191
#if HasITuple
107192
where TLabels : struct, ITuple, IEquatable<TLabels>
@@ -112,6 +197,36 @@ public static void Dec<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily
112197
metricFamily.Unlabelled.Dec(decrement, timestamp);
113198
}
114199

200+
public static void DecTo<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value)
201+
#if HasITuple
202+
where TLabels : struct, ITuple, IEquatable<TLabels>
203+
#else
204+
where TLabels : struct, IEquatable<TLabels>
205+
#endif
206+
{
207+
metricFamily.Unlabelled.DecTo(value);
208+
}
209+
210+
public static void DecTo<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value, long timestamp)
211+
#if HasITuple
212+
where TLabels : struct, ITuple, IEquatable<TLabels>
213+
#else
214+
where TLabels : struct, IEquatable<TLabels>
215+
#endif
216+
{
217+
metricFamily.Unlabelled.DecTo(value, timestamp);
218+
}
219+
220+
public static void DecTo<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value, DateTimeOffset timestamp)
221+
#if HasITuple
222+
where TLabels : struct, ITuple, IEquatable<TLabels>
223+
#else
224+
where TLabels : struct, IEquatable<TLabels>
225+
#endif
226+
{
227+
metricFamily.Unlabelled.DecTo(value, timestamp);
228+
}
229+
115230
public static void Set<TLabels>(this IMetricFamily<IGauge, TLabels> metricFamily, double value)
116231
#if HasITuple
117232
where TLabels : struct, ITuple, IEquatable<TLabels>

0 commit comments

Comments
 (0)