Skip to content

Commit

Permalink
Support mysql prepare statement command (elastic#8084)
Browse files Browse the repository at this point in the history
This improves Packetbeat's mysql decoder to understand and report prepared statements.

```
  "query": "select distinct count(distinct purchasede0_.id) as col_0_0_ from purchase_demand purchasede0_ where purchasede0_.chain_master=? and purchasede0_.create_time>=? and purchasede0_.create_time<=?",
  "params": [
    "A1224638",
    "2017/7/28 0:0:0",
    "2017/10/28 23:59:59"
  ],
```
  • Loading branch information
adriansr authored Jan 15, 2019
1 parent 8a04a80 commit 0044a06
Show file tree
Hide file tree
Showing 12 changed files with 444 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Packetbeat*

- Add support to decode mysql prepare statement command. {pull}8084[8084]

*Functionbeat*

==== Deprecated
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/_meta/beat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ packetbeat.protocols:

# Configure the ports where to listen for MySQL traffic. You can disable
# the MySQL protocol by commenting out the list of ports.
ports: [3306]
ports: [3306,3307]

# If this option is enabled, the raw message of the request (`request` field)
# is sent to Elasticsearch. The default is false.
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/_meta/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packetbeat.protocols:
- type: mysql
# Configure the ports where to listen for MySQL traffic. You can disable
# the MySQL protocol by commenting out the list of ports.
ports: [3306]
ports: [3306,3307]

- type: pgsql
# Configure the ports where to listen for Pgsql traffic. You can disable
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/docs/gettingstarted.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ packetbeat.protocols:
ports: [11211]
- type: mysql
ports: [3306]
ports: [3306,3307]
- type: pgsql
ports: [5432]
Expand Down
50 changes: 43 additions & 7 deletions packetbeat/docs/packetbeat-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ packetbeat.protocols:
ports: [11211]
- type: mysql
ports: [3306]
ports: [3306,3307]
- type: redis
ports: [6379]
Expand Down Expand Up @@ -899,22 +899,58 @@ The memcache protocol analyzer will wait for the number of milliseconds specifie
`udptransactiontimeout` before publishing quiet messages. Non-quiet messages or
quiet requests with an error response are published immediately.

[[packetbeat-mysql-pgsql-options]]
=== Capture MySQL and PgSQL traffic
[[packetbeat-mysql-options]]
=== Capture MySQL traffic

++++
<titleabbrev>MySQL and PgSQL</titleabbrev>
<titleabbrev>MySQL</titleabbrev>
++++

The `mysql` and `pgsql` sections of the +{beatname_lc}.yml+ config file specify configuration options for the MySQL
and PgSQL protocols.
The `mysql` section of the +{beatname_lc}.yml+ config file specifies configuration
options for the MySQL protocols.

[source,yaml]
------------------------------------------------------------------------------
packetbeat.protocols:
- type: mysql
ports: [3306]
ports: [3306,3307]
------------------------------------------------------------------------------

==== Configuration options

Also see <<common-protocol-options>>.

===== `max_rows`

The maximum number of rows from the SQL message to publish to Elasticsearch. The
default is 10 rows.


===== `max_row_length`

The maximum length in bytes of a row from the SQL message to publish to
Elasticsearch. The default is 1024 bytes.

==== `statement_timeout`

The duration for which prepared statements are cached after their last use.
Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
The default is `1h`.

[[packetbeat-pgsql-options]]
=== Capture PgSQL traffic

++++
<titleabbrev>PgSQL</titleabbrev>
++++

The `pgsql` sections of the +{beatname_lc}.yml+ config file specifies configuration
options for the PgSQL protocols.

[source,yaml]
------------------------------------------------------------------------------
packetbeat.protocols:
- type: pgsql
ports: [5432]
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/packetbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ packetbeat.protocols:

# Configure the ports where to listen for MySQL traffic. You can disable
# the MySQL protocol by commenting out the list of ports.
ports: [3306]
ports: [3306,3307]

# If this option is enabled, the raw message of the request (`request` field)
# is sent to Elasticsearch. The default is false.
Expand Down
2 changes: 1 addition & 1 deletion packetbeat/packetbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packetbeat.protocols:
- type: mysql
# Configure the ports where to listen for MySQL traffic. You can disable
# the MySQL protocol by commenting out the list of ports.
ports: [3306]
ports: [3306,3307]

- type: pgsql
# Configure the ports where to listen for Pgsql traffic. You can disable
Expand Down
12 changes: 8 additions & 4 deletions packetbeat/protos/mysql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,26 @@
package mysql

import (
"time"

"github.com/elastic/beats/packetbeat/config"
"github.com/elastic/beats/packetbeat/protos"
)

type mysqlConfig struct {
config.ProtocolCommon `config:",inline"`
MaxRowLength int `config:"max_row_length"`
MaxRows int `config:"max_rows"`
MaxRowLength int `config:"max_row_length"`
MaxRows int `config:"max_rows"`
StatementTimeout time.Duration `config:"statement_timeout"`
}

var (
defaultConfig = mysqlConfig{
ProtocolCommon: config.ProtocolCommon{
TransactionTimeout: protos.DefaultTransactionExpiration,
},
MaxRowLength: 1024,
MaxRows: 10,
MaxRowLength: 1024,
MaxRows: 10,
StatementTimeout: 3600 * time.Second,
}
)
Loading

0 comments on commit 0044a06

Please sign in to comment.