目录
目录README.md

SwiftBox Metrics StatsD

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.

Build Status Swift 4.1 Linux MacOS

SwiftBoxMetricsStatsD

SatsD handler for official swift-metrics API.

Supported metric types:

  • Counters
  • Timers
  • Gauges

Usage

1. Import

import Metrics
import SwiftBoxMetricsStatsD

2. Bootstrap

Metrics 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 MetricsHandler implementation.
    // 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
         )
     }
    )

3. Usage

Detailed usage details may be found in official swift-metrics GitHub repository.

Handlers

LoggerMetricsHandler

Default handler for metrics that prints gathered metrics to console.

MetricsSystem.bootstrap(
    try StatsDMetricsFactory(
            baseMetricPath: "com.allegro"
    ) { path in
        LoggerMetricsHandler(path: path)
    }
)

StatsDMetricsHandler

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!
        )
    )
)
  • path is a path that metric will be recorder at.
  • client is a TCPStatsDClient or UDPStatsDClient instance.

Custom Handlers

To create custom handlers, conform to MetricsHandler or BaseMetricsHandler protocol.

邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号