Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow build and run by docker #6

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM hseeberger/scala-sbt
ADD . /burrower/
WORKDIR /burrower
RUN sbt assembly
CMD java -cp "target/scala-2.11/burrower-0.2-SNAPSHOT.jar:conf/" com.github.splee.burrower.OffsetMonitor
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Metrics are sent to InfluxDB with the following values and tags:
1. Update configuration, saving it as `conf/application.conf` (example config file: `burrow/conf/application.conf.example`)
1. `java -cp target/scala-2.11/burrower-0.2-SNAPSHOT.jar:conf/ com.github.splee.burrower.OffsetMonitor`

## Docker build & Run

* cd burrower
* docker build .
* docker run -it --env BURROW_HOST=127.0.0.1 --env BURROWER_WRITER=influxdb --env INFLUXDB_HOST=127.0.0.1 imageName

## Planned Features

* Ability to specify any class implmenting `com.github.splee.burrower.write.Writer` to write metrics to custom back ends.
Expand Down
4 changes: 3 additions & 1 deletion conf/application.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ burrower {
host = 127.0.0.1
port = 8086
database = "metrics"
series = "kafka.consumer_lag"
series = "kafka_consumer_lag"
username = ""
password = ""
}
}
6 changes: 4 additions & 2 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ burrower {
influx = {
host = "localhost"
port = 8086
database = "metrics"
series = "kafka.consumer_lag"
database = "burrower"
series = "kafka_consumer_lag"
userName = ""
password = ""
}
}
27 changes: 13 additions & 14 deletions src/main/scala/com/github/splee/burrower/OffsetMonitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package com.github.splee.burrower

import com.github.splee.burrower.lag.{BurrowConsumerStatus, BurrowPartitionLag, Lag, LagGroup}
import com.github.splee.burrower.write.{ConsoleWriter, InfluxWriter, Writer}
import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.config.{Config, ConfigFactory, ConfigParseOptions}
import com.typesafe.scalalogging.LazyLogging

import scalaj.http._
import play.api.libs.json._

object OffsetMonitor extends LazyLogging {

def main(args: Array[String]): Unit = {
val conf = ConfigFactory.load()

val bHost = conf.getString("burrower.burrow.host")
val bPort = conf.getInt("burrower.burrow.port")

var bHost:String = sys.env.getOrElse("BURROW_HOST",conf.getString("burrower.burrow.host")).toString
val bPort = sys.env.getOrElse("BURROW_PORT",conf.getInt("burrower.burrow.port")).toString.toInt
val writer = buildWriter(conf)

logger.info("Creating monitor...")
Expand All @@ -30,7 +29,7 @@ object OffsetMonitor extends LazyLogging {
}

def buildWriter(conf: Config): Writer = {
val writerType = conf.getString("burrower.writer")
val writerType = sys.env.getOrElse("BURROWER_WRITER",conf.getString("burrower.writer"))
logger.info(f"Creating $writerType writer...")

if (writerType == "console")
Expand All @@ -46,18 +45,18 @@ object OffsetMonitor extends LazyLogging {

def buildInfluxWriter(conf: Config): InfluxWriter =
new InfluxWriter(
conf.getString("burrower.influx.host"),
conf.getInt("burrower.influx.port"),
conf.getString("burrower.influx.database"),
conf.getString("burrower.influx.series"),
conf.getString("burrower.influx.userName"),
conf.getString("burrower.influx.password")
sys.env.getOrElse("INFLUXDB_HOST",conf.getString("burrower.influx.host")),
sys.env.getOrElse("INFLUXDB_PORT",conf.getInt("burrower.influx.port")).toString.toInt,
sys.env.getOrElse("INFLUXDB_DATABASE",conf.getString("burrower.influx.database")),
sys.env.getOrElse("INFLUXDB_SERIES",conf.getString("burrower.influx.series")),
sys.env.getOrElse("INFLUXDB_USER",conf.getString("burrower.influx.userName")),
sys.env.getOrElse("INFLUXDB_PASSWORD",conf.getString("burrower.influx.password"))
)
}

class OffsetMonitor (
burrowHost: String,
burrowPort: Number,
burrowHost: String="localhost",
burrowPort: Number=8000,
writer: Writer
) extends Runnable with LazyLogging {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ case class BurrowConsumerStatus(
partitions: List[BurrowPartitionLag],
partition_count: Int,
maxlag: Option[BurrowPartitionLag],
totallag: Int
totallag: Long
)

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}

class InfluxWriter(
influxHost: String,
influxPort: Int,
influxDatabase: String,
influxSeries: String,
userName: String,
password: String
influxHost: String="localhost",
influxPort: Int=8086,
influxDatabase: String="burrower",
influxSeries: String="kafka_consumer_lag",
userName: String="",
password: String=""
) extends Writer with LazyLogging {

val influxdb = InfluxDB.connect(influxHost, influxPort, userName, password)
Expand All @@ -36,7 +36,7 @@ class InfluxWriter(
case Success(v) =>
logger.debug("Metrics sent to InfluxDB")
case Failure(e) =>
logger.debug(f"Sending metrics to InfluxDB failed: ${e.getMessage}")
logger.error(f"Sending metrics to InfluxDB failed: ${e.getMessage}")
})
}
}