Skip to content

Commit

Permalink
Filter allocator and framework_offers in filterMetrics()
Browse files Browse the repository at this point in the history
  • Loading branch information
branden committed Aug 8, 2019
1 parent effb993 commit 8352b73
Show file tree
Hide file tree
Showing 2 changed files with 302 additions and 285 deletions.
53 changes: 24 additions & 29 deletions plugins/inputs/mesos/mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ func getMetrics(role Role, group string) []string {
"master/outstanding_offers",
}

// These groups are empty because filtering is done in gatherMainMetrics
// based on presence of "framework_offers"/"allocator" in MasterCols.
// These lines are included to prevent the "unknown" info log below.
// framework_offers and allocator metrics have unpredictable names, so they can't be listed here.
// These empty groups are included to prevent the "unknown metrics group" info log below.
// filterMetrics() filters these metrics by looking for names with the corresponding prefix.
m["framework_offers"] = []string{}
m["allocator"] = []string{}

Expand Down Expand Up @@ -505,9 +505,27 @@ func (m *Mesos) filterMetrics(role Role, metrics *map[string]interface{}) {
}

for _, k := range metricsDiff(role, selectedMetrics) {
for _, v := range getMetrics(role, k) {
if _, ok = (*metrics)[v]; ok {
delete((*metrics), v)
switch k {
// allocator and framework_offers metrics have unpredictable names, so we have to identify them by name prefix.
case "allocator":
for m, _ := range *metrics {
if strings.HasPrefix(m, "allocator/") {
delete((*metrics), m)
}
}
case "framework_offers":
for m, _ := range *metrics {
if strings.HasPrefix(m, "master/frameworks/") || strings.HasPrefix(m, "frameworks/") {
delete((*metrics), m)
}
}

// All other metrics have predictable names. We can use getMetrics() to retrieve them.
default:
for _, v := range getMetrics(role, k) {
if _, ok = (*metrics)[v]; ok {
delete((*metrics), v)
}
}
}
}
Expand Down Expand Up @@ -621,29 +639,6 @@ func (m *Mesos) gatherMainMetrics(u *url.URL, role Role, acc telegraf.Accumulato
}
}

var includeFrameworkOffers, includeAllocator bool
for _, col := range m.MasterCols {
if col == "framework_offers" {
includeFrameworkOffers = true
} else if col == "allocator" {
includeAllocator = true
}
}

for metricName := range jf.Fields {
if !strings.HasPrefix(metricName, "master/frameworks/") && !strings.HasPrefix(metricName, "frameworks/") && !strings.HasPrefix(metricName, "allocator/") {
continue
}

// filter out framework offers/allocator metrics if necessary
if !includeFrameworkOffers &&
(strings.HasPrefix(metricName, "master/frameworks/") || strings.HasPrefix(metricName, "frameworks/")) ||
(!includeAllocator && strings.HasPrefix(metricName, "allocator/")) {
delete(jf.Fields, metricName)
continue
}
}

acc.AddFields("mesos", jf.Fields, tags)

return nil
Expand Down
Loading

0 comments on commit 8352b73

Please sign in to comment.