Skip to content

Commit

Permalink
Add SQL module (elastic#13257)
Browse files Browse the repository at this point in the history
The SQL module can collect metrics and other data with
custom queries, using the database drivers included in
Metricbeat.
  • Loading branch information
Amanda H. L. de Andrade Katz authored and jsoriano committed Dec 11, 2019
1 parent 936e73a commit a3136a4
Show file tree
Hide file tree
Showing 31 changed files with 3,328 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- system/raid metricset now uses /sys/block instead of /proc/mdstat for data. {pull}11613[11613]
- kubernetes.container.cpu.limit.cores and kubernetes.container.cpu.requests.cores are now floats. {issue}11975[11975]
- Add statistic option into cloudwatch metricset. If there is no statistic method specified, default is to collect Average, Sum, Maximum, Minimum and SampleCount. {issue}12370[12370] {pull}12840[12840]
- Add sql module that fetches metrics from a SQL database {pull}13257[13257]

*Packetbeat*

Expand Down
30 changes: 30 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3740,6 +3740,36 @@ License type (autodetected): Apache-2.0
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/jmoiron/sqlx
Revision: d7d95172beb5a538ff08c50a6e98aee6e7c41f40
License type (autodetected): MIT
./x-pack/metricbeat/module/sql/vendor/github.com/jmoiron/sqlx/LICENSE:
--------------------------------------------------------------------
Copyright (c) 2013, Jason Moiron

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.


--------------------------------------------------------------------
Dependency: github.com/joeshaw/multierror
Revision: 69b34d4ec901851247ae7e77d33909caf9df99ed
Expand Down
62 changes: 62 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ grouped in the following categories:
* <<exported-fields-prometheus>>
* <<exported-fields-rabbitmq>>
* <<exported-fields-redis>>
* <<exported-fields-sql>>
* <<exported-fields-statsd>>
* <<exported-fields-system>>
* <<exported-fields-tomcat>>
Expand Down Expand Up @@ -29456,6 +29457,67 @@ type: long
--
[[exported-fields-sql]]
== sql fields
sql module
[float]
=== sql
`sql` fetches metrics from a SQL database
[float]
=== query
query
*`sql.query.driver`*::
+
--
Driver used to execute the query.
type: keyword
--
*`sql.query.query`*::
+
--
Query executed to collect metrics.
type: keyword
--
*`sql.query.metrics.numeric.*`*::
+
--
Numeric metrics collected.
type: object
--
*`sql.query.metrics.string.*`*::
+
--
Non-numeric values collected.
type: object
--
[[exported-fields-statsd]]
== Statsd fields
Expand Down
45 changes: 45 additions & 0 deletions metricbeat/docs/modules/sql.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
////
This file is generated! See scripts/mage/docs_collector.go
////

[[metricbeat-module-sql]]
[role="xpack"]
== sql module

beta[]

This is the sql module that fetches metrics from a SQL database. You can define driver, datasource and SQL query.




[float]
=== Example configuration

The sql module supports the standard configuration options that are described
in <<configuration-metricbeat>>. Here is an example configuration:

[source,yaml]
----
metricbeat.modules:
- module: sql
metricsets:
- query
period: 10s
hosts: ["localhost"]
driver: "postgres"
datasource: "user=myuser password=mypassword dbname=mydb sslmode=disable"
sql_query: "select now()"
----

[float]
=== Metricsets

The following metricsets are available:

* <<metricbeat-metricset-sql-query,query>>

include::sql/query.asciidoc[]

23 changes: 23 additions & 0 deletions metricbeat/docs/modules/sql/query.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
////
This file is generated! See scripts/mage/docs_collector.go
////

[[metricbeat-metricset-sql-query]]
=== sql query metricset

beta[]

include::../../../../x-pack/metricbeat/module/sql/query/_meta/docs.asciidoc[]


==== Fields

For a description of each field in the metricset, see the
<<exported-fields-sql,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../../x-pack/metricbeat/module/sql/query/_meta/data.json[]
----
3 changes: 3 additions & 0 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ This file is generated! See scripts/mage/docs_collector.go
.3+| .3+| |<<metricbeat-metricset-redis-info,info>>
|<<metricbeat-metricset-redis-key,key>>
|<<metricbeat-metricset-redis-keyspace,keyspace>>
|<<metricbeat-module-sql,sql>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-sql-query,query>> beta[]
|<<metricbeat-module-statsd,Statsd>> beta[] |image:./images/icon-no.png[No prebuilt dashboards] |
.1+| .1+| |<<metricbeat-metricset-statsd-server,server>> beta[]
|<<metricbeat-module-system,System>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
Expand Down Expand Up @@ -261,6 +263,7 @@ include::modules/postgresql.asciidoc[]
include::modules/prometheus.asciidoc[]
include::modules/rabbitmq.asciidoc[]
include::modules/redis.asciidoc[]
include::modules/sql.asciidoc[]
include::modules/statsd.asciidoc[]
include::modules/system.asciidoc[]
include::modules/tomcat.asciidoc[]
Expand Down
2 changes: 2 additions & 0 deletions x-pack/metricbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions x-pack/metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,18 @@ metricbeat.modules:
# Redis AUTH password. Empty by default.
#password: foobared

#--------------------------------- Sql Module ---------------------------------
- module: sql
metricsets:
- query
period: 10s
hosts: ["localhost"]

driver: "postgres"
datasource: "user=myuser password=mypassword dbname=mydb sslmode=disable"
sql_query: "select now()"


#-------------------------------- Statsd Module --------------------------------
- module: statsd
host: "localhost"
Expand Down
10 changes: 10 additions & 0 deletions x-pack/metricbeat/module/sql/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- module: sql
metricsets:
- query
period: 10s
hosts: ["localhost"]

driver: "postgres"
datasource: "user=myuser password=mypassword dbname=mydb sslmode=disable"
sql_query: "select now()"

3 changes: 3 additions & 0 deletions x-pack/metricbeat/module/sql/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is the sql module that fetches metrics from a SQL database. You can define driver, datasource and SQL query.


11 changes: 11 additions & 0 deletions x-pack/metricbeat/module/sql/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- key: sql
title: "sql"
release: beta
description: >
sql module
fields:
- name: sql
type: group
description: >
`sql` fetches metrics from a SQL database
fields:
6 changes: 6 additions & 0 deletions x-pack/metricbeat/module/sql/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

// Package sql is a Metricbeat module that collects information from databases using SQL queries.
package sql
23 changes: 23 additions & 0 deletions x-pack/metricbeat/module/sql/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions x-pack/metricbeat/module/sql/query/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"@timestamp":"2016-05-23T08:05:34.853Z",
"beat":{
"hostname":"beathost",
"name":"beathost"
},
"metricset":{
"host":"localhost",
"module":"sql",
"name":"query",
"rtt":44269
},
"sql":{
"metrics":{
"numeric":{
"mynumericfield":1
},
"string":{
"mystringfield":"abc"
}
},
"driver":"postgres",
"query":"select * from mytable"
},
"type":"metricsets"
}
4 changes: 4 additions & 0 deletions x-pack/metricbeat/module/sql/query/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The sql `query` metricset collect rows returned by a query.

Fields names (columns) will be returned as lowercase.
Values will be returned as numeric or string.
24 changes: 24 additions & 0 deletions x-pack/metricbeat/module/sql/query/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: query
type: group
release: beta
description: >
query
fields:
- name: driver
type: keyword
description: >
Driver used to execute the query.
- name: query
type: keyword
description: >
Query executed to collect metrics.
- name: metrics.numeric.*
type: object
object_type: double
description: >
Numeric metrics collected.
- name: metrics.string.*
type: object
object_type: keyword
description: >
Non-numeric values collected.
Loading

0 comments on commit a3136a4

Please sign in to comment.