SwiftBox Metrics StatsD is a StatsD TCP/UDP client and and handler. Handler is compatible with official swift-metrics API.
Coming soon: Replace SwiftBoxLogging implementation in favor of official swift-log.
SatsD handler for official swift-metrics API.
Supported metric types:
- Counters
- Timers
- Gauges
import Metrics
import SwiftBoxMetricsStatsDMetrics must be bootstrap with Factory, that conforms to MetricsFactory protocol.
Default StatsDMetricsFactory accepts 2 parameters:
- baseMetricsPath: path that is prepended to every recorded metric path
- handlerFactory: Factory function that returns- MetricsHandlerimplementation.
// StatsD Handler initialization
let statsdClient = UDPStatsDClient(
   config: UDPConnectionConfig(
       host: "127.0.0.1",
       port: 1234
   )
)
MetricsSystem.bootstrap(
    try StatsDMetricsFactory(
            baseMetricPath: "com.allegro"
    ) { path in
        StatsDMetricsHandler(
            path: path,
            client: statsdClient
        )
    }
)Detailed usage details may be found in official swift-metrics GitHub repository.
Default handler for metrics that prints gathered metrics to console.
MetricsSystem.bootstrap(
    try StatsDMetricsFactory(
            baseMetricPath: "com.allegro"
    ) { path in
        LoggerMetricsHandler(path: path)
    }
)StatsD Metrics Handler responsible for sending gathered logs to statsD server. Supports TCP and UDP protocols. Metrics are sent in separate thread, so operation is non-blocking for application.
StatsDMetricsHandler(
    path: "com.allegro.counter",
    client: UDPStatsDClient(
        config: UDPConnectionConfig(
            host: AppConfig.global.statsd.host!,
            port: AppConfig.global.statsd.port!
        )
    )
)- pathis a path that metric will be recorder at.
- clientis a- TCPStatsDClientor- UDPStatsDClientinstance.
To create custom handlers, conform to MetricsHandler or BaseMetricsHandler protocol.