-
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
Extend logstash.node_stats metricset for logstash_stats stack monitoring data #11511
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fb8f914
WIP: Adding GetPipelinesStats function
ycombinator f028a93
WIP: initial code for x-pack path
ycombinator c7cbc84
Implementing a couple of TODOs
ycombinator 228db53
Reference issues in TODOs
ycombinator 7cd5e17
Getting logstash basic node info
ycombinator af4300e
Get basic node info from GET _node/stats call
ycombinator 4de94b6
Inlining single-use const
ycombinator 0f65bfd
Updating code per LS API changes
ycombinator d04e66e
Resolving remaining TODOs
ycombinator 72f78df
Fixing version serialization
ycombinator c3e405c
Fixing logstash double nesting
ycombinator 0977c1a
Removing TODOs as they have been implemented now
ycombinator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
// 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 node_stats | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/metricbeat/helper/elastic" | ||
"github.com/elastic/beats/metricbeat/mb" | ||
) | ||
|
||
type commonStats struct { | ||
Events map[string]interface{} `json:"events"` | ||
JVM map[string]interface{} `json:"jvm"` | ||
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. @felixbarny @axw Just found some more jvm metrics. I wonder if long term this also ties into our metrics discussion: elastic/ecs#474 |
||
Reloads map[string]interface{} `json:"reloads"` | ||
Queue struct { | ||
EventsCount int `json:"events_count"` | ||
} `json:"queue"` | ||
} | ||
|
||
type cpu struct { | ||
Percent int `json:"percent"` | ||
LoadAverage map[string]interface{} `json:"load_average"` | ||
NumCPUs int `json:"num_cpus"` | ||
} | ||
|
||
type process struct { | ||
OpenFileDescriptors int `json:"open_file_descriptors"` | ||
MaxFileDescriptors int `json:"max_file_descriptors"` | ||
CPU cpu `json:"cpu"` | ||
} | ||
|
||
type os struct { | ||
CPU cpu `json:"cpu"` | ||
} | ||
|
||
type nodeInfo struct { | ||
ID string `json:"id,omitempty"` | ||
UUID string `json:"uuid"` | ||
EphemeralID string `json:"ephemeral_id"` | ||
Name string `json:"name"` | ||
Host string `json:"host"` | ||
Version string `json:"version"` | ||
Snapshot bool `json:"snapshot"` | ||
Status string `json:"status"` | ||
HTTPAddress string `json:"http_address"` | ||
Pipeline map[string]interface{} `json:"pipeline"` | ||
} | ||
|
||
// NodeStats represents the stats of a Logstash node | ||
type NodeStats struct { | ||
nodeInfo | ||
commonStats | ||
Process process `json:"process"` | ||
Pipelines map[string]PipelineStats `json:"pipelines"` | ||
} | ||
|
||
// LogstashStats represents the logstash_stats sub-document indexed into .monitoring-logstash-* | ||
type LogstashStats struct { | ||
commonStats | ||
Process process `json:"process"` | ||
OS os `json:"os"` | ||
Pipelines []PipelineStats `json:"pipelines"` | ||
Logstash nodeInfo `json:"logstash"` | ||
Timestamp common.Time `json:"timestamp"` | ||
} | ||
|
||
// PipelineStats represents the stats of a Logstash pipeline | ||
type PipelineStats struct { | ||
ID string `json:"id"` | ||
Hash string `json:"hash"` | ||
EphemeralID string `json:"ephemeral_id"` | ||
Events map[string]interface{} `json:"events"` | ||
Reloads map[string]interface{} `json:"reloads"` | ||
Queue map[string]interface{} `json:"queue"` | ||
Vertices []map[string]interface{} `json:"vertices"` | ||
} | ||
|
||
func eventMappingXPack(r mb.ReporterV2, m *MetricSet, content []byte) error { | ||
var nodeStats NodeStats | ||
err := json.Unmarshal(content, &nodeStats) | ||
if err != nil { | ||
return errors.Wrap(err, "could not parse node stats response") | ||
} | ||
|
||
timestamp := common.Time(time.Now()) | ||
|
||
// Massage Logstash node basic info | ||
nodeStats.nodeInfo.UUID = nodeStats.nodeInfo.ID | ||
nodeStats.nodeInfo.ID = "" | ||
|
||
proc := process{ | ||
nodeStats.Process.OpenFileDescriptors, | ||
nodeStats.Process.MaxFileDescriptors, | ||
cpu{ | ||
Percent: nodeStats.Process.CPU.Percent, | ||
}, | ||
} | ||
|
||
o := os{ | ||
cpu{ | ||
LoadAverage: nodeStats.Process.CPU.LoadAverage, | ||
NumCPUs: nodeStats.Process.CPU.NumCPUs, | ||
}, | ||
} | ||
|
||
var pipelines []PipelineStats | ||
for pipelineID, pipeline := range nodeStats.Pipelines { | ||
pipeline.ID = pipelineID | ||
pipelines = append(pipelines, pipeline) | ||
} | ||
|
||
pipelines = getUserDefinedPipelines(pipelines) | ||
clusterToPipelinesMap := makeClusterToPipelinesMap(pipelines) | ||
|
||
for clusterUUID, clusterPipelines := range clusterToPipelinesMap { | ||
logstashStats := LogstashStats{ | ||
nodeStats.commonStats, | ||
proc, | ||
o, | ||
clusterPipelines, | ||
nodeStats.nodeInfo, | ||
timestamp, | ||
} | ||
|
||
event := mb.Event{} | ||
event.RootFields = common.MapStr{ | ||
"timestamp": timestamp, | ||
"interval_ms": m.Module().Config().Period / time.Millisecond, | ||
"type": "logstash_stats", | ||
"logstash_stats": logstashStats, | ||
} | ||
|
||
if clusterUUID != "" { | ||
event.RootFields["cluster_uuid"] = clusterUUID | ||
} | ||
|
||
event.Index = elastic.MakeXPackMonitoringIndexName(elastic.Logstash) | ||
r.Event(event) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func makeClusterToPipelinesMap(pipelines []PipelineStats) map[string][]PipelineStats { | ||
var clusterToPipelinesMap map[string][]PipelineStats | ||
clusterToPipelinesMap = make(map[string][]PipelineStats) | ||
|
||
for _, pipeline := range pipelines { | ||
var clusterUUIDs []string | ||
for _, vertex := range pipeline.Vertices { | ||
c, ok := vertex["cluster_uuid"] | ||
if !ok { | ||
continue | ||
} | ||
|
||
clusterUUID, ok := c.(string) | ||
if !ok { | ||
continue | ||
} | ||
|
||
clusterUUIDs = append(clusterUUIDs, clusterUUID) | ||
} | ||
|
||
for _, clusterUUID := range clusterUUIDs { | ||
clusterPipelines := clusterToPipelinesMap[clusterUUID] | ||
if clusterPipelines == nil { | ||
clusterToPipelinesMap[clusterUUID] = []PipelineStats{} | ||
} | ||
|
||
clusterToPipelinesMap[clusterUUID] = append(clusterPipelines, pipeline) | ||
} | ||
} | ||
|
||
return clusterToPipelinesMap | ||
} | ||
|
||
func getUserDefinedPipelines(pipelines []PipelineStats) []PipelineStats { | ||
userDefinedPipelines := []PipelineStats{} | ||
for _, pipeline := range pipelines { | ||
if pipeline.ID[0] != '.' { | ||
userDefinedPipelines = append(userDefinedPipelines, pipeline) | ||
} | ||
} | ||
return userDefinedPipelines | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
don't use an underscore in package name