-
-
Save aleung/1ec7e56bfa9448af920b to your computer and use it in GitHub Desktop.
API metrics demo. Includes:
(1) an util to feed mock API metrics into Graphite
(2) Grafana portal configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": null, | |
"title": "API Monitor", | |
"originalTitle": "API Monitor", | |
"tags": [], | |
"style": "light", | |
"timezone": "browser", | |
"editable": true, | |
"hideControls": false, | |
"sharedCrosshair": true, | |
"rows": [ | |
{ | |
"title": "New row", | |
"height": "150px", | |
"editable": true, | |
"collapse": false, | |
"panels": [ | |
{ | |
"title": "Total Requests", | |
"error": false, | |
"span": 2, | |
"editable": true, | |
"type": "singlestat", | |
"id": 11, | |
"links": [], | |
"maxDataPoints": "", | |
"interval": null, | |
"targets": [ | |
{ | |
"target": "sumSeries(api.ac.$sc.$partner.$app.*.count)", | |
"hide": false | |
} | |
], | |
"cacheTimeout": "1", | |
"format": "short", | |
"prefix": "", | |
"postfix": "", | |
"nullText": null, | |
"valueMaps": [], | |
"nullPointMode": "null as zero", | |
"valueName": "total", | |
"prefixFontSize": "50%", | |
"valueFontSize": "80%", | |
"postfixFontSize": "50%", | |
"thresholds": "0, 50, 80", | |
"colorBackground": false, | |
"colorValue": false, | |
"colors": [ | |
"rgba(71, 212, 59, 0.4)", | |
"rgba(245, 150, 40, 0.73)", | |
"rgba(225, 40, 40, 0.59)" | |
], | |
"sparkline": { | |
"show": false, | |
"full": false, | |
"lineColor": "rgb(255, 255, 255)", | |
"fillColor": "rgba(209, 38, 38, 0.91)" | |
} | |
}, | |
{ | |
"title": "Avg Throughput", | |
"error": false, | |
"span": 2, | |
"editable": true, | |
"type": "singlestat", | |
"id": 12, | |
"links": [], | |
"maxDataPoints": 100, | |
"interval": null, | |
"targets": [ | |
{ | |
"target": "sumSeries(scaleToSeconds(api.ac.$sc.$partner.$app.*.count, 1))" | |
} | |
], | |
"cacheTimeout": null, | |
"format": "none", | |
"prefix": "", | |
"postfix": "/s", | |
"nullText": null, | |
"valueMaps": [ | |
{ | |
"value": "null", | |
"op": "=", | |
"text": "N/A" | |
} | |
], | |
"nullPointMode": "null as zero", | |
"valueName": "avg", | |
"prefixFontSize": "50%", | |
"valueFontSize": "80%", | |
"postfixFontSize": "50%", | |
"thresholds": "", | |
"colorBackground": false, | |
"colorValue": false, | |
"colors": [ | |
"rgba(245, 54, 54, 0.9)", | |
"rgba(237, 129, 40, 0.89)", | |
"rgba(50, 172, 45, 0.97)" | |
], | |
"sparkline": { | |
"show": false, | |
"full": false, | |
"lineColor": "rgb(31, 120, 193)", | |
"fillColor": "rgba(31, 118, 189, 0.18)" | |
} | |
}, | |
{ | |
"title": "Avg Rsp Time", | |
"error": false, | |
"span": 2, | |
"editable": true, | |
"type": "singlestat", | |
"id": 15, | |
"links": [], | |
"maxDataPoints": 100, | |
"interval": null, | |
"targets": [ | |
{ | |
"target": "averageSeries(api.ac.$sc.$partner.$app.*.t.avg)" | |
} | |
], | |
"cacheTimeout": null, | |
"format": "ms", | |
"prefix": "", | |
"postfix": "", | |
"nullText": null, | |
"valueMaps": [ | |
{ | |
"value": "null", | |
"op": "=", | |
"text": "N/A" | |
} | |
], | |
"nullPointMode": "connected", | |
"valueName": "avg", | |
"prefixFontSize": "50%", | |
"valueFontSize": "80%", | |
"postfixFontSize": "50%", | |
"thresholds": "0,40,100", | |
"colorBackground": false, | |
"colorValue": true, | |
"colors": [ | |
"rgba(50, 172, 45, 0.97)", | |
"rgba(237, 129, 40, 0.89)", | |
"rgba(245, 54, 54, 0.9)" | |
], | |
"sparkline": { | |
"show": false, | |
"full": false, | |
"lineColor": "rgb(31, 120, 193)", | |
"fillColor": "rgba(31, 118, 189, 0.18)" | |
} | |
}, | |
{ | |
"title": "Success Rate", | |
"error": false, | |
"span": 2, | |
"editable": true, | |
"type": "singlestat", | |
"id": 7, | |
"links": [], | |
"maxDataPoints": "", | |
"interval": null, | |
"targets": [ | |
{ | |
"target": "sumSeries(api.ac.$sc.$partner.$app.*.count)", | |
"hide": true | |
}, | |
{ | |
"target": "asPercent(api.ac.$sc.$partner.$app.200.count, #A)", | |
"hide": false | |
} | |
], | |
"cacheTimeout": "1", | |
"format": "percent", | |
"prefix": "", | |
"postfix": "", | |
"nullText": null, | |
"valueMaps": [], | |
"nullPointMode": "null", | |
"valueName": "avg", | |
"prefixFontSize": "50%", | |
"valueFontSize": "80%", | |
"postfixFontSize": "50%", | |
"thresholds": "0, 50, 80", | |
"colorBackground": false, | |
"colorValue": true, | |
"colors": [ | |
"rgba(245, 54, 54, 0.9)", | |
"rgba(237, 129, 40, 0.89)", | |
"rgba(50, 172, 45, 0.97)" | |
], | |
"sparkline": { | |
"show": true, | |
"full": false, | |
"lineColor": "rgba(177, 177, 177, 0)", | |
"fillColor": "rgba(179, 179, 179, 0.91)" | |
} | |
}, | |
{ | |
"title": "Throughput (TPS)", | |
"error": false, | |
"span": 4, | |
"editable": true, | |
"type": "graph", | |
"id": 8, | |
"datasource": null, | |
"renderer": "flot", | |
"x-axis": true, | |
"y-axis": true, | |
"y_formats": [ | |
"short", | |
"short" | |
], | |
"grid": { | |
"leftMax": null, | |
"rightMax": null, | |
"leftMin": 0, | |
"rightMin": null, | |
"threshold1": 0, | |
"threshold2": null, | |
"threshold1Color": "rgba(216, 200, 27, 0.27)", | |
"threshold2Color": "rgba(234, 112, 112, 0.22)", | |
"thresholdLine": false | |
}, | |
"lines": true, | |
"fill": 4, | |
"linewidth": 2, | |
"points": false, | |
"pointradius": 5, | |
"bars": false, | |
"stack": false, | |
"percentage": false, | |
"legend": { | |
"show": false, | |
"values": true, | |
"min": false, | |
"max": false, | |
"current": false, | |
"total": false, | |
"avg": true, | |
"alignAsTable": false, | |
"rightSide": false | |
}, | |
"nullPointMode": "null", | |
"steppedLine": true, | |
"tooltip": { | |
"value_type": "individual", | |
"shared": true | |
}, | |
"targets": [ | |
{ | |
"target": "alias(sumSeries(scaleToSeconds(api.ac.$sc.$partner.$app.*.count, 1)), ' ')", | |
"hide": false | |
} | |
], | |
"aliasColors": { | |
"failure": "#EAB839", | |
"error": "#EA6460", | |
"success": "#9AC48A", | |
" ": "#CCA300" | |
}, | |
"seriesOverrides": [], | |
"links": [], | |
"cacheTimeout": "0" | |
} | |
] | |
}, | |
{ | |
"title": "New row", | |
"height": "250px", | |
"editable": true, | |
"collapse": false, | |
"panels": [ | |
{ | |
"title": "Requests (status $status) per $summarize", | |
"error": false, | |
"span": 6, | |
"editable": true, | |
"type": "graph", | |
"id": 9, | |
"datasource": null, | |
"renderer": "flot", | |
"x-axis": true, | |
"y-axis": true, | |
"y_formats": [ | |
"short", | |
"short" | |
], | |
"grid": { | |
"leftMax": null, | |
"rightMax": null, | |
"leftMin": 0, | |
"rightMin": null, | |
"threshold1": 0, | |
"threshold2": null, | |
"threshold1Color": "rgba(216, 200, 27, 0.27)", | |
"threshold2Color": "rgba(234, 112, 112, 0.22)", | |
"thresholdLine": false | |
}, | |
"lines": false, | |
"fill": 3, | |
"linewidth": 2, | |
"points": false, | |
"pointradius": 5, | |
"bars": true, | |
"stack": true, | |
"percentage": false, | |
"legend": { | |
"show": true, | |
"values": true, | |
"min": false, | |
"max": false, | |
"current": false, | |
"total": true, | |
"avg": false, | |
"alignAsTable": false, | |
"rightSide": false | |
}, | |
"nullPointMode": "connected", | |
"steppedLine": false, | |
"tooltip": { | |
"value_type": "individual", | |
"shared": true | |
}, | |
"targets": [ | |
{ | |
"target": "aliasByNode(summarize(sumSeriesWithWildcards(sumSeriesWithWildcards(sumSeriesWithWildcards(api.ac.$sc.$partner.$app.$status.count, 2), 2), 2), '$summarize', 'sum', false), 2)", | |
"hide": false | |
} | |
], | |
"aliasColors": { | |
"failure": "#EAB839", | |
"error": "#EA6460", | |
"success": "#9AC48A", | |
"error / 5m": "#EA6460", | |
"success / 5m": "#9AC48A" | |
}, | |
"seriesOverrides": [], | |
"links": [], | |
"cacheTimeout": "0" | |
}, | |
{ | |
"title": "Top $topn applications: Requests (status $status)", | |
"error": false, | |
"span": 6, | |
"editable": true, | |
"type": "graph", | |
"id": 14, | |
"datasource": null, | |
"renderer": "flot", | |
"x-axis": true, | |
"y-axis": true, | |
"y_formats": [ | |
"percent", | |
"short" | |
], | |
"grid": { | |
"leftMax": null, | |
"rightMax": null, | |
"leftMin": 0, | |
"rightMin": null, | |
"threshold1": 0, | |
"threshold2": null, | |
"threshold1Color": "rgba(216, 200, 27, 0.27)", | |
"threshold2Color": "rgba(234, 112, 112, 0.22)", | |
"thresholdLine": false | |
}, | |
"lines": true, | |
"fill": 2, | |
"linewidth": 1, | |
"points": false, | |
"pointradius": 5, | |
"bars": false, | |
"stack": true, | |
"percentage": false, | |
"legend": { | |
"show": true, | |
"values": true, | |
"min": false, | |
"max": false, | |
"current": false, | |
"total": false, | |
"avg": true, | |
"alignAsTable": true, | |
"rightSide": true, | |
"sortDesc": null, | |
"sort": null | |
}, | |
"nullPointMode": "null as zero", | |
"steppedLine": false, | |
"tooltip": { | |
"value_type": "individual", | |
"shared": true | |
}, | |
"targets": [ | |
{ | |
"target": "aliasSub(asPercent(highestAverage(sumSeriesWithWildcards(api.ac.$sc.$partner.$app.$status.count, 5), $topn), #B), '.*\\.(.*)\\.count.*sumSeries.*', '\\1')", | |
"hide": false | |
}, | |
{ | |
"target": "sumSeries(api.ac.$sc.$partner.$app.$status.count)", | |
"hide": true | |
} | |
], | |
"aliasColors": { | |
"failure": "#EAB839", | |
"error": "#EA6460", | |
"success": "#9AC48A", | |
"sumSeries(api.ac.sc_1.sp_1.app_1.500.count)": "#BADFF4", | |
"requests": "#BADFF4" | |
}, | |
"seriesOverrides": [], | |
"links": [], | |
"cacheTimeout": "0" | |
} | |
] | |
}, | |
{ | |
"title": "New row", | |
"height": "250px", | |
"editable": true, | |
"collapse": false, | |
"panels": [ | |
{ | |
"title": "Response Time (status $status)", | |
"error": false, | |
"span": 6, | |
"editable": true, | |
"type": "graph", | |
"id": 10, | |
"datasource": null, | |
"renderer": "flot", | |
"x-axis": true, | |
"y-axis": true, | |
"y_formats": [ | |
"ms", | |
"short" | |
], | |
"grid": { | |
"leftMax": null, | |
"rightMax": null, | |
"leftMin": 0, | |
"rightMin": null, | |
"threshold1": null, | |
"threshold2": null, | |
"threshold1Color": "rgba(216, 200, 27, 0.27)", | |
"threshold2Color": "rgba(234, 112, 112, 0.22)" | |
}, | |
"lines": true, | |
"fill": 0, | |
"linewidth": 3, | |
"points": false, | |
"pointradius": 5, | |
"bars": false, | |
"stack": false, | |
"percentage": false, | |
"legend": { | |
"show": true, | |
"values": false, | |
"min": false, | |
"max": false, | |
"current": false, | |
"total": false, | |
"avg": false, | |
"alignAsTable": false, | |
"rightSide": false | |
}, | |
"nullPointMode": "null", | |
"steppedLine": false, | |
"tooltip": { | |
"value_type": "cumulative", | |
"shared": true | |
}, | |
"targets": [ | |
{ | |
"target": "aliasByMetric(maxSeries(api.ac.$sc.$partner.$app.$status.t.max))" | |
}, | |
{ | |
"target": "aliasByMetric(averageSeries(api.ac.$sc.$partner.$app.$status.t.avg))" | |
}, | |
{ | |
"target": "aliasByMetric(minSeries(api.ac.$sc.$partner.$app.$status.t.min))" | |
} | |
], | |
"aliasColors": { | |
"max)": "#BADFF4", | |
"avg)": "#5195CE", | |
"min)": "#BADFF4" | |
}, | |
"seriesOverrides": [ | |
{ | |
"alias": "max)", | |
"fillBelowTo": "min)", | |
"linewidth": 1 | |
}, | |
{ | |
"alias": "min)", | |
"linewidth": 1 | |
} | |
], | |
"links": [], | |
"cacheTimeout": "0" | |
}, | |
{ | |
"title": "Slowest $topn applications (status $status)", | |
"error": false, | |
"span": 6, | |
"editable": true, | |
"type": "graph", | |
"id": 17, | |
"datasource": null, | |
"renderer": "flot", | |
"x-axis": true, | |
"y-axis": true, | |
"y_formats": [ | |
"ms", | |
"short" | |
], | |
"grid": { | |
"leftMax": null, | |
"rightMax": null, | |
"leftMin": 0, | |
"rightMin": null, | |
"threshold1": null, | |
"threshold2": null, | |
"threshold1Color": "rgba(216, 200, 27, 0.27)", | |
"threshold2Color": "rgba(234, 112, 112, 0.22)" | |
}, | |
"lines": true, | |
"fill": 0, | |
"linewidth": 1, | |
"points": false, | |
"pointradius": 5, | |
"bars": false, | |
"stack": false, | |
"percentage": false, | |
"legend": { | |
"show": true, | |
"values": true, | |
"min": false, | |
"max": false, | |
"current": false, | |
"total": false, | |
"avg": true, | |
"alignAsTable": true, | |
"rightSide": true | |
}, | |
"nullPointMode": "null", | |
"steppedLine": false, | |
"tooltip": { | |
"value_type": "individual", | |
"shared": true | |
}, | |
"targets": [ | |
{ | |
"target": "aliasByNode(highestAverage(api.ac.$sc.$partner.$app.$status.t.avg, $topn), 4)" | |
} | |
], | |
"aliasColors": { | |
"max)": "#F9D9F9", | |
"avg)": "#806EB7", | |
"min)": "#F9D9F9" | |
}, | |
"seriesOverrides": [], | |
"links": [], | |
"cacheTimeout": "0", | |
"leftYAxisLabel": "" | |
} | |
] | |
} | |
], | |
"nav": [ | |
{ | |
"type": "timepicker", | |
"collapse": false, | |
"enable": true, | |
"status": "Stable", | |
"time_options": [ | |
"15m", | |
"1h", | |
"3h", | |
"12h", | |
"24h", | |
"2d", | |
"7d" | |
], | |
"refresh_intervals": [ | |
"5s", | |
"1m", | |
"30m" | |
], | |
"now": false, | |
"notice": false | |
} | |
], | |
"time": { | |
"from": "2014-12-09T04:24:37.517Z", | |
"to": "2014-12-09T07:37:17.591Z", | |
"now": true | |
}, | |
"templating": { | |
"list": [ | |
{ | |
"type": "query", | |
"datasource": null, | |
"refresh_on_load": false, | |
"name": "sc", | |
"options": [ | |
{ | |
"text": "sc_1", | |
"value": "sc_1" | |
}, | |
{ | |
"text": "sc_2", | |
"value": "sc_2" | |
} | |
], | |
"includeAll": false, | |
"allFormat": "wildcard", | |
"query": "api.ac.*", | |
"current": { | |
"text": "sc_1", | |
"value": "sc_1" | |
}, | |
"refresh": true | |
}, | |
{ | |
"type": "query", | |
"datasource": null, | |
"refresh_on_load": false, | |
"name": "partner", | |
"options": [ | |
{ | |
"text": "All", | |
"value": "*" | |
}, | |
{ | |
"text": "sp_1", | |
"value": "sp_1" | |
}, | |
{ | |
"text": "sp_2", | |
"value": "sp_2" | |
} | |
], | |
"includeAll": true, | |
"allFormat": "wildcard", | |
"query": "api.ac.*.*", | |
"current": { | |
"text": "All", | |
"value": "*" | |
}, | |
"refresh": true | |
}, | |
{ | |
"type": "query", | |
"datasource": null, | |
"refresh_on_load": false, | |
"name": "app", | |
"options": [ | |
{ | |
"text": "All", | |
"value": "*" | |
}, | |
{ | |
"text": "app_1", | |
"value": "app_1" | |
}, | |
{ | |
"text": "app_10", | |
"value": "app_10" | |
}, | |
{ | |
"text": "app_11", | |
"value": "app_11" | |
}, | |
{ | |
"text": "app_12", | |
"value": "app_12" | |
}, | |
{ | |
"text": "app_13", | |
"value": "app_13" | |
}, | |
{ | |
"text": "app_2", | |
"value": "app_2" | |
}, | |
{ | |
"text": "app_3", | |
"value": "app_3" | |
}, | |
{ | |
"text": "app_4", | |
"value": "app_4" | |
}, | |
{ | |
"text": "app_5", | |
"value": "app_5" | |
}, | |
{ | |
"text": "app_6", | |
"value": "app_6" | |
}, | |
{ | |
"text": "app_7", | |
"value": "app_7" | |
}, | |
{ | |
"text": "app_8", | |
"value": "app_8" | |
}, | |
{ | |
"text": "app_9", | |
"value": "app_9" | |
} | |
], | |
"includeAll": true, | |
"allFormat": "wildcard", | |
"query": "api.ac.*.$partner.*", | |
"current": { | |
"text": "All", | |
"value": "*" | |
}, | |
"refresh": true | |
}, | |
{ | |
"type": "query", | |
"datasource": null, | |
"refresh_on_load": false, | |
"name": "status", | |
"options": [ | |
{ | |
"text": "All", | |
"value": "*" | |
}, | |
{ | |
"text": "200", | |
"value": "200" | |
}, | |
{ | |
"text": "400", | |
"value": "400" | |
}, | |
{ | |
"text": "500", | |
"value": "500" | |
} | |
], | |
"includeAll": true, | |
"allFormat": "wildcard", | |
"query": "api.ac.*.*.*.*", | |
"current": { | |
"text": "All", | |
"value": "*" | |
}, | |
"refresh": true | |
}, | |
{ | |
"type": "interval", | |
"datasource": null, | |
"refresh_on_load": false, | |
"name": "summarize", | |
"options": [ | |
{ | |
"text": "auto", | |
"value": "$__auto_interval" | |
}, | |
{ | |
"text": "1m", | |
"value": "1m" | |
}, | |
{ | |
"text": "1h", | |
"value": "1h" | |
}, | |
{ | |
"text": "8h", | |
"value": "8h" | |
}, | |
{ | |
"text": "1d", | |
"value": "1d" | |
}, | |
{ | |
"text": "7d", | |
"value": "7d" | |
}, | |
{ | |
"text": "30d", | |
"value": "30d" | |
} | |
], | |
"includeAll": false, | |
"allFormat": "glob", | |
"query": "1m,1h,8h,1d,7d,30d", | |
"current": { | |
"text": "auto", | |
"value": "$__auto_interval" | |
}, | |
"auto": true, | |
"auto_count": 50 | |
}, | |
{ | |
"type": "custom", | |
"datasource": null, | |
"refresh_on_load": false, | |
"name": "topn", | |
"options": [ | |
{ | |
"text": "3", | |
"value": "3" | |
}, | |
{ | |
"text": "5", | |
"value": "5" | |
}, | |
{ | |
"text": "10", | |
"value": "10" | |
}, | |
{ | |
"text": "20", | |
"value": "20" | |
} | |
], | |
"includeAll": false, | |
"allFormat": "glob", | |
"query": "3,5,10,20", | |
"current": { | |
"text": "5", | |
"value": "5" | |
} | |
} | |
], | |
"enable": true | |
}, | |
"annotations": { | |
"list": [] | |
}, | |
"refresh": false, | |
"version": 6, | |
"hideAllLegends": false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.Socket | |
import scala.util.Random | |
import scala.math._ | |
// configurations | |
val successCount = 300 | |
val failureCount = 50 | |
val minutes = 60 | |
val random = new Random | |
def send(record: String) = { | |
val msg = record + "\n" | |
print(msg) | |
val socket = new Socket("192.168.103.2", 2003) // carbon service address | |
socket.getOutputStream().write(msg.getBytes) | |
socket.close() | |
} | |
def apiBias(scId: Int): Int = { | |
scId match { | |
case 2 => 50 | |
case _ => 1 | |
} | |
} | |
def count(status: Int, appId: Int): Int = { | |
def appSpecificCount(c: Int, appId: Int) = { | |
appId match { | |
case 3 => c * 3 | |
case _ => c | |
} | |
} | |
val c = if (status == 200) successCount else failureCount | |
val high = appSpecificCount(c, appId) | |
randomInRange(high/3, high) | |
} | |
def randomInRange(low: Int, high: Int): Int = { | |
assert(high > low && low >= 0) | |
random.nextInt(high - low) + low | |
} | |
def generateMetrics(scId: Int, spId: Int, appId: Int, status: Int, time: Long) = { | |
val keyPrefix = s"api.ac.sc_$scId.sp_$spId.app_$appId.$status" | |
send(keyPrefix + ".count " + count(status, appId) + " " + time) | |
val bias = apiBias(scId) | |
val t = randomInRange(bias, bias + 100) | |
send(keyPrefix + ".t.avg " + t + " " + time) | |
send(keyPrefix + ".t.max " + randomInRange(t, bias + 200) + " " + time) | |
send(keyPrefix + ".t.min " + randomInRange(0, min(t,50)) + " " + time) | |
} | |
val currentSecond = System.currentTimeMillis() / 1000 | |
for ( t <- (currentSecond - minutes*60) to currentSecond by 30; | |
sc <- 1 to 2; | |
sp <- 1 to 2; | |
app <- 1 to 3; | |
status <- List(200, 400, 500)) { | |
generateMetrics(sc, sp, (sp-1)*10+app, status, t) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment