Coder Social home page Coder Social logo

swift-statsd-client's Introduction

Use zalora/swift-statsd-client for the updated version.

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

Sending metrics

statsD.write(metric: Counting(name: "counting", value: 1))
statsD.write(metric: Sets(name: "uniques", value: "765"))
statsD.write(metric: Timing(name: "glork", value: 320))
statsD.write(metric: Gauge(name: "gaugor", value: 333))

Sending metrics in batch - Keep in mind of your network's MTU Ref

There are helper functions so you don't have to create metric models.

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

And if you want to send raw metric data

statsD.write(payload: "foo:1|c") 

Accessing

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 "khoiracle/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.

swift-statsd-client's People

Contributors

cjrieck avatar khoi avatar nghiatranuit avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.