Skip to content

NSMyself/swift-statsd-client

 
 

Repository files navigation

swift-statsd-client

CircleCI

A Statsd Client written in Swift that is transport protocol agnostic. UDP and HTTP are supported out of the box.

Requirements

  • iOS 9.0+ / macOS 10.11+ / tvOS 9.0+
  • Xcode 9.0+
  • Swift 4.0+

Usage

Initializing the client

UDP Client

let statsD = StatsD(transport: UDPTransport(host: "localhost", port: 2003))

TCPClient

let statsD = StatsD(transport: TCPTransport(host: "localhost", port: 2003))

HTTP CLient

let statsD = StatsD(transport: HTTPTransport(endpoint: URL(string: "https://localhost:8888/statsd")!)

And if you want to customize your HTTP request

let statsD: StatsD = {
    let configuration = URLSessionConfiguration()
    configuration.httpAdditionalHeaders = ["token": "Some Super Secret Token"]
    return StatsD(transport: HTTPTransport(endpoint: URL(string: "https://localhost:8888/statsd")!,
                                      configuration: configuration))
}()

Sending Data

statsD.increment("foo") # Increment 'foo' by 1
statsD.increment("foo", by: 10) # Increment 'foo' by 10
statsD.set("uniques", value: "someUniqueValue") # Add 'someUniqueValue' to the set
statsD.timing("api.foo.bar", value: 320) # Set time for api.foo.bar
statsD.gauge("gaugor", value: 10) # Set gauge to 10
statsD.gauge("gaugor", delta: -10) # Decrement gauge by 10

Installation

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

To integrate StatsD into your Xcode project using Carthage, specify it in your Cartfile:

github "khoiln/swift-statsd-client"

The project is currently configured to build for iOS, tvOS and Mac. After building with carthage the resultant frameworks will be stored in:

  • Carthage/Build/iOS/StatsdClient.framework
  • Carthage/Build/tvOS/StatsdClient.framework
  • Carthage/Build/Mac/StatsdClient.framework

Select the correct framework(s) and drag it into your project.

FAQ

Contributing

See Contributing.

License

swift-statsd-client is released under the MIT license. See LICENSE for details.

About

A Statsd Client written in Swift

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 93.4%
  • Ruby 6.6%