Early releases of Application Metrics for Swift (SwiftMetrics) were difficult to get working for Xcode developers due to the use of dynamic libraries as plugins and the fact that SwiftMetrics previously expected them to be all in the same folder in a specified location. As a workaround it was possible to build SwiftMetrics outside of Xcode and then copy the built libraries (.dylib files) to the directory that SwiftMetrics expected to find them in, but this was not an ideal solution.

Application Metrics for Swift adds support for Xcode in version 1.2.0. SwiftMetrics can now be added as a dependency of your Swift project and metrics can either be gathered via the API or the dashboard can be launched. SwiftMetrics itself can also now be developed, debugged and tested in Xcode, which is great for the development team and anyone interested in getting involved in the project!

Screen shot of an application using SwiftMetrics in Xcode

Note: Open localhost:8080/swiftmetrics-dash to view the dashboard.

Sample Code

import SwiftMetricsDash
import SwiftMetrics
import Foundation
import Kitura

// Start SwiftMetrics
let sm = try SwiftMetrics()
let monitor = sm.monitor()

// Set up monitoring for latency data
func processLatency(latency: LatencyData) {
   print("Received a latency event")
}
monitor.on(processLatency)

// Start the dashboard
let router = Router()
let smd=try SwiftMetricsDash(swiftMetricsInstance : sm, endpoint: router)
Kitura.addHTTPServer(onPort: 8080, with: router)
Kitura.run()

Join The Discussion

Your email address will not be published. Required fields are marked *