Skip to content

Commit

Permalink
Add Nginx stub status to metricbeat (elastic#1642)
Browse files Browse the repository at this point in the history
* Add Nginx module with stub status metric set
* Return error if Nginx stub status cannot be parsed
* Add Nginx stub status integration test
* Add fields for Nginx and Nginx stub metricset (#2)
  • Loading branch information
KS Chan authored and ruflin committed May 17, 2016
1 parent 016ca9a commit 86d7c78
Show file tree
Hide file tree
Showing 24 changed files with 685 additions and 4 deletions.
6 changes: 6 additions & 0 deletions metricbeat/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ beat:
links:
- apache
- mysql
- nginx
- redis
- zookeeper
environment:
- APACHE_HOST=apache
- APACHE_PORT=80
- NGINX_HOST=nginx
- NGINX_PORT=80
- REDIS_HOST=redis
- REDIS_PORT=6379
- MYSQL_DSN=root:test@tcp(mysql:3306)/
Expand All @@ -31,6 +34,9 @@ mysql:
environment:
- MYSQL_ROOT_PASSWORD=test

nginx:
build: ${PWD}/tests/environments/nginx

redis:
image: redis:3.2.0

Expand Down
4 changes: 2 additions & 2 deletions metricbeat/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ waitFor() {
echo
echo >&2 '${3} is not available'
echo >&2 "Address: ${1}:${2}"

}

# Main
waitFor ${APACHE_HOST} ${APACHE_PORT} Apache
waitFor ${REDIS_HOST} ${REDIS_PORT} Redis
waitFor ${MYSQL_HOST} ${MYSQL_PORT} MySQL
waitFor ${NGINX_HOST} ${NGINX_PORT} Nginx
waitFor ${REDIS_HOST} ${REDIS_PORT} Redis
waitFor ${ZOOKEEPER_HOST} ${ZOOKEEPER_PORT} Zookeeper
exec "$@"
84 changes: 84 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ grouped in the following categories:
* <<exported-fields-beat>>
* <<exported-fields-common>>
* <<exported-fields-mysql>>
* <<exported-fields-nginx>>
* <<exported-fields-redis>>
* <<exported-fields-system>>
* <<exported-fields-zookeeper>>
Expand Down Expand Up @@ -445,6 +446,89 @@ type: integer
The number of bytes sent to all clients.


[[exported-fields-nginx]]
=== Nginx Status Fields

Nginx server status metrics collected from various modules.



=== nginx-stubstatus Fields

`nginx-stubstatus` contains the metrics that were scraped from the ngx_http_stub_status_module status page.



==== nginx-stubstatus.hostname

type: keyword

Nginx hostname


==== nginx-stubstatus.active

type: integer

The current number of active client connections including Waiting connections.


==== nginx-stubstatus.accepts

type: integer

The total number of accepted client connections.


==== nginx-stubstatus.handled

type: integer

The total number of handled client connections.


==== nginx-stubstatus.dropped

type: integer

The total number of dropped client connections.


==== nginx-stubstatus.requests

type: integer

The total number of client requests.


==== nginx-stubstatus.current

type: integer

The current number of client requests.


==== nginx-stubstatus.reading

type: integer

The current number of connections where nginx is reading the request header.


==== nginx-stubstatus.writing

type: integer

The current number of connections where nginx is writing the response back to the client.


==== nginx-stubstatus.waiting

type: integer

The current number of idle client connections waiting for a request.


[[exported-fields-redis]]
=== Redis Fields

Expand Down
40 changes: 40 additions & 0 deletions metricbeat/docs/modules/nginx.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
////
This file is generated! See scripts/docs_collector.py
////

[[metricbeat-module-nginx]]
== Nginx Module

This module periodically fetches metrics from https://nginx.org/[Nginx] servers.



=== Example Configuration

The Nginx module supports the standard configuration options which can be found
here (add link). Below is an example of a configuration option:

[source,yaml]
----
metricbeat.modules:
#----------------------------- Nginx Module ----------------------------------
- module: nginx
metricsets: ["stubstatus"]
enabled: true
period: 1s
# Nginx hosts
hosts: ["http://127.0.0.1/"]
# Path to server status. Default server-status
#server_status_path: "server-status"
----

=== MetricSets

The following MetricSets are available:

* <<metricbeat-metricset-nginx-stubstatus,stubstatus>>

include::nginx/stubstatus.asciidoc[]

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

[[metricbeat-metricset-nginx-stubstatus]]
=== Nginx StubStatus MetricSet

The Nginx StubStatus MetricSet collects data from the Nginx
http://nginx.org/en/docs/http/ngx_http_stub_status_module.html[ngx_http_stub_status] module. It
scrapes the server status data from the web page generated by ngx_http_stub_status.



==== Fields

A description of each field in the MetricSet can be found in the
<<exported-fields-nginx,exported fields>> section

Below is an example document generated by this metricset.

[source,json]
----
----
12 changes: 12 additions & 0 deletions metricbeat/etc/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ metricbeat.modules:
# Password of hosts. Empty by default
#password: test

#----------------------------- Nginx Module ----------------------------------
- module: nginx
metricsets: ["stubstatus"]
enabled: true
period: 1s

# Nginx hosts
hosts: ["http://127.0.0.1/"]

# Path to server status. Default server-status
#server_status_path: "server-status"

#------------------------------- Redis Module ---------------------------------
- module: redis
metricsets: ["info"]
Expand Down
55 changes: 55 additions & 0 deletions metricbeat/etc/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,61 @@
type: integer
description: >
The number of bytes sent to all clients.
- key: nginx
title: "Nginx Status"
description: >
Nginx server status metrics collected from various modules.
fields:
- name: nginx
type: group
description: >
nginx contains the metrics that were scraped from nginx.
fields:
- name: nginx-stubstatus
type: group
description: >
`nginx-stubstatus` contains the metrics that were scraped from the ngx_http_stub_status_module status page.
fields:
- name: hostname
type: keyword
description: >
Nginx hostname
- name: active
type: integer
description: >
The current number of active client connections including Waiting connections.
- name: accepts
type: integer
description: >
The total number of accepted client connections.
- name: handled
type: integer
description: >
The total number of handled client connections.
- name: dropped
type: integer
description: >
The total number of dropped client connections.
- name: requests
type: integer
description: >
The total number of client requests.
- name: current
type: integer
description: >
The current number of client requests.
- name: reading
type: integer
description: >
The current number of connections where nginx is reading the request header.
- name: writing
type: integer
description: >
The current number of connections where nginx is writing the response back to the client.
- name: waiting
type: integer
description: >
The current number of idle client connections waiting for a request.
- key: redis
title: "Redis"
description: >
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/include/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
_ "github.com/elastic/beats/metricbeat/module/apache/status"
_ "github.com/elastic/beats/metricbeat/module/mysql"
_ "github.com/elastic/beats/metricbeat/module/mysql/status"
_ "github.com/elastic/beats/metricbeat/module/nginx"
_ "github.com/elastic/beats/metricbeat/module/nginx/stubstatus"
_ "github.com/elastic/beats/metricbeat/module/redis"
_ "github.com/elastic/beats/metricbeat/module/redis/info"
_ "github.com/elastic/beats/metricbeat/module/system"
Expand Down
38 changes: 37 additions & 1 deletion metricbeat/metricbeat.template-es2x.json
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,42 @@
}
}
},
"nginx-stubstatus": {
"properties": {
"accepts": {
"type": "integer"
},
"active": {
"type": "integer"
},
"current": {
"type": "integer"
},
"dropped": {
"type": "integer"
},
"handled": {
"type": "integer"
},
"hostname": {
"ignore_above": 1024,
"index": "not_analyzed",
"type": "string"
},
"reading": {
"type": "integer"
},
"requests": {
"type": "integer"
},
"waiting": {
"type": "integer"
},
"writing": {
"type": "integer"
}
}
},
"redis": {
"properties": {
"info": {
Expand Down Expand Up @@ -644,4 +680,4 @@
"index.refresh_interval": "5s"
},
"template": "metricbeat-*"
}
}
37 changes: 36 additions & 1 deletion metricbeat/metricbeat.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,41 @@
}
}
},
"nginx-stubstatus": {
"properties": {
"accepts": {
"type": "integer"
},
"active": {
"type": "integer"
},
"current": {
"type": "integer"
},
"dropped": {
"type": "integer"
},
"handled": {
"type": "integer"
},
"hostname": {
"ignore_above": 1024,
"type": "keyword"
},
"reading": {
"type": "integer"
},
"requests": {
"type": "integer"
},
"waiting": {
"type": "integer"
},
"writing": {
"type": "integer"
}
}
},
"redis": {
"properties": {
"info": {
Expand Down Expand Up @@ -621,4 +656,4 @@
"index.refresh_interval": "5s"
},
"template": "metricbeat-*"
}
}
Loading

0 comments on commit 86d7c78

Please sign in to comment.