Skip to content

Commit cd8dbeb

Browse files
authored
Merge pull request #139 from incertum/update/docs-aug-2025
2 parents e3e9569 + 9c7e444 commit cd8dbeb

File tree

5 files changed

+283
-112
lines changed

5 files changed

+283
-112
lines changed

README.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,35 @@
33
[![sswg:sandbox](https://img.shields.io/badge/sswg-sandbox-yellow.svg)][SSWG-Incubation]
44
[![Documentation](http://img.shields.io/badge/read_the-docs-2196f3.svg)][Documentation]
55

6-
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).
97

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.
119

12-
Please see [SECURITY.md](SECURITY.md) for details on the security process.
10+
## Installation and Usage
1311

14-
## Contributing
12+
Please refer to the [Documentation][Documentation] for installation, usage instructions, and implementation details including Prometheus standards compliance.
1513

16-
All contributions are most welcome!
14+
For general Prometheus guidance, see [Prometheus Monitoring System][prometheus-docs].
1715

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
2017

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.
2219

23-
[Documentation]: https://swiftpackageindex.com/swift-server/swift-prometheus/documentation/prometheus
24-
[SSWG-Incubation]: https://www.swift.org/sswg/incubation-process.html
20+
## Contributing
2521

22+
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.
2623

2724
## Benchmarks
2825

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+
3428
```
3529
swift package benchmark
3630
```
3731

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).
33+
34+
35+
[Documentation]: https://swiftpackageindex.com/swift-server/swift-prometheus/documentation/prometheus
36+
[prometheus-docs]: https://prometheus.io/docs/introduction/overview/
37+
[SSWG-Incubation]: https://www.swift.org/sswg/incubation-process.html

Sources/Prometheus/Docs.docc/index.md

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# ``Prometheus``
22

3-
A prometheus client library for Swift.
3+
A Swift client library for the Prometheus Monitoring System.
44

55
## Overview
66

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.
98

10-
``Prometheus`` integrates with [Swift Metrics](doc:swift-metrics).
9+
#### Key Features
1110

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.
12+
- *Flexible Metric Labeling*: Supports flexible metric label structures with consistency guarantees.
13+
- *Thread Safe and Type-Safe*.
14+
- *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].
1317

1418
## Installation
1519

@@ -40,41 +44,61 @@ In your Swift file you must first `import Prometheus`:
4044
import Prometheus
4145
```
4246

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``:
4548

4649
```swift
4750
let registry = PrometheusCollectorRegistry()
4851

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+
)
5164

52-
let myGauge = registry.makeGauge(name: "my_gauge")
53-
myGauge.increment()
54-
myGauge.decrement()
65+
httpRequestsGet.increment(by: 5.0)
5566
```
5667

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:
5969

6070
```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
77+
# TYPE myapp_http_requests_total counter
78+
myapp_http_requests_total{method="GET",status="200"} 5.0
79+
```
80+
81+
Unregister a ``Counter``:
6482

65-
print(String(decoding: buffer, as: Unicode.UTF8.self))
83+
```swift
84+
registry.unregisterCounter(httpRequestsGet)
6685
```
6786

87+
Explore a detailed usage guide at <doc:labels>.
88+
89+
6890
## Topics
6991

70-
### Getting started
92+
### Getting Started
7193

72-
- <doc:swift-metrics>
7394
- <doc:labels>
95+
- <doc:swift-metrics>
96+
97+
### Registry
98+
7499
- ``PrometheusCollectorRegistry``
75100
- ``PrometheusMetricsFactory``
76101

77-
78102
### Metrics
79103

80104
- ``Counter``
@@ -83,4 +107,8 @@ print(String(decoding: buffer, as: Unicode.UTF8.self))
83107
- ``DurationHistogram``
84108
- ``ValueHistogram``
85109

110+
### Configuration
111+
112+
- ``MetricNameDescriptor``
113+
86114
[prometheus-docs]: https://prometheus.io/docs/introduction/overview/

0 commit comments

Comments
 (0)