y-ken / fluent-plugin-mysql-query

Fluentd Input plugin to execute mysql query and fetch rows. It is useful for stationary interval metrics measurement.
https://rubygems.org/gems/fluent-plugin-mysql-query
Other
21 stars 8 forks source link

Support multiple query #14

Open y-ken opened 7 years ago

y-ken commented 7 years ago

It is the time to improvement for needs satisfaction. Due to support single statement for now, It cause many mysql connection only for fluentd.

plan

<source>
  type            mysql_query
  host            localhost           # Optional (default: localhost)
  port            3306                # Optional (default: 3306)
  username        nagios              # Optional (default: root)
  password        passw0rd            # Optional (default nopassword)
  interval        30s                 # Optional (default: 1m)
  tag             input.mysql         # Required
  <query>
    # I'd like to support multiple line
    query           "
      SHOW VARIABLES LIKE 'Thread_%';
    "
    # record hostname into message.
    record_hostname yes                 # Optional (default: no)
    # multi row results into nested record or separated message.
    nest_result     yes                 # Optional (default: no)
    nest_key        data                # Optional (default: result)
    # record the number of lines of a query result
    row_count       yes                 # Optional (default: no)
    row_count_key   row_count           # Optional (default: row_count)
  </query>
  <query>
    query           SHOW VARIABLES LIKE 'Thread_%' # Required
    # record hostname into message.
    record_hostname yes                 # Optional (default: no)
    # multi row results into nested record or separated message.
    nest_result     yes                 # Optional (default: no)
    nest_key        data                # Optional (default: result)
    # record the number of lines of a query result
    row_count       yes                 # Optional (default: no)
    row_count_key   row_count           # Optional (default: row_count)
  </query>
</source>
y-ken commented 7 years ago

Hi @okkez @cosmo0920 I'm afraid would you please consider to support for this improvements?

okkez commented 7 years ago

In current (released) version, query is a top level parameter. Do this plan drops backward compatibilities? I think query/query/ is not good name.

How about that change default value nest_key to nil and remove nest_result? This plugin returns nested values if user specify nest_key parameter. Otherwise this plugin returns flatten values. row_count and row_count_key are ditto with above, too.

Do you want to change record_hostname, nest_result, nest_key, row_count, row_count_key per query? I want to set these parameters only once on top level.

My proposal:

<source>
  @type mysql_query
  host            localhost           # Optional (default: localhost)
  port            3306                # Optional (default: 3306)
  username        nagios              # Optional (default: root)
  password        passw0rd            # Optional (default nopassword)
  interval        30s                 # Optional (default: 1m)
  tag             input.mysql         # Required
  parallel      no                    # Optional (default: no)
  record_hostname yes                 # Optional (default: no)
  nest_key   data                     # Optional (default: nil)
  row_count_key count                 # Optional (default: nil)
  <query>
    query SHOW VARIABLES LIKE 'Thread_%';
  </query>
  <query>
    query SHOW VARIABLES LIKE 'Thread_%';
  </query>
</source>