Skip to content

Move to docc documentation #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
--extensionacl on-declarations
--disable typeSugar

# rules
# rules
18 changes: 14 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0
// swift-tools-version:5.6
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
Expand All @@ -23,19 +23,29 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),

// ~~~ SwiftPM Plugins ~~~
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: ["CoreMetrics"]
dependencies: [
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.target(
name: "MetricsTestUtils",
dependencies: ["Metrics", "CoreMetrics"]
dependencies: [
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: ["SystemMetrics"]
dependencies: [
"SystemMetrics",
]
),
]
)
41 changes: 41 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swift-tools-version:5.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
//
// Copyright (c) 2018-2019 Apple Inc. and the Swift Metrics API project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Metrics API project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-metrics-extras",
products: [
.library(name: "SystemMetrics", targets: ["SystemMetrics"]),
.library(name: "MetricsTestUtils", targets: ["MetricsTestUtils"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: ["CoreMetrics"]
),
.target(
name: "MetricsTestUtils",
dependencies: ["Metrics", "CoreMetrics"]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: ["SystemMetrics"]
),
]
)
41 changes: 41 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// swift-tools-version:5.1
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
//
// Copyright (c) 2018-2019 Apple Inc. and the Swift Metrics API project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Metrics API project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-metrics-extras",
products: [
.library(name: "SystemMetrics", targets: ["SystemMetrics"]),
.library(name: "MetricsTestUtils", targets: ["MetricsTestUtils"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: ["CoreMetrics"]
),
.target(
name: "MetricsTestUtils",
dependencies: ["Metrics", "CoreMetrics"]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: ["SystemMetrics"]
),
]
)
48 changes: 48 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// swift-tools-version:5.2
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
//
// Copyright (c) 2018-2019 Apple Inc. and the Swift Metrics API project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Metrics API project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-metrics-extras",
products: [
.library(name: "SystemMetrics", targets: ["SystemMetrics"]),
.library(name: "MetricsTestUtils", targets: ["MetricsTestUtils"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: [
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.target(
name: "MetricsTestUtils",
dependencies: [
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: [
"SystemMetrics",
]
),
]
)
48 changes: 48 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// swift-tools-version:5.3
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
//
// Copyright (c) 2018-2019 Apple Inc. and the Swift Metrics API project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Metrics API project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-metrics-extras",
products: [
.library(name: "SystemMetrics", targets: ["SystemMetrics"]),
.library(name: "MetricsTestUtils", targets: ["MetricsTestUtils"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: [
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.target(
name: "MetricsTestUtils",
dependencies: [
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: [
"SystemMetrics",
]
),
]
)
48 changes: 48 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// swift-tools-version:5.4
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
//
// Copyright (c) 2018-2019 Apple Inc. and the Swift Metrics API project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Metrics API project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-metrics-extras",
products: [
.library(name: "SystemMetrics", targets: ["SystemMetrics"]),
.library(name: "MetricsTestUtils", targets: ["MetricsTestUtils"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: [
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.target(
name: "MetricsTestUtils",
dependencies: [
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: [
"SystemMetrics",
]
),
]
)
48 changes: 48 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// swift-tools-version:5.5
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Metrics API open source project
//
// Copyright (c) 2018-2019 Apple Inc. and the Swift Metrics API project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Swift Metrics API project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import PackageDescription

let package = Package(
name: "swift-metrics-extras",
products: [
.library(name: "SystemMetrics", targets: ["SystemMetrics"]),
.library(name: "MetricsTestUtils", targets: ["MetricsTestUtils"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.3.2"),
],
targets: [
.target(
name: "SystemMetrics",
dependencies: [
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.target(
name: "MetricsTestUtils",
dependencies: [
.product(name: "Metrics", package: "swift-metrics"),
.product(name: "CoreMetrics", package: "swift-metrics"),
]
),
.testTarget(
name: "SystemMetricsTests",
dependencies: [
"SystemMetrics",
]
),
]
)
56 changes: 1 addition & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ or other such metric system agnostic metrics additions–such additions are perf
To add a dependency on the extras package, you need to declare it in your `Package.swift`:

```swift
.package(url: "https://github.com/apple/swift-metrics-extras.git", "1.0.0" ..< "2.0.0"),
.package(url: "https://github.com/apple/swift-metrics-extras.git", from: "0.1.0"),
```

and to your application/library target, add the specific module you would like to depend on to your dependencies:
Expand All @@ -37,57 +37,3 @@ Swift Metrics Extras ships the following extra modules:

- [System Metrics](Sources/SystemMetrics)
- [MetricsTestUtils](Sources/MetricsTestUtils)

### System Metrics

The System Metrics package provides default process metrics for applications. The following metrics are exposed:

- Virtual memory in Bytes.
- Resident memory in Bytes.
- Application start time in Seconds.
- Total CPU seconds.
- Maximum number of file descriptors.
- Number of file descriptors currently in use.

***NOTE:*** Currently these metrics are only implemented on Linux platforms, and not on Darwin or Windows.

#### Using System Metrics

After [adding swift-metrics-extras as a dependency](#adding-the-dependency) you can import the `SystemMetrics` module.

```swift
import SystemMetrics
```

This makes the System Metrics API available. This adds a new method to `MetricsSystem` called `bootstrapWithSystemMetrics`. Calling this method will call `MetricsSystem.bootstrap` as well as bootstrapping System Metrics.

`bootstrapWithSystemMetrics` takes a `SystemMetrics.Configuration` object to configure the system metrics. The config has the following properties:

- interval: The interval at which SystemMetrics are being calculated & exported.
- dataProvider: A closure returing `SystemMetrics.Data?`. When `nil` no metrics are exported (the default on non-linux platforms). `SystemMetrics.Data` holds all the values mentioned above.
- labels: `SystemMetrics.Labels` hold a string label for each of the above mentioned metrics that will be used for the metric labels, along with a prefix that will be used for all above mentioned metrics.

Swift Metrics backend implementations are encouraged to provide static extensions to `SystemMetrics.Configuration` that fit the requirements of their specific backends. For example:
```swift
public extension SystemMetrics.Configuration {
/// `SystemMetrics.Configuration` with Prometheus style labels.
///
/// For more information see `SystemMetrics.Configuration`
static let prometheus = SystemMetrics.Configuration(
labels: .init(
prefix: "process_",
virtualMemoryBytes: "virtual_memory_bytes",
residentMemoryBytes: "resident_memory_bytes",
startTimeSeconds: "start_time_seconds",
cpuSecondsTotal: "cpu_seconds_total",
maxFds: "max_fds",
openFds: "open_fds"
)
)
}
```
This allows end users to add System Metrics like this:

```swift
MetricsSystem.bootstrapWithSystemMetrics(myPrometheusInstance, config: .prometheus)
```
Loading