Airframe

Airframe

  • Docs
  • Blog
  • Release Notes
  • GitHub

›Utilities

Resources

  • Overview
  • Articles
  • Release Notes
  • Logos

Framework

  • airframe-di: Dependency Injection
  • Airframe RPC
  • airframe-http: Creating REST Service
  • airframe-rx: ReactiveX interface
  • AirSpec: Testing Framework

Core Modules

  • airframe-codec: Schema-On-Read Object Serializer
  • airframe-config: Application Config Flow
  • airframe-control: Retry/Rate Control
  • airframe-log: Application Logger
  • airframe-metrics: Human-Friendly Measures for Time and Data Size
  • airframe-surface: Object Shape Inspector

Utilities

  • airframe-benchmark: JMH Benchmark
  • airframe-canvas: Off-Heap Memory Manager
  • airframe-fluentd: Fluentd Logger
  • airframe-http-recorder: Web Request/Response Recorder
  • airframe-jdbc: JDBC Connection Pool
  • airframe-jmx: JMX Application Monitor
  • airframe-json: Pure-Scala JSON Parser
  • airframe-launcher: Command-Line Program Launcher
  • airframe-msgpack: Pure-Scala MessagePack Parser
  • airframe-parquet: Parquet Columnar File Reader and Writer
  • airframe-sql: SQL Parser
  • airframe-ulid: ULID Generator

airframe-fluentd: Fluentd Logger

airframe-fluentd is a logging library for sending metrics to Fluentd or Treasure Data

  • Internally it uses Fluency as the fluentd client.

Maven Central

Usage

build.sbt

libraryDependencies += "org.wvlet.airframe" %% "airframe-fluentd" % "(version)"

Sending Data to Fluentd

import wvlet.airframe.fluentd._

// Define a metric class
case class MyMetric(a:Int, b:String) extends TaggedMetric {
  // Used for defining the default tag prefix for this metric.
  // (tagPrefix).(metricTag) will be used as fluentd tag. 
  override def metricTag: String = "my_metric"
}

// Creating a logger to use the local fluentd (host="localhost", port=24224)
// [optional] tagPrefix: common tag prefix for all metrics  
val loggerFactory = Fluentd.client
  .withTagPrefix("data")
  .newFluentdLoggerFactory()
   
// Create a metric logger for MyMetric class
val l = loggerFactory.getTypedLogger[MyMetric]

l.emit(MyMetric(1, "hello"))   // data.my_metric {"a":1, "b":"hello"}
l.emit(MyMetric(2, "fluentd")) // data.my_metric {"a":2, "b":"fluentd"}

// Close the factory (and underlying loggers)
f.close()

Sending Data to Treasure Data

import wvlet.airframe.fluentd._

// Define a metric class
case class MyMetric(a:Int, b:String) extends TaggedMetric {
  // Specify the table name to store this metric
  override def metricTag: String = "my_metric"
}

// Creating a logger to send log data to Treasure Data Stream Import API:
val loggerFactory = Fluentd.client
  .withTagPrefix("(database name to store logs)")
  .newTDLoggerFactory(apikey = "(Your TD API key)")

// Create a metric logger for MyMetric class
val l = loggerFactory.getTypedLogger[MyMetric]

// Metrics will be stored in data.my_mertric table
l.emit(MyMetric(1, "hello"))   // data.my_metric {"a":1, "b":"hello"}
l.emit(MyMetric(2, "fluentd")) // data.my_metric {"a":2, "b":"fluentd"}

// Make sure closing the logger factory to flush out the logged metrics
loggerFactory.close()

Using Non-Typed Logger

val loggerFactory = Flutentd.client.newFluentdLoggerFactory()

val l = loggerFactory.getLogger
l.emit("data.my_metric", Map("a"->1, "b"->"hello"))

Debugging Metrics

For debugging purpose, use fluentd.withConsoleLogging design:

val d = fluentd.withConsoleLogging // Use a console logger instead of sending logs to Fluentd

d.build[MetricLoggerFactory] { f =>
   val l = f.getTypedLogger[MyMetric]
   l.emit(MyMetric(1, "hello"))   // prints data.my_metric: {"a":1, "b":"hello"}
   l.emit(MyMetric(2, "fluentd")) // prints data.my_metric: {"a":2, "b":"fluentd"}
}
← airframe-canvas: Off-Heap Memory Managerairframe-http-recorder: Web Request/Response Recorder →
  • Usage
    • Sending Data to Fluentd
    • Sending Data to Treasure Data
    • Using Non-Typed Logger
  • Debugging Metrics
Airframe
Docs
Documentation
Community
Gitter Chat
More
GitHubStar
airframe logo
Copyright © 2024 wvlet.org