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

Refactor jolokia fields #14086

Closed
wants to merge 1 commit 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
14 changes: 10 additions & 4 deletions metricbeat/module/jolokia/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
release: ga
settings: ["ssl", "http"]
fields:
- name: jolokia
type: group
- name: jvm.jmx.metrics.string.*
type: object
object_type: keyword
description: >
jolokia contains metrics exposed via jolokia agent
fields:
JMX string metrics
- name: jvm.jmx.metrics.numeric.*
type: object
object_type: double
object_type_mapping_type: "*"
description: >
JMX numeric metrics
26 changes: 21 additions & 5 deletions metricbeat/module/jolokia/jmx/jmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package jmx

import (
"fmt"
"github.com/elastic/beats/metricbeat/helper"
"strings"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
Expand Down Expand Up @@ -96,18 +98,32 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {
// of an error set the Error field of mb.Event or simply call report.Error().
func (m *MetricSet) Fetch(reporter mb.ReporterV2) error {
var allEvents []common.MapStr
var fieldKey string

eventList := common.MapStr{}

allEvents, err := m.jolokia.Fetch(m)
if err != nil {
return err
}

// Set dynamic namespace.
for _, event := range allEvents {
reporter.Event(mb.Event{
MetricSetFields: event,
Namespace: m.Module().Name() + "." + m.namespace,
})
for key, val := range event.Flatten() {
detotKey := strings.Replace(key, ".", "_", -1)
switch v := val.(type) {
case float64:
fieldKey = fmt.Sprintf("jvm.jmx.metrics.numeric.%v", detotKey)
case string:
fieldKey = fmt.Sprintf("jvm.jmx.metrics.string.%v", detotKey)
default:
logp.Debug("jolokia", "JMX value should be doulbe or string and received %v", v)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to support all types Jolokia knows how to serialize, and we will have to check to what types they are converted when Unmarshalling. We will need a good set of test cases for this.
You can find the list of supported types here: https://jolokia.org/reference/html/protocol.html#serialization-response

Take also a look to the list operation, that allows to obtain information about the MBean attributes, including its type and description. Knowing the type we could do a proper handling without depending on how the value is converted to JSON and Unmarshalled. (With the description we could also provide some tool to autogenerate the documentation on light modules, but this is another story).

eventList.Put(fieldKey, val)
}
}

reporter.Event(mb.Event{
RootFields: eventList,
})
return nil
}