Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support appmetrics v4 and Elasticsearch/Kibana 6 #33

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "strongloop",
"env": {
"node": true
},
"parserOptions": { "ecmaVersion": 6 },
"rules": {
"eqeqeq": "off",
"max-len": ["error", 120, 8, {"ignoreComments": true}],
"comma-dangle": "off",
"spaced-comment": ["error", "always", { "exceptions": ["*"] }]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
76 changes: 43 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ELK Connector for Node Application Metrics

A connector that collects data using 'appmetrics' and sends it to a configured ElasticSearch instance in LogStash format for use with Kibana.
A connector that collects data using 'appmetrics' and sends it to a configured Elasticsearch instance in LogStash format for use with Kibana.

## Getting Started

Expand All @@ -9,55 +9,64 @@ The ELK Connector for Node Application Metrics can be installed via `npm`:
```sh
$ npm install appmetrics-elk
```
This is designed to be used with an [ElasticSearch][1] database, and a visualization tool such as [Kibana][2].
This is designed to be used with an [Elasticsearch][1] database, and a visualization tool such as [Kibana][2].

### Configuring the ELK Connector for Node Application Metrics

The connector can be used in your application by requiring it as the first line of your application:
```js
var appmetrics = require('appmetrics-elk').monitor();
const appmetrics = require('appmetrics');
//...
require('appmetrics-elk')(appmetrics.monitor());
```
This will send all of the available `appmetrics` data to the ElasticSearch instance, as well as returning an appmetrics object that can be used to control data collection.
This will send all of the available `appmetrics` data to the Elasticsearch instance, as well as returning an appmetrics object that can be used to control data collection.

```js
var appmetrics = require('appmetrics-elk').monitor();
const appmetrics = require('appmetrics')
//...
require('appmetrics-elk')(appmetrics.monitor());
appmetrics.disable('mysql'); // disable MySQL monitoring
```

Additionally, the `monitor()` API call can be passed an optional [ElasticSearch Configuration][3] object to configure the ElasticSearch connection, including database location and security.
Additionally, the connector function call can be passed an optional [Elasticsearch Configuration][3] object to configure the Elasticsearch connection, including database location and security.

The same configuration object can be used to pass configuration to the ELK connector. The following configurations can be applied:
* `index` (String) the name of the index to use for storing the monitoring data. The default is `appmetrics`.
* `applicationName` (String) the name to use for the applicationName field in the monitoring data. The default is the name of the applications main file, eg. `app.js`.
* `app` (String) the name to use for the app field in the monitoring data. The default is the name of the applications main file, eg. `app.js`.

```js
var config = {
hosts: [
'https://es1.bluemix.net',
'https://es2.bluemix.net'
],
ssl: {
ca: fs.readFileSync('./cacert.pem'),
rejectUnauthorized: true
},
const appmetrics = require('appmetrics');
const config = {
index: 'nodedata',
applicationName: 'HelloWorld'
app: 'HelloWorld',
// esClient: {an existing Elasticsearch client instance}
esConfig: {
hosts: [
'https://es1.bluemix.net',
'https://es2.bluemix.net'
],
ssl: {
ca: fs.readFileSync('./cacert.pem'),
rejectUnauthorized: true
}
}
}

var appmetrics = require('appmetrics-elk').monitor(config);
const monitoring = appmetrics.monitor();
appmetrics.disable('mysql'); // disable MySQL monitoring
require('appmetrics-elk')(monitoring, config);
```

### Data Provided to ElasticSearch
### Data Provided to Elasticsearch

The ELK Connector for Node Application Metrics uploads its data to the 'appmetrics' index in ElasticSearch. It sends the following values to ElasticSearch for every monitoring entry:
The ELK Connector for Node Application Metrics uploads its data to the 'appmetrics' index in Elasticsearch. It sends the following values to Elasticsearch for every monitoring entry:

Value | Description
:------------------------|:-------------------------------------------
timestamp | The time when the monitoring event occurred
hostName | The hostname for the machine the monitored process is running on
@timestamp | The time when the monitoring event occurred
host | The hostname for the machine the monitored process is running on
pid | The process ID for the monitored process
applicationName | The JavaScript file used to launch the application, or a custom name
app | The JavaScript file used to launch the application, or a custom name

Additional data is then included depending on the monitoring event.

Expand Down Expand Up @@ -115,6 +124,8 @@ Additional data is then included depending on the monitoring event.

Value | Description
:------------------------|:-------------------------------------------
mongo.collection | The MongoDB collection name query made on
mongo.method | The executed method for the query, such as find, update
mongo.query | The query made of the MongoDB database
mongo.duration | The time taken for the MongoDB query to be responded to in ms

Expand Down Expand Up @@ -178,28 +189,27 @@ Additional data is then included depending on the monitoring event.
mqlight.duration | The time taken for the message to be handled to in ms

<a name="custom-data"></a>
### Sending Custom Data to ElasticSearch
The Node Application Metrics to ELK Connector registers for events that it is aware of, and forwards the data from those events to ElasticSearch. The registration for those events is based on the 'mappings' files in the following directory:
### Sending Custom Data to Elasticsearch
The Node Application Metrics to ELK Connector registers for events that it is aware of, and forwards the data from those events to Elasticsearch. The registration for those events is based on the 'mappings' files in the following directory:
```sh
node_modules/appmetrics-elk/mappings/
```
Any mappings files found in that directory are both used to configure how ElasticSearch handles the data, and to configure the monitoring events that are forwarded.
Any mappings files found in that directory are both used to configure how Elasticsearch handles the data, and to configure the monitoring events that are forwarded.

The `type` field is used to determine the name of the event to register for, and the `properties` fields are used to determine the values to send. Note that the values in the properties entry in the mapping file must match the fields in the monitoring event data. For example, the CPU event has the following data:
* `process`
* `system`

The mapping file that causes this data to be sent to ElasticSearch therefore has the following structure:
The mapping file that causes this data to be sent to Elasticsearch therefore has the following structure:
```json
{
"index": "appmetrics",
"type": "cpu",
"type": "doc",
"body": {
"_source" : {"compress" : true},
"_ttl" : {"enabled" : true, "default" : "90d"},
"properties": {
"timestamp": {"type": "date", "format": "dateOptionalTime"},
"hostName": {"type": "string", "index": "not_analyzed"},
"type": {"type": "keyword"},
"@timestamp": {"type": "date", "format": "dateOptionalTime"},
"host": {"type": "keyword"},
"pid": {"type": "integer"},
"cpu": {
"type": "nested",
Expand All @@ -224,7 +234,7 @@ During startup the ELK Connector for Node Application Metrics attempts to provid

Each of these configurations are dynamically loaded from the 'indexes', 'mappings', 'charts' and 'dashboards' directories in the `appmetrics-elk` install directory. It is therefore possible to prevent the configurations from being automatically added by deleting those files, or to add to them by adding existing files.

**Note:** The 'mappings' directory also provides the configuration of which types of monitoring data are uploaded to ElasticSearch so entries should only be deleted if necessary. See *[Sending Custom Data to ElasticSeach](#custom-data)* for more information.
**Note:** The 'mappings' directory also provides the configuration of which types of monitoring data are uploaded to Elasticsearch so entries should only be deleted if necessary. See *[Sending Custom Data to ElasticSeach](#custom-data)* for more information.

### Visualizing the data with Kibana 4
The pre-configuration for Kibana 4 provdes a number of default visualizations, as well as a default dashboard. These can subsequently be modified or new visualizations and dashboards created.
Expand Down
19 changes: 11 additions & 8 deletions charts/gcmemory.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"index": ".kibana",
"type": "visualization",
"id": "GC-Memory-Usage",
"type": "doc",
"id": "visualization:GC-Memory-Usage",
"body": {
"title": "GC Memory Usage",
"visState": "{\"type\":\"line\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"showCircles\":true,\"smoothLines\":false,\"interpolate\":\"linear\",\"scale\":\"linear\",\"drawLinesBetweenPoints\":true,\"radiusRatio\":9,\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"gc.used\"}},{\"id\":\"2\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"gc.size\"}},{\"id\":\"3\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
"type": "visualization",
"visualization": {
"title": "GC Memory Usage",
"visState": "{\"type\":\"line\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"showCircles\":true,\"smoothLines\":false,\"interpolate\":\"linear\",\"scale\":\"linear\",\"drawLinesBetweenPoints\":true,\"radiusRatio\":9,\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"gc.used\"}},{\"id\":\"2\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"gc.size\"}},{\"id\":\"3\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
}
}
}
}
19 changes: 11 additions & 8 deletions charts/gcperf.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"index": ".kibana",
"type": "visualization",
"id": "GC-Performance",
"type": "doc",
"id": "visualization:GC-Performance",
"body": {
"title": "GC Performance",
"visState": "{\"type\":\"line\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"showCircles\":true,\"smoothLines\":false,\"interpolate\":\"linear\",\"scale\":\"linear\",\"drawLinesBetweenPoints\":true,\"radiusRatio\":9,\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"gc.duration\"}},{\"id\":\"3\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
"type": "visualization",
"visualization": {
"title": "GC Performance",
"visState": "{\"type\":\"line\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"showCircles\":true,\"smoothLines\":false,\"interpolate\":\"linear\",\"scale\":\"linear\",\"drawLinesBetweenPoints\":true,\"radiusRatio\":9,\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"gc.duration\"}},{\"id\":\"3\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
}
}
}
}
19 changes: 11 additions & 8 deletions charts/mongoperf.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"index": ".kibana",
"type": "visualization",
"id": "MongoDB-Performance",
"type": "doc",
"id": "visualization:MongoDB-Performance",
"body": {
"title": "MongoDB Performance",
"visState": "{\"type\":\"histogram\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"scale\":\"linear\",\"mode\":\"grouped\",\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"mongo.duration\"}},{\"id\":\"2\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"type\":\"max\",\"schema\":\"metric\",\"params\":{\"field\":\"mongo.duration\"}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"mongo.query\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}},{\"id\":\"5\",\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
"type": "visualization",
"visualization": {
"title": "MongoDB Performance",
"visState": "{\"type\":\"histogram\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"scale\":\"linear\",\"mode\":\"grouped\",\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"mongo.duration\"}},{\"id\":\"2\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"type\":\"max\",\"schema\":\"metric\",\"params\":{\"field\":\"mongo.duration\"}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"mongo.query\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}},{\"id\":\"5\",\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
}
}
}
}
19 changes: 11 additions & 8 deletions charts/mysqlperf.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"index": ".kibana",
"type": "visualization",
"id": "MySQL-Performance",
"type": "doc",
"id": "visualization:MySQL-Performance",
"body": {
"title": "MySQL Performance",
"visState": "{\"type\":\"histogram\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"scale\":\"linear\",\"mode\":\"grouped\",\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"mysql.duration\"}},{\"id\":\"2\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"type\":\"max\",\"schema\":\"metric\",\"params\":{\"field\":\"mysql.duration\"}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"mysql.query\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}},{\"id\":\"5\",\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
"type": "visualization",
"visualization": {
"title": "MySQL Performance",
"visState": "{\"type\":\"histogram\",\"params\":{\"shareYAxis\":true,\"addTooltip\":true,\"addLegend\":true,\"scale\":\"linear\",\"mode\":\"grouped\",\"times\":[],\"addTimeMarker\":false,\"defaultYExtents\":false,\"setYExtents\":false,\"yAxis\":{}},\"aggs\":[{\"id\":\"1\",\"type\":\"avg\",\"schema\":\"metric\",\"params\":{\"field\":\"mysql.duration\"}},{\"id\":\"2\",\"type\":\"date_histogram\",\"schema\":\"segment\",\"params\":{\"field\":\"@timestamp\",\"interval\":\"auto\",\"customInterval\":\"2h\",\"min_doc_count\":1,\"extended_bounds\":{}}},{\"id\":\"3\",\"type\":\"max\",\"schema\":\"metric\",\"params\":{\"field\":\"mysql.duration\"}},{\"id\":\"4\",\"type\":\"terms\",\"schema\":\"split\",\"params\":{\"field\":\"mysql.query\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\",\"row\":true}},{\"id\":\"5\",\"type\":\"terms\",\"schema\":\"group\",\"params\":{\"field\":\"pid\",\"size\":5,\"order\":\"desc\",\"orderBy\":\"1\"}}],\"listeners\":{}}",
"description": "",
"version": 1,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"index\":\"appmetrics\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"*\"}},\"filter\":[]}"
}
}
}
}
Loading