You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,14 +8,35 @@ A prometheus client for Swift supporting counters, gauges, histograms, summaries
8
8
9
9
For examples, see [main.swift](./Sources/PrometheusExample/main.swift)
10
10
11
+
First, we have to create an instance of our `PrometheusClient`:
12
+
```swift
13
+
importPrometheus
14
+
let myProm =PrometheusClient()
15
+
```
16
+
17
+
## Usage with Swift-Metrics
18
+
_For more details about swift-metrics, check the GitHub repo [here](https://github.com/apple/swift-metrics)_
19
+
20
+
To use SwiftPrometheus with swift-metrics, all the setup required is this:
21
+
```swift
22
+
importPrometheusMetrics// Auto imports Prometheus too, but adds the swift-metrics compatibility
23
+
let myProm =PrometheusClient()
24
+
MetricsSystem.bootstrap(myProm)
25
+
```
26
+
27
+
To use prometheus specific features in a later stage of your program, or to get your metrics out of the system, there is a convenience method added to `MetricsSystem`:
28
+
```swift
29
+
// This is the same instance was used in `.bootstrap()` earlier.
30
+
let promInstance =try MetricsSystem.prometheus()
31
+
```
32
+
You can than use the same APIs that are layed out in the rest of this README
33
+
11
34
## Counter
12
35
13
36
Counters go up, and reset when the process restarts.
14
37
15
38
```swift
16
-
let prom =PrometheusClient()
17
-
18
-
let counter = prom.createCounter(forType: Int.self, named: "my_counter")
39
+
let counter = myProm.createCounter(forType: Int.self, named: "my_counter")
19
40
counter.inc() // Increment by 1
20
41
counter.inc(12) // Increment by given value
21
42
```
@@ -25,9 +46,7 @@ counter.inc(12) // Increment by given value
25
46
Gauges can go up and down
26
47
27
48
```swift
28
-
let prom =PrometheusClient()
29
-
30
-
let gauge = prom.createGauge(forType: Int.self, named: "my_gauge")
49
+
let gauge = myProm.createGauge(forType: Int.self, named: "my_gauge")
31
50
gauge.inc() // Increment by 1
32
51
gauge.dec(19) // Decrement by given value
33
52
gauge.set(12) // Set to a given value
@@ -38,9 +57,7 @@ gauge.set(12) // Set to a given value
38
57
Histograms track the size and number of events in buckets. This allows for aggregatable calculation of quantiles.
39
58
40
59
```swift
41
-
let prom =PrometheusClient()
42
-
43
-
let histogram = prom.createHistogram(forType: Double.self, named: "my_histogram")
60
+
let histogram = myProm.createHistogram(forType: Double.self, named: "my_histogram")
44
61
histogram.observe(4.7) // Observe the given value
45
62
```
46
63
@@ -49,9 +66,7 @@ histogram.observe(4.7) // Observe the given value
49
66
Summaries track the size and number of events
50
67
51
68
```swift
52
-
let prom =PrometheusClient()
53
-
54
-
let summary = prom.createSummary(forType: Double.self, named: "my_summary")
69
+
let summary = myProm.createSummary(forType: Double.self, named: "my_summary")
0 commit comments