-
Notifications
You must be signed in to change notification settings - Fork 23
[docs] organization, style, and grammar updates #81
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
Changes from all commits
d01f521
8ca1c01
ec5253f
bed4a8f
7b0f3fb
e31d564
43a8171
c670dae
cebd6d9
cff9040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,75 @@ | ||||||||||||
| # Capturing and reporting process metrics | ||||||||||||
|
|
||||||||||||
| Use the system metrics monitor in your application to provide metrics from the process where you run your service. | ||||||||||||
|
|
||||||||||||
| ### Add the project dependency | ||||||||||||
|
|
||||||||||||
| Add `swift-system-metrics` as a dependency to your app and executable target: | ||||||||||||
|
|
||||||||||||
| ```bash | ||||||||||||
| swift package add-dependency https://github.com/apple/swift-system-metrics --from 1.0.0 | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ```bash | ||||||||||||
| swift package add-target-dependency SystemMetrics MyExecutableTarget --package swift-system-metrics | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ### Create a system monitor service | ||||||||||||
|
|
||||||||||||
| Import the `SystemMetrics` module, then create and add a ``SystemMetricsMonitor`` to a service group. | ||||||||||||
|
|
||||||||||||
| ```swift | ||||||||||||
| import SystemMetrics | ||||||||||||
| // Import and create a logger, or use one of the existing loggers | ||||||||||||
| import Logging | ||||||||||||
|
|
||||||||||||
| let logger = Logger(label: "MyService") | ||||||||||||
|
|
||||||||||||
| // Create the monitor | ||||||||||||
| let systemMetricsMonitor = SystemMetricsMonitor(logger: logger) | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| The monitor collects and reports metrics periodically using the global `MetricsSystem` that Swift Metrics provides. | ||||||||||||
| You can configure the polling interval with your own ``SystemMetricsMonitor/Configuration``, as well as the `MetricsSystem`, when you create the monitor: | ||||||||||||
|
|
||||||||||||
| ```swift | ||||||||||||
| let systemMetricsMonitor = SystemMetricsMonitor( | ||||||||||||
| configuration: .init(pollInterval: .seconds(5)), | ||||||||||||
| logger: logger | ||||||||||||
|
Comment on lines
+37
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we want to promote the initializer with the custom factory as a baseline expectation? I got the impression that the one without would be more commonly used/desired here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggested the change because the text above it mentions the factory. It was strange to mention it without showing the code. But we can also remove it and also remove the mention in the text, either is fine. |
||||||||||||
| ) | ||||||||||||
| ``` | ||||||||||||
|
|
||||||||||||
| ### Run the service in your app | ||||||||||||
|
|
||||||||||||
| Use [Swift Service Lifecycle](https://github.com/swift-server/swift-service-lifecycle) to run the monitor as a background service with support for graceful shutdown and UNIX signal handling. | ||||||||||||
| To do so, include the system metrics monitor you created in a service group and run the group in your application. | ||||||||||||
|
|
||||||||||||
| The following code bootstraps your own metrics backend, creates a system metrics monitor, and uses service lifecycle to run both: | ||||||||||||
|
|
||||||||||||
| ```swift | ||||||||||||
| import SystemMetrics | ||||||||||||
| import ServiceLifecycle | ||||||||||||
| import Metrics | ||||||||||||
heckj marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
| import Logging | ||||||||||||
|
|
||||||||||||
| @main | ||||||||||||
| struct Application { | ||||||||||||
| static func main() async throws { | ||||||||||||
| let logger = Logger(label: "Application") | ||||||||||||
| let metrics = MyMetricsBackendImplementation() | ||||||||||||
| MetricsSystem.bootstrap(metrics) | ||||||||||||
|
|
||||||||||||
| let service = FooService() | ||||||||||||
| let systemMetricsMonitor = SystemMetricsMonitor(logger: logger) | ||||||||||||
|
|
||||||||||||
| let serviceGroup = ServiceGroup( | ||||||||||||
| services: [service, systemMetricsMonitor], | ||||||||||||
| gracefulShutdownSignals: [.sigint], | ||||||||||||
| cancellationSignals: [.sigterm], | ||||||||||||
| logger: logger | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| try await serviceGroup.run() | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
| ``` | ||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # ``SystemMetricsMonitor/Configuration`` | ||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a monitor configuration | ||
|
|
||
| - ``init(pollInterval:)`` | ||
| - ``default`` | ||
|
|
||
| ### Inspecting the configuration | ||
|
|
||
| - ``interval`` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # ``SystemMetricsMonitor`` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been meaning to ask - what's the docc command to generate these? Or did you hand-write them?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol - I hand wrote these. There's not a DocC command to generate them one off, unfortunately- I've just got 'my pattern' of how I do it, which it mostly stub, see what show's up in preview, then iterate to drop the right pieces into place. That said, there is a curation generation command - although I'm not certain if anyone actually uses it, as it's not detailed anywhere in the docs. The gist of which is:
So it's kind of a pain to use... |
||
|
|
||
| ## Topics | ||
|
|
||
| ### Creating a system metrics monitor | ||
|
|
||
| - ``init(configuration:logger:)`` | ||
| - ``init(configuration:metricsFactory:logger:)`` | ||
| - ``Configuration`` | ||
|
|
||
| ### Running a monitor | ||
|
|
||
| - ``run()`` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.