Giter Site home page Giter Site logo

absinthe-metrics's Introduction

AbsintheMetrics

Build Status Module Version Hex Docs Total Download License Last Updated

AbsintheMetrics provides time (or counter) based metrics for your Absinthe resolvers to allow you to keep track of where your queries are spending their time.

Usage is fairly straight forward:

defmodule MyApp.Instrumenter do
  use AbsintheMetrics,
    adapter: AbsintheMetrics.Backend.PrometheusHistogram,
    # See prometheus.ex for more examples
    arguments: [buckets: {:exponential, 250, 1.5, 7}]
end

defmodule MyApp.Schema do
  use Absinthe.Schema
  def middleware(middlewares, field, object) do
    MyApp.Instrumenter.instrument(middlewares, field, object)
  end
end

# in application.ex

defmodule MyApp do
  def start(_type, _args) do
    # initialize all available metrics in your schema
    MyApp.Instrumenter.install(MyApp.Schema)
    # ...
  end
end

How metrics are gathered depends on the backend, but for PrometheusHistogram the format is #{object}_#{field}_duration_microseconds or query_field_duration_microseconds for root queries.

Adding backends

Adding additional backends is pretty straight forward, you just need to implement the AbsintheMetrics behaviour,

defmodule LogBackend do
  @behaviour AbsintheMetrics
  require Logger

  # Called during application start to allow you to register
  # fields with your TSDB
  def field(object, field, _args \\ []) do
    Logger.info("install field #{object}_#{field}")
  end

  # Called every time a value is observed
  # status can be :ok or :error
  def instrument(object, field, {status, _result}, time) do
    metric = "#{object}_#{field}"
    case status do
      :error -> Logger.warn("#{metric} failed (took: #{inspect time})")
      :ok -> Logger.info("#{metric} took: #{inspect time}")
    end
  end
end

Installation

The package can be installed by adding :absinthe_metrics to your list of dependencies in mix.exs:

def deps do
  [
    {:absinthe_metrics, "~> 0.9.0"}
  ]
end

Copyright and License

Copyright (c) 2017 Soundtrack Your Brand

This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE.md file for more details.

absinthe-metrics's People

Contributors

azhi avatar dylan-chong avatar fredr avatar frekw avatar kianmeng avatar

Watchers

 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.