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
A Swift client for the [Prometheus](https://github.com/prometheus/prometheus) monitoring system,
7
-
supporting counters, gauges and histograms. Swift Prometheus
8
-
implements the Swift Metrics API.
6
+
A Swift client library for [Prometheus Monitoring System](https://github.com/prometheus/prometheus).
9
7
10
-
## Security
8
+
`swift-prometheus` supports creating `Counter`s, `Gauge`s and `Histogram`s, updating metric values, and exposing their values in the Prometheus text format.
11
9
12
-
Please see [SECURITY.md](SECURITY.md) for details on the security process.
10
+
## Installation and Usage
13
11
14
-
## Contributing
12
+
Please refer to the [Documentation][Documentation] for installation, usage instructions, and implementation details including Prometheus standards compliance.
15
13
16
-
All contributions are most welcome!
14
+
For general Prometheus guidance, see [Prometheus Monitoring System][prometheus-docs].
17
15
18
-
If you think of some cool new feature that should be included, please [create an issue](https://github.com/swift-server/swift-prometheus/issues/new).
19
-
Or, if you want to implement it yourself, [fork this repo](https://github.com/swift-server/swift-prometheus/fork) and submit a PR!
16
+
## Security
20
17
21
-
If you find a bug or have issues, please [create an issue](https://github.com/swift-server-community/SwiftPrometheus/issues/new) explaining your problems. Please include as much information as possible, so it's easier for us to reproduce (Framework, OS, Swift version, terminal output, etc.)
18
+
Please see [SECURITY.md](SECURITY.md)for details on the security process.
We welcome all contributions to `swift-prometheus`! For feature requests or bug reports, please [create an issue](https://github.com/swift-server/swift-prometheus/issues/new) with detailed information including Swift version, platform, and reproduction steps. To contribute code, [fork this repo](https://github.com/swift-server/swift-prometheus/fork) and submit a pull request with tests and documentation updates.
26
23
27
24
## Benchmarks
28
25
29
-
Benchmarks for `swift-prometheus` are in a separate Swift Package in the `Benchmarks` subfolder of this repository.
30
-
They use the [`package-benchmark`](https://github.com/ordo-one/package-benchmark) plugin.
31
-
Benchmarks depends on the [`jemalloc`](https://jemalloc.net) memory allocation library, which is used by `package-benchmark` to capture memory allocation statistics.
32
-
An installation guide can be found in the [Getting Started article](https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark/gettingstarted#Installing-Prerequisites-and-Platform-Support) of `package-benchmark`.
33
-
Afterwards you can run the benchmarks from CLI by going to the `Benchmarks` subfolder (e.g. `cd Benchmarks`) and invoking:
26
+
Benchmarks are located in the [Benchmarks](/Benchmarks/) subfolder and use the [`package-benchmark`](https://github.com/ordo-one/package-benchmark) plugin. See the [Benchmarks Getting Started]((https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark/gettingstarted#Installing-Prerequisites-and-Platform-Support)) guide for installation instructions. Run benchmarks by navigating to Benchmarks and executing:
27
+
34
28
```
35
29
swift package benchmark
36
30
```
37
31
38
-
For more information please refer to `swift package benchmark --help` or the [documentation of `package-benchmark`](https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark).
32
+
For more information please refer to `swift package benchmark --help` or the [`package-benchmark` Documentation](https://swiftpackageindex.com/ordo-one/package-benchmark/documentation/benchmark).
Copy file name to clipboardExpand all lines: Sources/Prometheus/Docs.docc/index.md
+49-21Lines changed: 49 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,19 @@
1
1
# ``Prometheus``
2
2
3
-
A prometheus client library for Swift.
3
+
A Swift client library for the Prometheus Monitoring System.
4
4
5
5
## Overview
6
6
7
-
``Prometheus`` supports creating ``Counter``s, ``Gauge``s and ``Histogram``s and exporting their
8
-
values in the Prometheus text format.
7
+
``Prometheus`` supports creating ``Counter``s, ``Gauge``s and ``Histogram``s, updating metric values, and exposing their values in the Prometheus text format.
9
8
10
-
``Prometheus`` integrates with [Swift Metrics](doc:swift-metrics).
9
+
#### Key Features
11
10
12
-
For general advice on how to use `Prometheus` make sure to also read the [Prometheus documentation][prometheus-docs].
11
+
-*Standards Compliant*: Follows Prometheus naming conventions and exposition formats, enforces base guarantees.
-*Swift Metrics Compatible*: Use the native Prometheus client API implemented in this library or use [Swift Metrics](doc:swift-metrics) as a backend for this library.
15
+
16
+
For general Prometheus guidance, see the [Prometheus Monitoring System Documentation][prometheus-docs].
13
17
14
18
## Installation
15
19
@@ -40,41 +44,61 @@ In your Swift file you must first `import Prometheus`:
40
44
importPrometheus
41
45
```
42
46
43
-
Next you need to create a ``PrometheusCollectorRegistry``, which you use to create ``Counter``s,
44
-
``Gauge``s and ``Histogram``s.
47
+
Create a ``PrometheusCollectorRegistry`` instance and register, for instance, a ``Counter``:
45
48
46
49
```swift
47
50
let registry =PrometheusCollectorRegistry()
48
51
49
-
let myCounter = registry.makeCounter(name: "my_counter")
50
-
myCounter.increment()
52
+
let httpRequestsDescriptor =MetricNameDescriptor(
53
+
namespace: "myapp",
54
+
subsystem: "http",
55
+
metricName: "requests",
56
+
unitName: "total",
57
+
helpText: "Total HTTP requests"
58
+
)
59
+
60
+
let httpRequestsGet = registry.makeCounter(
61
+
descriptor: httpRequestsDescriptor,
62
+
labels: [("method", "GET"), ("status", "200")]
63
+
)
51
64
52
-
let myGauge = registry.makeGauge(name: "my_gauge")
53
-
myGauge.increment()
54
-
myGauge.decrement()
65
+
httpRequestsGet.increment(by: 5.0)
55
66
```
56
67
57
-
Lastly, you can use your ``PrometheusCollectorRegistry`` to generate a Prometheus export in the
58
-
text representation:
68
+
Emit all registered metrics to the Prometheus text exposition format:
59
69
60
70
```swift
61
-
var buffer = [UInt8]()
62
-
buffer.reserveCapacity(1024) // potentially smart moves to reduce the number of reallocations
63
-
registry.emit(into: &buffer)
71
+
let output = registry.emitToString()
72
+
print(output)
73
+
```
74
+
75
+
```sh
76
+
# HELP myapp_http_requests_total Total HTTP requests
0 commit comments