forked from swift-server/swift-prometheus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.swift
120 lines (110 loc) · 3.3 KB
/
main.swift
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
import Prometheus
import Metrics
import NIO
let myProm = PrometheusClient()
MetricsSystem.bootstrap(PrometheusMetricsFactory(client: myProm))
//for _ in 0...Int.random(in: 10...100) {
// let c = Counter(label: "test")
// c.increment()
//}
for _ in 0...Int.random(in: 10...100) {
let c = Counter(label: "test", dimensions: [("abc", "123")])
c.increment()
}
//for _ in 0...Int.random(in: 100...500_000) {
// let r = Recorder(label: "recorder")
// r.record(Double.random(in: 0...20))
//}
//
//for _ in 0...Int.random(in: 100...500_000) {
// let g = Gauge(label: "non_agg_recorder")
// g.record(Double.random(in: 0...20))
//}
//
//for _ in 0...Int.random(in: 100...500_000) {
// let t = Timer(label: "timer")
// t.recordMicroseconds(Double.random(in: 20...150))
//}
//
//for _ in 0...Int.random(in: 100...500_000) {
// let r = Recorder(label: "recorder", dimensions: [("abc", "123")])
// r.record(Double.random(in: 0...20))
//}
//
//for _ in 0...Int.random(in: 100...500_000) {
// let g = Gauge(label: "non_agg_recorder", dimensions: [("abc", "123")])
// g.record(Double.random(in: 0...20))
//}
//
//for _ in 0...Int.random(in: 100...500_000) {
// let t = Timer(label: "timer", dimensions: [("abc", "123")])
// t.recordMicroseconds(Double.random(in: 20...150))
//}
//struct MyCodable: MetricLabels {
// var thing: String = "*"
//}
//
//let codable1 = MyCodable(thing: "Thing1")
//let codable2 = MyCodable(thing: "Thing2")
//
//let counter = myProm.createCounter(forType: Int.self, named: "my_counter", helpText: "Just a counter", initialValue: 12, withLabelType: MyCodable.self)
//
//counter.inc(5)
//counter.inc(Int.random(in: 0...100), codable2)
//counter.inc(Int.random(in: 0...100), codable1)
//
//let gauge = myProm.createGauge(forType: Int.self, named: "my_gauge", helpText: "Just a gauge", initialValue: 12, withLabelType: MyCodable.self)
//
//gauge.inc(100)
//gauge.inc(Int.random(in: 0...100), codable2)
//gauge.inc(Int.random(in: 0...100), codable1)
//
//struct HistogramThing: HistogramLabels {
// var le: String = ""
// let route: String
//
// init() {
// self.route = "*"
// }
//
// init(_ route: String) {
// self.route = route
// }
//}
//
//let histogram = myProm.createHistogram(forType: Double.self, named: "my_histogram", helpText: "Just a histogram", labels: HistogramThing.self)
//
//for _ in 0...Int.random(in: 10...50) {
// histogram.observe(Double.random(in: 0...1))
//}
//
//for _ in 0...Int.random(in: 10...50) {
// histogram.observe(Double.random(in: 0...1), HistogramThing("/test"))
//}
//
//struct SummaryThing: SummaryLabels {
// var quantile: String = ""
// let route: String
//
// init() {
// self.route = "*"
// }
//
// init(_ route: String) {
// self.route = route
// }
//}
//
//let summary = myProm.createSummary(forType: Double.self, named: "my_summary", helpText: "Just a summary", labels: SummaryThing.self)
//
//for _ in 0...Int.random(in: 100...1000) {
// summary.observe(Double.random(in: 0...10000))
//}
//
//for _ in 0...Int.random(in: 100...1000) {
// summary.observe(Double.random(in: 0...10000), SummaryThing("/test"))
//}
let elg = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let prom = elg.next().makePromise(of: String.self)
try! MetricsSystem.prometheus().collect(prom.succeed)
print(try! prom.futureResult.wait())