Skip to content

Commit e2fe1e5

Browse files
committed
Update README too
1 parent 2612857 commit e2fe1e5

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

README.md

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,51 @@ A prometheus client for Swift supporting counters, gauges, histograms, summaries
66

77
# Usage
88

9-
For examples, see [main.swift](./Sources/PrometheusExample/main.swift)
9+
To see a working demo, see [PrometheusExample](./Sources/PrometheusExample/main.swift).
1010

1111
First, we have to create an instance of our `PrometheusClient`:
12+
1213
```swift
1314
import Prometheus
1415
let myProm = PrometheusClient()
1516
```
1617

17-
## Usage with Swift-Metrics
18-
_For more details about swift-metrics, check the GitHub repo [here](https://github.com/apple/swift-metrics)_
18+
## Usage with SwiftMetrics
19+
_For more details about swift-metrics, please view [the GitHub repo](https://github.com/apple/swift-metrics)._
20+
21+
To use SwiftPrometheus with swift-metrics, you need to configure the backend inside the `MetricsSystem`:
1922

20-
To use SwiftPrometheus with swift-metrics, all the setup required is this:
2123
```swift
24+
import Metrics
2225
import Prometheus
23-
import PrometheusMetrics
2426
let myProm = PrometheusClient()
2527
MetricsSystem.bootstrap(myProm)
2628
```
2729

28-
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`:
30+
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`:
31+
2932
```swift
30-
// This is the same instance was used in `.bootstrap()` earlier.
33+
// This returns the same instance passed in to `.bootstrap()` earlier.
3134
let promInstance = try MetricsSystem.prometheus()
35+
print(promInstance.collect())
3236
```
33-
You can than use the same APIs that are layed out in the rest of this README
37+
38+
You can then use the same APIs described in the rest of this README.
3439

3540
## Counter
3641

37-
Counters go up, and reset when the process restarts.
42+
Counters go up (they can only increase in value), and reset when the process restarts.
3843

3944
```swift
4045
let counter = myProm.createCounter(forType: Int.self, named: "my_counter")
4146
counter.inc() // Increment by 1
42-
counter.inc(12) // Increment by given value
47+
counter.inc(12) // Increment by given value
48+
counter.reset() // Set the value back to 0
4349
```
4450

4551
## Gauge
4652

47-
Gauges can go up and down
53+
Gauges can go up and down, they represent a "point-in-time" snapshot of a value. This is similar to the sppedometer of a car.
4854

4955
```swift
5056
let gauge = myProm.createGauge(forType: Int.self, named: "my_gauge")
@@ -73,16 +79,16 @@ summary.observe(4.7) // Observe the given value
7379

7480
## Info
7581

76-
Info tracks key-value information, usually about a whole target.
82+
Info tracks key-value information, usually about a whole target. These are typically helpful details like git sha or other metadata.
7783

7884
```swift
7985
struct MyInfoStruct: MetricLabels {
8086
let value: String
81-
87+
8288
init() {
8389
self.value = "abc"
8490
}
85-
91+
8692
init(_ v: String) {
8793
self.value = v
8894
}
@@ -99,6 +105,7 @@ info.info(MyInfoStruct("def"))
99105
All metric types support adding labels, allowing for grouping of related metrics.
100106

101107
Example with a counter:
108+
102109
```swift
103110
struct RouteLabels: MetricLabels {
104111
var route: String = "*"
@@ -113,15 +120,15 @@ counter.inc(12, .init(route: "/"))
113120

114121
# Exporting
115122

116-
To keep SwiftPrometheus as clean and lightweight as possible, there is no way of exporting metrics directly to Prometheus. Instead, retrieve a formatted string that Prometheus can use, so you can integrate it in your own Serverside Swift application
123+
Prometheus itself is designed to "pull" metrics from a destination. Following this pattern, SwiftPrometheus is designed to expose metrics, as opposed to submitted/exporting them directly to Prometheus itself. Instead, SwiftPrometheus produces a formatted string that Prometheus can parse, which can be integrated into your own application.
124+
125+
By default, this should be accessible on your main serving port, at the `/metrics` endpoint. An example in [Vapor](https://vapor.codes) syntax looks like:
117126

118-
This could look something like this:
119127
```swift
120128
router.get("/metrics") { request -> String in
121129
return myProm.collect()
122130
}
123131
```
124-
Here, I used [Vapor](https://github.com/vapor/vapor) syntax, but this will work with any web framework, since it's just returning a plain String.
125132

126133
# Contributing
127134

0 commit comments

Comments
 (0)