-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add connection metricset of nats module #10095
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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[] | ||
---- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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" |
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" |
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you expect more info about the server then just the id? If yes, perhaps we should make this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had similar thoughts about merging
How about introducing this too in follow up PRs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea. Is it reporting_time or is this actually the time of the server? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically, it's the same thing. So let's keep it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChrsMark Can you follow up on this and also do the change for the changelog? |
||
"now": "2018-12-28T12:33:53.026865597Z", | ||
"connections":{ | ||
"total": 10 | ||
} | ||
}, | ||
"type":"metricsets" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is the connections metricset of the module nats. |
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 |
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 | ||
} |
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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice find :-) Could you perhaps move both of these lines to
CHANGELOG.next.asciidoc
. We recently introduced this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! I'm in for addressing this in follow up PRs, in order to have it merged and add new metricsets on top of schema changes introduced here.
cc: @skatsaounis, @MichaelKatsoulis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi both @ruflin, @ChrsMark. I will apply this change to the second commit I am preparing for the new pr regarding routes metricset #10149
cc: @MichaelKatsoulis