Top Banner
Making Sense of your Data Building A Custom DataSource for Grafana with Vert.x Gerald Mücke DevCon5 GmbH @gmuecke
39

Making sense of your data

Mar 20, 2017

Download

Software

Gerald Muecke
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Making sense of your data

Making Sense of your DataBuilding A Custom DataSourcefor Grafana with Vert.x

Gerald MückeDevCon5 GmbH@gmuecke

Page 2: Making sense of your data

About me

IT Consultant & Java Specialist at DevCon5 (CH) Focal Areas

Tool-assisted quality assurance

Performance (-testing, -analysis, -tooling)

Operational Topics (APM, Monitoring)

Twitter: @gmuecke

3

Page 3: Making sense of your data

The Starting Point

Customer stored and keep response time measurement of test runs in a MongoDB Lots of Data

Timestamp & Value

No Proper Visualization

4

Page 4: Making sense of your data

What are timeseries data?

a set of datapoints with a timestamp and a value

time

valu

e

Page 5: Making sense of your data

What is MongoDB?

MongoDB NoSQL database with focus on scale

JSON as data representation

No HTTP endpoint (TCP based Wire Protocol)

Aggregation framework for complex queries

6

Page 6: Making sense of your data

What is Grafana?

A Service for Visualizing Time Series Data Open Source Backend written in Go Frontend based on Angular Dashboards & Alerts

Page 7: Making sense of your data

Grafana Architecture 8

Grafana Server • Implemented in GO• Persistence for Settings and Dashboards• Offers Proxy for Service Calls

Browser

Angular UI Data Source Data Source Plugin...

Proxy

DB DB

Page 8: Making sense of your data

Datasources for Grafana 9

Grafana Server • Implemented in GO• Persistence for Settings and Dashboards• Offers Proxy for Service Calls

Browser

Datasource

Angular UIData Source Plugin

• Angular• JavaScript

HTTP

Page 9: Making sense of your data

Connect Angular Directly to Mongo?

10

Page 10: Making sense of your data

From 2 Tier to 3 Tier 11

Grafana(Angular) Mongo DB

Grafana(Angular) Mongo DB

Datasource ServiceHTTP Mongo

WireProtocol

Page 11: Making sense of your data

Start Simple

SimpleJsonDatasource (Plugin)3 ServiceEndpoints /search Labels – names of available timeseries /annoations Annotations – textual markers /query Query – actual time series data

12

https://github.com/grafana/simple-json-datasource

Page 12: Making sense of your data

/search Format

Request{

"target" : "select metric",

"refId" : "E"

}

Response[

"Metric Name 1",

"Metric Name2",

]

An array of strings

13

Page 13: Making sense of your data

/annotations Format

Request{ "annotation" : {

"name" : "Test",

"iconColor" : "rgba(255, 96, 96, 1)",

"datasource" : "Simple Example DS",

"enable" : true,

"query" : "{\"name\":\"Timeseries A\"}" },

"range" : {

"from" : "2016-06-13T12:23:47.387Z",

"to" : "2016-06-13T12:24:19.217Z" },

"rangeRaw" : {

"from" : "2016-06-13T12:23:47.387Z",

"to" : "2016-06-13T12:24:19.217Z"

} }

Response[ { "annotation": {

"name": "Test",

"iconColor": "rgba(255, 96, 96, 1)",

"datasource": "Simple Example DS",

"enable": true,

"query": "{\"name\":\"Timeseries A\"}" },

"time": 1465820629774,

"title": "Marker",

"tags": [

"Tag 1",

"Tag 2" ] } ]

14

Page 14: Making sense of your data

/query Format

Request{ "panelId" : 1,

"maxDataPoints" : 1904,

"format" : "json",

"range" : {

"from" : "2016-06-13T12:23:47.387Z",

"to" : "2016-06-13T12:24:19.217Z" },

"rangeRaw" : {

"from" : "2016-06-13T12:23:47.387Z",

"to" : "2016-06-13T12:24:19.217Z" },

"interval" : "20ms",

"targets" : [ {

"target" : "Time series A",

"refId" : "A" },] }

Response[ { "target":"Timeseries A",

"datapoints":[

[1936,1465820629774],

[2105,1465820632673],

[4187,1465820635570],

[30001,1465820645243] },

{ "target":"Timeseries B",

"datapoints":[ ] }

]

15

Page 15: Making sense of your data

Structure of the Source Data

{

"_id" : ObjectId("56375bc54f3c4caedfe68aca"),

"t" : {

"eDesc" : "KW001_Partner_Zahlungsprofil-erfassen_Sammelkonto_Smoketest",

"eId" : "56375ae24f3c4caedfe68a07",

"name" : "KW001_Partner_Zahlungsprofil-erfassen_steppage1_oeffnen_Task",

"profile" : "I01",

"rnId" : "56375b694f3c4caedfe68aa0",

"rnStatus" : "PASSED",

"uId" : "anonymous"

},

"n" : {

"begin" : NumberLong("1446468494689"),

"value" : NumberLong(283)

}

}

16

Page 16: Making sense of your data

Custom Datasource

Should be Lightweight

Fast / Performant

Simple

17

Page 17: Making sense of your data

Microservice?

Options for implementation Java EE Microservice (i.e. Wildfly Swarm)

Springboot Microservice

Vert.x Microservice

Node.js

...

19

Page 18: Making sense of your data

The Alternative Options

Node.js Single Threaded

Child Worker Processes

Javascript Only

Not best-choice for heavy computation

Spring / Java EE Multithreaded

Clusterable

Java Only

Solid Workhorses, cumbersome at times

21

Page 19: Making sense of your data

Why Vert.x?

High Performance, Low Footprint Asynchronous, Non-Blocking

Actor-like Concurrency Event & Worker Verticles

Message Driven

Polyglott Java, Groovy, Javascript, Scala …

Scalable Distributed Eventbus

Multi-threaded Event Loops

22

Page 20: Making sense of your data

Asynchronous non-blocking vsSynchronous blocking

23

Page 21: Making sense of your data

Event Loop 24

Photo: Andreas Praefcke

Page 22: Making sense of your data

Event Loop and Verticles 25

Photo: RokerHRO

3rd Floor, Verticle A

2nd Floor, Verticle B

1st Floor, Verticle C

Page 23: Making sense of your data

26

Page 24: Making sense of your data

27

Page 25: Making sense of your data

Event Loop 28

Verticle

Verticle

Verticle

EventI/O

Page 26: Making sense of your data

Event Bus 30

Verticle

Verticle

Verticle

Eventbus

Message

Page 27: Making sense of your data

CPU

Multi-Reactor 31

Core Core Core Core

Eventbus

Other Vert.xInstance

Browser

Verticle Verticle

Page 28: Making sense of your data

Event & Worker Verticles

Event Driven Verticles Worker Verticles

32

Verticle

Verticle

Verticle

Thread Pool

Thread Pool

Ver

ticle

Ver

ticle

Ver

ticle

Ver

ticle

Ver

ticle

Page 29: Making sense of your data

Implementing the datasource

Http Routes Pre-Processing

Optional, for example: Split Request

Query Database for Time Data Points Post Processing

Optional, for example: Merge, Calculations

33

Page 30: Making sense of your data

Step 1 – The naive approach

Find all datapoints within range

34

Page 31: Making sense of your data

Step 2 – Split Request

Split request into chunks (#chunks = #cores) Use multiple Verticle Instance in parallel (#instances = #cores) ?

35

CPU

Page 32: Making sense of your data

Step 4 – Aggregate Datapoints

Use Mongo Aggregation Pipeline Reduce Datapoints returned to service

37

Page 33: Making sense of your data

Step 5 – Percentiles (Service)

Fetch all data Calculate percentiles in service

38

CPU

Page 34: Making sense of your data

Step 6 – Percentiles (DB)

Build aggregation pipeline to calculate percentiles Algorithm, see

http://www.dummies.com/education/math/statistics/how-to-calculate-percentiles-in-statistics/

39

DB

Page 35: Making sense of your data

CPUCPU

Datasource Architecture 40

HTTP Service

Split Request

Eventbus

Query Database

Query Database

Query Database

Query Database

Merge Result

HTTP Request

HTTP Response

DB

Post Process

Post Process

Post Process

Post Process

Eventbus

Page 36: Making sense of your data

Remember the CELL BE? CPU of the PS3 Central Bus (EIB) 1 General Purpose CPU

Runs the Game (Event) Loop

8 SPUs Special Processing

Sound

Physics

AI

...

41

Page 37: Making sense of your data

Adding more stats & calculation

Push Calculation to DB if possible Add more workers / node for complex (post-) processing Aggregate results before post-processing DB performance is king

42

Page 38: Making sense of your data

Takeaways

Grafana is powerful tool for visualizing data Information becomes consumable through visualization

Information is essential for decision making

Vert.x is Reactive, Non-Blocking, Asynchronous, Scalable

Running on JVM

Polyglott

Fun

47

Source code on: https://github.com/gmuecke/grafana-vertx-datasource

Page 39: Making sense of your data

Gerald Mücke www.devcon5.ch

DevCon5 @gmuecke