Skip to content

Instantly share code, notes, and snippets.

@williamho
Last active October 23, 2015 17:15
Show Gist options
  • Select an option

  • Save williamho/3292bb758154fdddadb0 to your computer and use it in GitHub Desktop.

Select an option

Save williamho/3292bb758154fdddadb0 to your computer and use it in GitHub Desktop.
work pipeline statsd

Work pipeline dashboard example

work-pipeline-grafana.json:

  • example grafana dashboard json (assumes the metrics will be prefixed in the format someNamespace.somePipelineName)

WorkPipelineSample.scala

  • scala example code for using the workpipeline and generating some metrics

you can use this to set up grafana/graphite/statsd locally: https://github.com/kamon-io/docker-grafana-graphite

{
"id": 3,
"title": "Work Pipeline",
"originalTitle": "Work Pipeline",
"tags": [],
"style": "dark",
"timezone": "browser",
"editable": true,
"hideControls": false,
"sharedCrosshair": false,
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"aliasColors": {
"failure": "#E24D42",
"stats.counters.example.work.failed.rate": "#E24D42"
},
"bars": false,
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"rightLogBase": 1,
"rightMax": null,
"rightMin": null,
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 5,
"leftYAxisLabel": "per second",
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"target": "alias(stats.counters.$namespace.$pipelineName.work.completed.rate, 'success')",
"textEditor": false
}
],
"timeFrom": null,
"timeShift": null,
"title": "Throughput",
"tooltip": {
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"short",
"short"
]
},
{
"aliasColors": {
"failure": "#E24D42",
"stats.counters.example.work.failed.rate": "#E24D42"
},
"bars": false,
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"rightLogBase": 1,
"rightMax": null,
"rightMin": null,
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 6,
"leftYAxisLabel": "count",
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"target": "alias(stats.counters.$namespace.$pipelineName.work.failed.count, 'failure')",
"textEditor": false
},
{
"target": "alias(stats.counters.$namespace.$pipelineName.work.timedOut.count, 'timeout')",
"textEditor": true
}
],
"timeFrom": null,
"timeShift": null,
"title": "Failures",
"tooltip": {
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"short",
"short"
],
"rightYAxisLabel": ""
}
],
"showTitle": false,
"title": "Row 1"
},
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"aliasColors": {},
"bars": false,
"datasource": null,
"decimals": 0,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"rightLogBase": 1,
"rightMax": null,
"rightMin": null,
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 1,
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"hide": false,
"target": "alias(stats.gauges.$namespace.$pipelineName.queue.length, 'queue length')",
"textEditor": true
},
{
"hide": true,
"target": "alias(stats.gauges.$namespace.$pipelineName.queue.maxLength, 'max length')",
"textEditor": true
}
],
"timeFrom": null,
"timeShift": null,
"title": "Queue Length",
"tooltip": {
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"short",
"short"
]
},
{
"aliasColors": {
"enqueue rejected": "#BF1B00",
"enqueued": "#7EB26D",
"rejected": "#E24D42",
"rejected enqueues": "#E24D42",
"successful enqueues": "#7EB26D"
},
"bars": false,
"cacheTimeout": "",
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"rightLogBase": 1,
"rightMax": null,
"rightMin": null,
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 2,
"leftYAxisLabel": "per second",
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"rightYAxisLabel": "",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"target": "alias(stats.counters.$namespace.$pipelineName.queue.enqueued.rate, 'enqueued')",
"textEditor": true
},
{
"target": "alias(stats.counters.$namespace.$pipelineName.queue.enqueueRejected.rate, 'rejected')",
"textEditor": true
}
],
"timeFrom": null,
"timeShift": null,
"title": "Inbound Requests",
"tooltip": {
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"short",
"short"
]
}
],
"title": "Row 2"
},
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"aliasColors": {
"Max size": "#447EBC",
"Utilized": "#7EB26D",
"stats.gauges.example.pool.size": "#1F78C1",
"stats.gauges.example.pool.utilized": "#7EB26D"
},
"bars": false,
"datasource": null,
"decimals": 0,
"editable": true,
"error": false,
"fill": 10,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"rightLogBase": 1,
"rightMax": null,
"rightMin": null,
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 3,
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": true,
"targets": [
{
"target": "alias(stats.gauges.$namespace.$pipelineName.pool.size, 'Max size')",
"textEditor": true
},
{
"target": "alias(stats.gauges.$namespace.$pipelineName.pool.utilized, 'Utilized')",
"textEditor": true
}
],
"timeFrom": null,
"timeShift": null,
"title": "Pool size",
"tooltip": {
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"short",
"short"
],
"repeat": null
},
{
"aliasColors": {},
"bars": false,
"datasource": null,
"editable": true,
"error": false,
"fill": 1,
"grid": {
"leftLogBase": 1,
"leftMax": null,
"leftMin": null,
"rightLogBase": 1,
"rightMax": null,
"rightMin": null,
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": 4,
"legend": {
"avg": false,
"current": true,
"max": false,
"min": false,
"show": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null as zero",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"span": 6,
"stack": false,
"steppedLine": false,
"targets": [
{
"target": "alias(multiplySeries(stats.timers.$namespace.$pipelineName.queue.waitTime.mean, stats.gauges.$namespace.$pipelineName.queue.length),'wait time (total)')",
"textEditor": true
},
{
"target": "alias(stats.timers.$namespace.$pipelineName.queue.waitTime.mean,'wait time (per unit of work)')",
"textEditor": true
}
],
"timeFrom": null,
"timeShift": null,
"title": "Expected Wait time",
"tooltip": {
"shared": true,
"value_type": "cumulative"
},
"type": "graph",
"x-axis": true,
"y-axis": true,
"y_formats": [
"ms",
"short"
]
}
],
"title": "Row 3"
}
],
"nav": [
{
"collapse": false,
"enable": true,
"notice": false,
"now": true,
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"status": "Stable",
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
],
"type": "timepicker"
}
],
"time": {
"from": "now-5m",
"to": "now"
},
"templating": {
"list": [
{
"allFormat": "glob",
"current": {
"tags": [],
"text": "workPipeline",
"value": "workPipeline"
},
"datasource": null,
"includeAll": false,
"label": "Namespace",
"multi": false,
"multiFormat": "glob",
"name": "namespace",
"options": [
{
"selected": false,
"text": "example",
"value": "example"
},
{
"selected": false,
"text": "pipeline",
"value": "pipeline"
},
{
"selected": true,
"text": "workPipeline",
"value": "workPipeline"
}
],
"query": "stats.timers.*",
"refresh_on_load": false,
"regex": "",
"type": "query"
},
{
"allFormat": "glob",
"current": {
"text": "example",
"value": "example",
"tags": []
},
"datasource": null,
"includeAll": false,
"label": "Pipeline",
"multi": false,
"multiFormat": "glob",
"name": "pipelineName",
"options": [
{
"selected": true,
"text": "example",
"value": "example"
},
{
"selected": false,
"text": "example2",
"value": "example2"
}
],
"query": "stats.timers.$namespace.*",
"refresh_on_load": false,
"regex": "",
"type": "query",
"useTags": false
}
]
},
"annotations": {
"list": []
},
"refresh": "5s",
"schemaVersion": 6,
"version": 27,
"links": []
}
package mypackage
import com.iheart.workpipeline.akka.patterns._
import akka.actor._
import com.iheart.workpipeline.metrics._
import scala.util.Random
import com.typesafe.config.{Config, ConfigFactory}
object WorkPipelineSample {
def main(args: Array[String]): Unit = try {
implicit val system = ActorSystem("example")
// If statsD key doesn't exist, no metrics will be reported
val metricsConfig: Config = ConfigFactory.parseString("""
statsD {
host: 192.168.99.100
port: 8125
eventSampleRate: 0.5
//// These values are provided by default:
// namespace: workPipeline
// statusSampleRate: 1.0
}
""")
val pipelineProps: Props = PushingWorkPipeline.props(
"example", PushingWorkPipeline.defaultSettings, Props(new MyActor), metricsConfig) {
case WorkDone => Right("got 'em")
case WorkFailed => Left("oh no")
}
val pipeline: ActorRef = system.actorOf(pipelineProps, "pipeline")
// Simulate some work, with periodic spikes
for (i <- 1 to Int.MaxValue) {
val sleepTime: Int = if (i / 5000 % 2 == 0) 3 else 40
Thread.sleep(Random.nextInt(sleepTime))
if (i % 1000 == 0) { println(i) } // running total of work sent
pipeline ! DelayedWork(Random.nextInt(200))
}
} catch {
case e: Throwable => println(e); println("exiting"); System.exit(0)
}
}
case class DelayedWork(milliseconds: Int)
case object WorkFailed
case object WorkDone
class MyActor extends Actor {
def receive: Receive = {
case DelayedWork(ms: Int) => {
Thread.sleep(ms)
if (Random.nextDouble < 0.001) {
sender ! WorkFailed
} else {
sender ! WorkDone
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment