8. What we need?
* A data provider (our application)
* A database that will collects data
* A dashboard for representing information
9. What is a time-series database?
A database optimized for handling time series data:
arrays of numbers indexed by time
(a datetime or a datetime range)
sign elem is 4 -> @10:13 elem is 4
A time series is a sequence of data points, measured typically at
successive points in time spaced at uniform time intervals
11. InfluxDB
Easy to use
Written in Golang (no external dependencies)
ready for bilion of rows (scalable)
UDP/IP and HTTP network adapters
Several client libraries (PHP, Golang, etc...)
Integrated query web panel
Ready for external dashboards (grafana, chronograf, etc...)
12. Write information in your InfluxDB
curl XPOST 'http://localhost:8086/write?db=mydb'
d 'cpu load=2 1434055562000000000'
13. Read data back from InfluxDB
curl G http://localhost:8086/query?pretty=true dataurlencode "db=mydb"
dataurlencode "q=SELECT * FROM cpu WHERE host='server01' AND time < now() 1d"
14. For example:
InfluxDB tags
You can mark new points with a tag information
sign @10.32 key=value tag1=value tag2=value
sign @10.32 temperature=21.3 location=home env=test
sign @10.32 cpu=21.3,mem=123.3 location=euwest1 env=dev instance=ia91afcd1
15. Use tags in your queries
Example
SELECT * FROM home_sensors WHERE
location="home" AND
temperature > 19.2 AND
time >= now() 10m
Example for websites:
SELECT * FROM index_page WHERE
env="prod" AND
load_time > 19.2 AND
time >= now() 1d
Just use them like string column values
16. Play from the InfluxDB web console
http://your-domain.tld:8083/
17. GRAFANA DASHBOARD
An open source, feature rich, metrics dashboard and graph editor
for several time series databases (InfluxDB, Graphite, etc.)
18. Annotate your graphs
Thanks to annotations you can use a serie
as an annotation list
Mark a new software release in your graph (Continuous Delivery)
Mark any critic event in all your graphs (Information Point)
20. How to send my application data?
* Send every single point directly in real-time
* Collect data during the application life-cycle and send those
points once per request
21. InfluxDB supports two network adapters
HTTP or UDP/IP
Which one we should have to use?
UDP/IP must be enabled by configuration
22. HTTP
* TCP/IP based
* Data point delivery guaranteed
* Error handling
* ~ 374 Ops/second (for compare with UDP/IP)
23. UDP/IP
* No delivery guarantees
* No error handling
* ~ 22917 Ops/second (for compare with TCP/IP)
24. HTTP
* Sensitive data
* Good for once at a time strategy
(or if we do not care about monitor impact on our application)
UDP/IP
* Good for immediate delivery
30. Symfony: Dependency Injection Container
#Only options
influxdb_udp_options:
class: InfluxDBOptions
calls:
["setHost", ["%influxdb_host%"]] # InfluxDB host
["setPort", ["%influxdb_udp_port%"]] # UDP/IP Port
["setTags", [{"env": "%kernel.environment%"}]] # tag every point with env
influxdb_http_options:
class: InfluxDBOptions
calls:
["setHost", ["%influxdb_host%"]] # InfluxDB host
["setPort", ["%influxdb_http_port%"]] # HTTP Port
parameters:
influxdb_host: "influxdb.domain.tld"
influxdb_udp_port: 4444
influxdb_http_port: 8086
31. Don't try this at home
class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$client = $this>container>get("influxdb");
$client>mark(...);
}
}
Goals: single-responsibility, reduce coupling, simplifing testing
35. A listener example with stopwatch
class MonitorListener
{
public function startStopwatch(GetResponseEvent $event)
{
$routeName = $event>getRequest()>attributes>get("_route");
$this>stopwatch>start($routeName);
}
public function stopStopwatch(FilterResponseEvent $event)
{
$routeName = $event>getRequest()>attributes>get("_route");
$events = $this>stopwatch>stop($routeName);
foreach ($events>getPeriods() as $measure) {
$this>client>mark($routeName, [
"memory" => $measure>getMemory(), //...
]);
}
}
}