-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add connection metricset of nats module (#10095)
This PR adds `connections` metricset to `nats` module as part of #10071. `connections` metricset retrieves metrics from `connz` [monitoring](https://nats.io/documentation/tutorials/nats-monitoring/) URI of `nats`. _______________________________________________________________________________ Co-Authored-By: Stamatis Katsaounis <katsaouniss@gmail.com>, @skatsaounis Co-Authored-By: Michael Katsoulis <michaelkatsoulis88@gmail.com>, @MichaelKatsoulis
- Loading branch information
Showing
27 changed files
with
465 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-nats-connections]] | ||
=== Nats connections metricset | ||
|
||
experimental[] | ||
|
||
include::../../../module/nats/connections/_meta/docs.asciidoc[] | ||
|
||
|
||
==== Fields | ||
|
||
For a description of each field in the metricset, see the | ||
<<exported-fields-nats,exported fields>> section. | ||
|
||
Here is an example document generated by this metricset: | ||
|
||
[source,json] | ||
---- | ||
include::../../../module/nats/connections/_meta/data.json[] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
- module: nats | ||
metricsets: ["stats"] | ||
metricsets: ["connections", "stats"] | ||
period: 10s | ||
hosts: ["localhost:8222"] | ||
#stats.metrics_path: "/varz" | ||
#connections.metrics_path: "/connz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
- module: nats | ||
metricsets: ["stats"] | ||
metricsets: ["connections", "stats"] | ||
period: 10s | ||
hosts: ["localhost:8222"] | ||
stats.metrics_path: "/varz" | ||
#stats.metrics_path: "/varz" | ||
#connections.metrics_path: "/connz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"@timestamp":"2016-05-23T08:05:34.853Z", | ||
"beat":{ | ||
"hostname":"beathost", | ||
"name":"beathost" | ||
}, | ||
"metricset":{ | ||
"host":"localhost", | ||
"module":"nats", | ||
"name":"connections", | ||
"rtt":44269 | ||
}, | ||
"nats":{ | ||
"server_id": "bUAdpRFtMWddIBWw80Yd9D", | ||
"now": "2018-12-28T12:33:53.026865597Z", | ||
"connections":{ | ||
"total": 10 | ||
} | ||
}, | ||
"type":"metricsets" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is the connections metricset of the module nats. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- name: connections | ||
type: group | ||
description: > | ||
Contains nats connection related metrics | ||
fields: | ||
- name: total | ||
type: integer | ||
description: > | ||
The number of currently active clients |
5 changes: 5 additions & 0 deletions
5
metricbeat/module/nats/connections/_meta/test/connectionsmetrics.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"server_id": "bUAdpRFtMWddIBWw80Yd9D", | ||
"now": "2018-12-28T12:33:53.026865597Z", | ||
"total": 10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package connections | ||
|
||
import ( | ||
"github.com/elastic/beats/libbeat/common/cfgwarn" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/metricbeat/helper" | ||
"github.com/elastic/beats/metricbeat/helper/elastic" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
"github.com/elastic/beats/metricbeat/mb/parse" | ||
) | ||
|
||
const ( | ||
defaultScheme = "http" | ||
defaultPath = "/connz" | ||
) | ||
|
||
var ( | ||
hostParser = parse.URLHostParserBuilder{ | ||
DefaultScheme: defaultScheme, | ||
DefaultPath: defaultPath, | ||
PathConfigKey: "connections.metrics_path", | ||
}.Build() | ||
) | ||
|
||
// init registers the MetricSet with the central registry as soon as the program | ||
// starts. The New function will be called later to instantiate an instance of | ||
// the MetricSet for each host defined in the module's configuration. After the | ||
// MetricSet has been created then Fetch will begin to be called periodically. | ||
func init() { | ||
mb.Registry.MustAddMetricSet("nats", "connections", New, | ||
mb.WithHostParser(hostParser), | ||
mb.DefaultMetricSet(), | ||
) | ||
} | ||
|
||
// MetricSet holds any configuration or state information. It must implement | ||
// the mb.MetricSet interface. And this is best achieved by embedding | ||
// mb.BaseMetricSet because it implements all of the required mb.MetricSet | ||
// interface methods except for Fetch. | ||
type MetricSet struct { | ||
mb.BaseMetricSet | ||
http *helper.HTTP | ||
Log *logp.Logger | ||
} | ||
|
||
// New creates a new instance of the MetricSet. New is responsible for unpacking | ||
// any MetricSet specific configuration options if there are any. | ||
func New(base mb.BaseMetricSet) (mb.MetricSet, error) { | ||
cfgwarn.Experimental("The nats connections metricset is experimental.") | ||
|
||
config := struct{}{} | ||
if err := base.Module().UnpackConfig(&config); err != nil { | ||
return nil, err | ||
} | ||
|
||
http, err := helper.NewHTTP(base) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &MetricSet{ | ||
base, | ||
http, | ||
logp.NewLogger("nats"), | ||
}, nil | ||
} | ||
|
||
// Fetch methods implements the data gathering and data conversion to the right | ||
// format. It publishes the event which is then forwarded to the output. In case | ||
// of an error set the Error field of mb.Event or simply call report.Error(). | ||
func (m *MetricSet) Fetch(r mb.ReporterV2) { | ||
content, err := m.http.FetchContent() | ||
if err != nil { | ||
elastic.ReportAndLogError(err, r, m.Log) | ||
return | ||
} | ||
err = eventMapping(r, content) | ||
if err != nil { | ||
elastic.ReportAndLogError(err, r, m.Log) | ||
return | ||
} | ||
} |
Oops, something went wrong.