Skip to content

Commit 8e837ac

Browse files
committed
update: docs featuring latest improvements
Signed-off-by: Melissa Kilby <[email protected]>
1 parent e3e9569 commit 8e837ac

File tree

3 files changed

+257
-80
lines changed

3 files changed

+257
-80
lines changed

Sources/Prometheus/Docs.docc/index.md

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ A prometheus client library for Swift.
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+
- *Type Safe*: Prevents common configuration errors through Swift's type system.
13+
- *Thread Safe*: Operations use internal locking and conform to `Sendable`.
14+
- *Flexible Metric Labeling*: Supports flexible metric label structures with consistency guarantees.
15+
- *Swift Metrics Compatible*: Use the native Prometheus client API implemented in this library or integrate with [Swift Metrics](doc:swift-metrics).
16+
17+
For general Prometheus guidance, see the [Prometheus Documentation][prometheus-docs].
1318

1419
## Installation
1520

@@ -40,41 +45,61 @@ In your Swift file you must first `import Prometheus`:
4045
import Prometheus
4146
```
4247

43-
Next you need to create a ``PrometheusCollectorRegistry``, which you use to create ``Counter``s,
44-
``Gauge``s and ``Histogram``s.
48+
Create a ``PrometheusCollectorRegistry`` instance and register, for instance, a ``Counter``:
4549

4650
```swift
4751
let registry = PrometheusCollectorRegistry()
4852

49-
let myCounter = registry.makeCounter(name: "my_counter")
50-
myCounter.increment()
53+
let httpRequestsDescriptor = MetricNameDescriptor(
54+
namespace: "myapp",
55+
subsystem: "http",
56+
metricName: "requests",
57+
unitName: "total",
58+
helpText: "Total HTTP requests"
59+
)
60+
61+
let httpRequestsGet = registry.makeCounter(
62+
descriptor: httpRequestsDescriptor,
63+
labels: [("method", "GET"), ("status", "200")]
64+
)
5165

52-
let myGauge = registry.makeGauge(name: "my_gauge")
53-
myGauge.increment()
54-
myGauge.decrement()
66+
httpRequestsGet.increment(by: 5.0)
5567
```
5668

57-
Lastly, you can use your ``PrometheusCollectorRegistry`` to generate a Prometheus export in the
58-
text representation:
69+
Emit all registered metrics to the Prometheus text exposition format:
5970

6071
```swift
61-
var buffer = [UInt8]()
62-
buffer.reserveCapacity(1024) // potentially smart moves to reduce the number of reallocations
63-
registry.emit(into: &buffer)
72+
let output = registry.emitToString()
73+
print(output)
74+
```
75+
76+
```sh
77+
# HELP myapp_http_requests_total Total HTTP requests
78+
# TYPE myapp_http_requests_total counter
79+
myapp_http_requests_total{method="GET",status="200"} 5.0
80+
```
81+
82+
Unregister a ``Counter``:
6483

65-
print(String(decoding: buffer, as: Unicode.UTF8.self))
84+
```swift
85+
registry.unregisterCounter(httpRequestsGet)
6686
```
6787

88+
Explore a detailed usage guide at <doc:labels>.
89+
90+
6891
## Topics
6992

70-
### Getting started
93+
### Getting Started
7194

72-
- <doc:swift-metrics>
7395
- <doc:labels>
96+
- <doc:swift-metrics>
97+
98+
### Registry
99+
74100
- ``PrometheusCollectorRegistry``
75101
- ``PrometheusMetricsFactory``
76102

77-
78103
### Metrics
79104

80105
- ``Counter``
@@ -83,4 +108,8 @@ print(String(decoding: buffer, as: Unicode.UTF8.self))
83108
- ``DurationHistogram``
84109
- ``ValueHistogram``
85110

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

0 commit comments

Comments
 (0)