Pinba (PHP Is Not A Bottleneck Anymore) is a statistics server using MySQL as an interface.
454
An attempt to rethink internal implementation and some features of excellent https://github.com/tony2001/pinba_engine by @tony2001.
Pinba (PHP Is Not A Bottleneck Anymore) is a statistics server using MySQL as an interface.
It accumulates and processes data sent over UDP and displays statistics in human-readable form of simple "reports" (like what are my slowest scripts or sql queries). This is not limited to PHP, there are clients for multiple languages and nginx module.
Same client libraries can be used with this pinba implementation
list from http://pinba.org/
We've got some scripts to help in scripts directory. Convert mysqldump of your old tables to new format with this script.
Requests
We get these over UDP, each request contains metrics data gathered by your application (like serving pages to users, or performing db queries).
Data comes in three forms
host_name: name of the physical host (like "subdomain.mycoolserver.localnetwork")script_name: name of the scriptserver_name: name of the logical host (like "example.com")schema: usually "http" or "https"status: usually http status (this one is 32-bit integer)request_time: wall-clock time it took to execute the whole requestrusage_user: rusage in user space for this requestrusage_system: rusage in kernel space for this requestdocument_size: size of result docmemory_footprint: amount of memory usedkey -> value pairs attached to request as a whole
[ 'application' -> 'my_cool_app', 'environment' -> 'production' ][ 'group' -> 'db', 'server' -> 'db1.lan', 'op_type' -> 'update' ][ 'group' -> 'memcache', 'server' -> 'mmc1.lan', 'op_type' -> 'get' ]Reports
Report is a read-only view of incoming data, aggregated within specified time window.
One can think of it as a table of key/value pairs: Aggregation_key value -> Aggregated_data + Percentiles.
Aggregation_key - configured when report is created.
~host, ~script, ~server, ~schema, ~status+whatever_name_you_want@some_timer_tag_nameAggregation_key value - is the set of values, corresponding to key names set in Aggregation_key
Aggregation_key is ~host, there'll be a key/value pair per unique host we see in request streamAggregation_key is ~host,+req_tag, there'll be a key/value pair per unique [host, req_tag_value] pairAggregated_data is report-specific (i.e. a structure with fields like: req_count, hit_count, total_time, etc.).Percentiles is a bunch of fields with specific percentiles, calculated over data from request_time or timer_valueHistogram is a field where engine exports raw histogram data (that we calculate percentiles from) in text formThere are 3 kinds of reports: packet, request, timer. The difference between those boils down to
Aggregation_key values-s are extracted and matchedAggregated_data is populated (i.e. if you aggregate on request tags, there is no need/way to aggregate timer data)Histogram and PercentilesSQL tables
Reports are exposed to the user as SQL tables.
All report tables have same simple structure
Aggregation_key, one table field per key part (i.e. ~script,~host,@timer_tag needs 3 fields with appropriate types)Aggregated_data, 3 fields per data field (field_value, field_value_per_sec, field_value_percent) (i.e. request report needs 7*3 fields = 21 data fields)Percentiles, one field per configured percentile (optional)Histogram, one text field for raw histogram data that percentiles are calculated from (optional)ASCII art!
---------------- -------------------------------------------------------------
| key -> value | | key_part_1 | ... | data_part_1 | ... | percentile_1 | ... |
------------ ---------------- -------------------------------------------------------------
| Requests | aggregate> | ......... | select> | ................................................... |
------------ ---------------- -------------------------------------------------------------
| key -> value | | key_part_1 | ... | data_part_1 | ... | percentile_1 | ... |
---------------- -------------------------------------------------------------
SQL table comments
All pinba tables are created with sql comment to tell the engine about table purpose and structure, general syntax for comment is as follows (not all reports use all the fields).
> COMMENT='v2/<report_type>/<aggregation_window>/<keys>/<histogram+percentiles>/<filters>';
Take a look at examples first
Packet report (like info in tony2001/pinba_engine)
General information about incoming packets
Table comment syntax
> 'v2/packet/<aggregation_window>/no_keys/<histogram+percentiles>/<filters>';
Example
mysql> CREATE TABLE `info` (
`req_count` bigint(20) unsigned NOT NULL,
`timer_count` bigint(20) unsigned NOT NULL,
`time_total` double NOT NULL,
`ru_utime_total` double NOT NULL,
`ru_stime_total` double NOT NULL,
`traffic` bigint(20) unsigned NOT NULL,
`memory_footprint` bigint(20) unsigned NOT NULL
) ENGINE=PINBA DEFAULT CHARSET=latin1 COMMENT='v2/packet/default_history_time/no_keys/no_percentiles/no_filters'
mysql> select * from info;
+-----------+-------------+-------------------+------------------+-----------------+-----------+------------------+
| req_count | timer_count | time_total | ru_utime_total | ru_stime_total | traffic | memory_footprint |
+-----------+-------------+-------------------+------------------+-----------------+-----------+------------------+
| 3940547 | 59017168 | 6982620.849607239 | 128279.101920963 | 18963.268457099 | 141734072 | 317514981871616 |
+-----------+-------------+-------------------+------------------+-----------------+-----------+------------------+
1 row in set (0.00 sec)
Request data report
Table comment syntax
> 'v2/packet/<aggregation_window>/<key_spec>/<histogram+percentiles>/<filters>';
example (report by script name only here)
mysql> CREATE TABLE `report_by_script_name` (
`script` varchar(64) NOT NULL,
`req_count` int(10) unsigned NOT NULL,
`req_per_sec` float NOT NULL,
`req_percent` float,
`req_time_total` float NOT NULL,
`req_time_per_sec` float NOT NULL,
`req_time_percent` float,
`ru_utime_total` float NOT NULL,
`ru_utime_per_sec` float NOT NULL,
`ru_utime_percent` float,
`ru_stime_total` float NOT NULL,
`ru_stime_per_sec` float NOT NULL,
`ru_stime_percent` float,
`traffic_total` bigint(20) unsigned NOT NULL,
`traffic_per_sec` float NOT NULL,
`traffic_percent` float,
`memory_footprint` bigint(20) NOT NULL,
`memory_per_sec` float NOT NULL,
`memory_percent` float
) ENGINE=PINBA DEFAULT CHARSET=latin1 COMMENT='v2/request/60/~script/no_percentiles/no_filters';
mysql> select * from report_by_script_name; -- skipped some fields for brevity
+----------------+-----------+-------------+----------------+------------------+----------------+------------------+-----------------+------------------+
| script | req_count | req_per_sec | req_time_total | req_time_per_sec | ru_utime_total | ru_stime_per_sec | traffic_per_sec | memory_footprint |
+----------------+-----------+-------------+----------------+------------------+----------------+------------------+-----------------+------------------+
| script-0.phtml | 200001 | 3333.35 | 200.001 | 3.33335 | 0 | 0 | 0 | 0 |
| script-6.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-3.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-5.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-4.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-8.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-9.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-1.phtml | 200001 | 3333.35 | 200.001 | 3.33335 | 0 | 0 | 0 | 0 |
| script-2.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
| script-7.phtml | 200000 | 3333.33 | 200 | 3.33333 | 0 | 0 | 0 | 0 |
+----------------+-----------+-------------+----------------+------------------+----------------+------------------+-----------------+------------------+
10 rows in set (0.00 sec)
Timer data report
This is the one you need for 95% uses
Table comment syntax
> 'v2/packet/<aggregation_window>/<key_spec>/<histogram+percentiles>/<filters>';
example (some complex report)
mysql> CREATE TABLE `tag_info_pinger_call_from_wwwbmamlan` (
`pinger_dst_cluster` varchar(64) NOT NULL,
`pinger_src_host` varchar(64) NOT NULL,
`pinger_dst_host` varchar(64) NOT NULL,
`req_count` int(11) NOT NULL,
`req_per_sec` float NOT NULL,
`req_percent` float,
`hit_count` int(11) NOT NULL,
`hit_per_sec` float NOT NULL,
`hit_percent` float,
`time_total` float NOT NULL,
`time_per_sec` float NOT NULL,
`time_percent` float,
`ru_utime_total` float NOT NULL,
`ru_utime_per_sec` float NOT NULL,
`ru_utime_percent` float,
`ru_stime_total` float NOT NULL,
`ru_stime_per_sec` float NOT NULL,
`ru_stime_percent` float,
`p50` float NOT NULL,
`p75` float NOT NULL,
`p95` float NOT NULL,
`p99` float NOT NULL,
`p100` float NOT NULL,
`histogram_data` text NOT NULL
) ENGINE=PINBA DEFAULT CHARSET=latin1
COMMENT='v2/timer/60/@pinger_dst_cluster,@pinger_src_host,@pinger_dst_host/hv=0:1000:100000,p50,p75,p95,p99,p100/+pinger_phase=call,+pinger_src_cluster=wwwbma.mlan';
example (grouped by host_name, scrip_tname, server_name and value timer tag "tag10")
mysql> CREATE TABLE `report_host_script_server_tag10` (
`host` varchar(64) NOT NULL,
`script` varchar(64) NOT NULL,
`server` varchar(64) NOT NULL,
`tag10` varchar(64) NOT NULL,
`req_count` int(10) unsigned NOT NULL,
`req_per_sec` float NOT NULL,
`hit_count` int(10) unsigned NOT NULL,
`hit_per_sec` float NOT NULL,
`time_total` float NOT NULL,
`time_per_sec` float NOT NULL,
`ru_utime_total` float NOT NULL,
`ru_utime_per_sec` float NOT NULL,
`ru_stime_total` float NOT NULL,
`ru_stime_per_sec` float NOT NULL
) ENGINE=PINBA DEFAULT CHARSET=latin1
COMMENT='v2/timer/60/~host,~script,~server,@tag10/no_percentiles/no_filters';
mysql> select * from report_host_script_server_tag10; -- skipped some fields for brevity
+-----------+----------------+-------------+-----------+-----------+-----------+------------+----------------+----------------+
| host | script | server | tag10 | req_count | hit_count | time_total | ru_utime_total | ru_stime_total |
+-----------+----------------+-------------+-----------+-----------+-----------+------------+----------------+----------------+
| localhost | script-3.phtml | antoxa-test | select | 806 | 806 | 5.642 | 0 | 0 |
| localhost | script-6.phtml | antoxa-test | select | 805 | 805 | 5.635 | 0 | 0 |
| localhost | script-0.phtml | antoxa-test | something | 800 | 800 | 12 | 0 | 0 |
| localhost | script-1.phtml | antoxa-test | select | 804 | 804 | 5.628 | 0 | 0 |
| localhost | script-2.phtml | antoxa-test | something | 797 | 797 | 11.955 | 0 | 0 |
| localhost | script-8.phtml | antoxa-test | select | 803 | 803 | 5.621 | 0 | 0 |
| localhost | script-6.phtml | antoxa-test | something | 805 | 805 | 12.075 | 0 | 0 |
| localhost | script-4.phtml | antoxa-test | select | 798 | 798 | 5.586 | 0 | 0 |
| localhost | script-4.phtml | antoxa-test | something | 798 | 798 | 11.97 | 0 | 0 |
| localhost | script-3.phtml | antoxa-test | something | 806 | 806 | 12.09 | 0 | 0 |
| localhost | script-1.phtml | antoxa-test | something | 804 | 804 | 12.06 | 0 | 0 |
| localhost | script-2.phtml | antoxa-test | select | 797 | 797 | 5.579 | 0 | 0 |
| localhost | script-9.phtml | antoxa-test | something | 806 | 806 | 12.09 | 0 | 0 |
| localhost | script-7.phtml | antoxa-test | select | 801 | 801 | 5.607 | 0 | 0 |
| localhost | script-5.phtml | antoxa-test | select | 802 | 802 | 5.614 | 0 | 0 |
| localhost | script-5.phtml | antoxa-test | something | 802 | 802 | 12.03 | 0 | 0 |
| localhost | script-9.phtml | antoxa-test | select | 806 | 806 | 5.642 | 0 | 0 |
| localhost | script-0.phtml | antoxa-test | select | 800 | 800 | 5.6 | 0 | 0 |
| localhost | script-8.phtml | antoxa-test | something | 803 | 803 | 12.045 | 0 | 0 |
| localhost | script-7.phtml | antoxa-test | something | 801 | 801 | 12.015 | 0 | 0 |
+-----------+----------------+-------------+-----------+-----------+-----------+------------+----------------+----------------+
Active reports information table
This table lists all reports known to the engine with additional information about them.
| Field | Description |
|---|---|
| id | internal id, useful for matching reports with system threads. report calls pthread_setname_np("rh/[id]") |
| table_name | mysql fully qualified table name (including database) |
| internal_name | the name known to the engine (it never changes with table renames, but you shouldn't really care about that). |
| kind | internal report kind (one of the kinds described in this doc, like stats, active, etc.) |
| uptime | time since report creation (seconds) |
| time_window | time window this reports aggregates data for (that you specify when creating a table) |
| tick_count | number of ticks, time_window is split into |
| approx_row_count | approximate row count |
| approx_mem_used | approximate memory usage |
| batches_sent | number of packet batches sent from coordinator to report thread |
| batches_received | number of packet batches received by report thread (if you have != 0 here, you're losing batches and packets) |
| packets_received | packets received and processed |
| packets_lost | packets that could not be processed and had to be dropped (aka, report couldn't cope with such packet rate) |
| packets_aggregated | number of packets that we took useful information from |
| packets_dropped_by_bloom | number of packets dropped by packet-level bloom filter |
| packets_dropped_by_filters | number of packets dropped by packet-level filters |
| packets_dropped_by_rfield | number of packets dropped by request_field aggregation |
| packets_dropped_by_rtag | number of packets dropped by request_tag aggregation |
| packets_dropped_by_timertag | number of packets dropped by timer_tag aggregation (i.e. no useful timers) |
| timers_scanned | number of timers scanned |
| timers_aggregated | number of timers that we took useful information from |
| timers_skipped_by_bloom | number of timers skipped by timer-level bloom filter |
| timers_skipped_by_filters | number of timers skipped by timertag filters |
| timers_skipped_by_tags | number of timers skipped by not having required tags present |
| ru_utime | rusage: user time |
| ru_stime | rusage: system time |
| last_tick_time | time we last merged temporary data to selectable data |
| last_tick_prepare_duration | time it took to prepare to merge temp data to selectable data |
| last_snapshot_merge_duration | time it took to prepare last select (not implemented yet) |
Table comment syntax
> 'v2/active'
example
mysql> CREATE TABLE IF NOT EXISTS `pinba`.`active` (
`id` int(10) unsigned NOT NULL,
`table_name` varchar(128) NOT NULL,
`internal_name` varchar
Content type
Image
Digest
Size
293 MB
Last updated
almost 8 years ago
docker pull alexanderilyin/pinba2