1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public License,
3  * v. 2.0. If a copy of the MPL was not distributed with this file, You can
4  * obtain one at http://mozilla.org/MPL/2.0/.
5  */
6 
7 module prometheus.metric;
8 
9 import prometheus.registry;
10 
11 abstract class Metric
12 {
13     string name;
14     string help;
15     string[] labels;
16 
17     void observe(double value, string[] labelValues);
18 
19     MetricSnapshot collect();
20 
21     Metric register()
22     {
23         return this.register(Registry.global);
24     }
25 
26     Metric register(Registry reg)
27     {
28         reg.register(this);
29         return this;
30     }
31 
32     /// I hate this hack, but it's what I have
33     final static long posixTime()
34     {
35         import core.time : convert;
36         import std.datetime : Clock, DateTime, SysTime, UTC;
37 
38         enum posixEpochAsStd = SysTime(
39             DateTime(1970, 1, 1, 0, 0, 0),
40             UTC()
41         ).stdTime;
42 
43         return (Clock.currTime.toUTC.stdTime - posixEpochAsStd).convert!("hnsecs", "msecs");
44     }
45 }
46 
47 enum EncodingFormat
48 {
49     text,
50     proto
51 }
52 
53 abstract class MetricSnapshot
54 {
55     ubyte[] encode(EncodingFormat fmt = EncodingFormat.text);
56 }
57 
58 class EncodeTextUtils
59 {
60 }