|
1 | 1 | import Prometheus |
2 | 2 |
|
3 | | -//struct MyCodable: MetricLabels { |
4 | | -// var thing: String = "*" |
5 | | -//} |
6 | | -// |
7 | | -//let codable1 = MyCodable(thing: "Thing1") |
8 | | -//let codable2 = MyCodable(thing: "Thing2") |
9 | | -// |
10 | | -//let counter = Prometheus.shared.createCounter(forType: Int.self, named: "my_counter", helpText: "Just a counter", initialValue: 12, withLabelType: MyCodable.self) |
11 | | -// |
12 | | -//counter.inc(5) |
13 | | -//counter.inc(Int.random(in: 0...100), codable2) |
14 | | -//counter.inc(Int.random(in: 0...100), codable1) |
15 | | -// |
16 | | -//let gauge = Prometheus.shared.createGauge(forType: Int.self, named: "my_gauge", helpText: "Just a gauge", initialValue: 12, withLabelType: MyCodable.self) |
17 | | -// |
18 | | -//gauge.inc(100) |
19 | | -//gauge.inc(Int.random(in: 0...100), codable2) |
20 | | -//gauge.inc(Int.random(in: 0...100), codable1) |
21 | | -// |
22 | | -//struct HistogramThing: HistogramLabels { |
23 | | -// var le: String = "" |
24 | | -// let route: String |
25 | | -// |
26 | | -// init() { |
27 | | -// self.route = "*" |
28 | | -// } |
29 | | -// |
30 | | -// init(_ route: String) { |
31 | | -// self.route = route |
32 | | -// } |
33 | | -//} |
34 | | -// |
35 | | -//let histogram = Prometheus.shared.createHistogram(forType: Double.self, named: "my_histogram", helpText: "Just a histogram", labels: HistogramThing.self) |
36 | | -// |
37 | | -//for _ in 0...Int.random(in: 10...50) { |
38 | | -// histogram.observe(Double.random(in: 0...1)) |
39 | | -//} |
40 | | -// |
41 | | -//for _ in 0...Int.random(in: 10...50) { |
42 | | -// histogram.observe(Double.random(in: 0...1), HistogramThing("/test")) |
43 | | -//} |
44 | | -// |
45 | | -//struct SummaryThing: SummaryLabels { |
46 | | -// var quantile: String = "" |
47 | | -// let route: String |
48 | | -// |
49 | | -// init() { |
50 | | -// self.route = "*" |
51 | | -// } |
52 | | -// |
53 | | -// init(_ route: String) { |
54 | | -// self.route = route |
55 | | -// } |
56 | | -//} |
57 | | -// |
58 | | -//let summary = Prometheus.shared.createSummary(forType: Double.self, named: "my_summary", helpText: "Just a summary", labels: SummaryThing.self) |
59 | | -// |
60 | | -//for _ in 0...Int.random(in: 100...1000) { |
61 | | -// summary.observe(Double.random(in: 0...10000)) |
62 | | -//} |
63 | | -// |
64 | | -//for _ in 0...Int.random(in: 100...1000) { |
65 | | -// summary.observe(Double.random(in: 0...10000), SummaryThing("/test")) |
66 | | -//} |
67 | | - |
68 | | -//struct MyInfoStruct: MetricLabels { |
69 | | -// let version: String |
70 | | -// let major: String |
71 | | -// |
72 | | -// init() { |
73 | | -// self.version = "1.0.0" |
74 | | -// self.major = "1" |
75 | | -// } |
76 | | -// |
77 | | -// init(_ v: String, _ m: String) { |
78 | | -// self.version = v |
79 | | -// self.major = m |
80 | | -// } |
81 | | -//} |
82 | | -// |
83 | | -//let info = Prometheus.shared.createInfo(named: "my_info", helpText: "Just some info", labelType: MyInfoStruct.self) |
84 | | -// |
85 | | -//info.info(MyInfoStruct("2.0.0", "2")) |
| 3 | +struct MyCodable: MetricLabels { |
| 4 | + var thing: String = "*" |
| 5 | +} |
| 6 | + |
| 7 | +let codable1 = MyCodable(thing: "Thing1") |
| 8 | +let codable2 = MyCodable(thing: "Thing2") |
| 9 | + |
| 10 | +let counter = Prometheus.shared.createCounter(forType: Int.self, named: "my_counter", helpText: "Just a counter", initialValue: 12, withLabelType: MyCodable.self) |
| 11 | + |
| 12 | +counter.inc(5) |
| 13 | +counter.inc(Int.random(in: 0...100), codable2) |
| 14 | +counter.inc(Int.random(in: 0...100), codable1) |
| 15 | + |
| 16 | +let gauge = Prometheus.shared.createGauge(forType: Int.self, named: "my_gauge", helpText: "Just a gauge", initialValue: 12, withLabelType: MyCodable.self) |
| 17 | + |
| 18 | +gauge.inc(100) |
| 19 | +gauge.inc(Int.random(in: 0...100), codable2) |
| 20 | +gauge.inc(Int.random(in: 0...100), codable1) |
| 21 | + |
| 22 | +struct HistogramThing: HistogramLabels { |
| 23 | + var le: String = "" |
| 24 | + let route: String |
| 25 | + |
| 26 | + init() { |
| 27 | + self.route = "*" |
| 28 | + } |
| 29 | + |
| 30 | + init(_ route: String) { |
| 31 | + self.route = route |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +let histogram = Prometheus.shared.createHistogram(forType: Double.self, named: "my_histogram", helpText: "Just a histogram", labels: HistogramThing.self) |
| 36 | + |
| 37 | +for _ in 0...Int.random(in: 10...50) { |
| 38 | + histogram.observe(Double.random(in: 0...1)) |
| 39 | +} |
| 40 | + |
| 41 | +for _ in 0...Int.random(in: 10...50) { |
| 42 | + histogram.observe(Double.random(in: 0...1), HistogramThing("/test")) |
| 43 | +} |
| 44 | + |
| 45 | +struct SummaryThing: SummaryLabels { |
| 46 | + var quantile: String = "" |
| 47 | + let route: String |
| 48 | + |
| 49 | + init() { |
| 50 | + self.route = "*" |
| 51 | + } |
| 52 | + |
| 53 | + init(_ route: String) { |
| 54 | + self.route = route |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +let summary = Prometheus.shared.createSummary(forType: Double.self, named: "my_summary", helpText: "Just a summary", labels: SummaryThing.self) |
| 59 | + |
| 60 | +for _ in 0...Int.random(in: 100...1000) { |
| 61 | + summary.observe(Double.random(in: 0...10000)) |
| 62 | +} |
| 63 | + |
| 64 | +for _ in 0...Int.random(in: 100...1000) { |
| 65 | + summary.observe(Double.random(in: 0...10000), SummaryThing("/test")) |
| 66 | +} |
| 67 | + |
| 68 | +struct MyInfoStruct: MetricLabels { |
| 69 | + let version: String |
| 70 | + let major: String |
| 71 | + |
| 72 | + init() { |
| 73 | + self.version = "1.0.0" |
| 74 | + self.major = "1" |
| 75 | + } |
| 76 | + |
| 77 | + init(_ v: String, _ m: String) { |
| 78 | + self.version = v |
| 79 | + self.major = m |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +let info = Prometheus.shared.createInfo(named: "my_info", helpText: "Just some info", labelType: MyInfoStruct.self) |
| 84 | + |
| 85 | +info.info(MyInfoStruct("2.0.0", "2")) |
86 | 86 |
|
87 | 87 | print(Prometheus.shared.getMetrics()) |
0 commit comments