Skip to content

Commit

Permalink
Make name field hierarchy configurable (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
boernd authored Sep 29, 2018
1 parent 69dc291 commit ced4038
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions _meta/beat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
############################# Prometheusbeat ######################################

prometheusbeat:
# Listen port of the server. Defaults to :8080
listen: ":8080"
# Context path. Defaults to /prometheus
context: "/prometheus"

# If this setting is set to true the metric name field is stored as a top-level field. Defaults to false
# name_under_root: false
3 changes: 0 additions & 3 deletions fields.yml → _meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
title: prometheusbeat
description:
fields:
- name: name
type: keyword
required: false
- name: value
type: double
required: false
Expand Down
10 changes: 6 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
package config

type Config struct {
Listen string `config:"listen"`
Context string `config:"context"`
Listen string `config:"listen"`
Context string `config:"context"`
NameUnderRoot bool `config:"name_under_root"`
}

var DefaultConfig = Config{
Listen: ":8080",
Context: "/prometheus",
Listen: ":8080",
Context: "/prometheus",
NameUnderRoot: false,
}
8 changes: 6 additions & 2 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ func (promSrv *PrometheusServer) handlePrometheus(w http.ResponseWriter, r *http
event := map[string]interface{}{}
labels := map[string]interface{}{}
for _, l := range ts.Labels {
fieldName := strings.Replace(l.Name, "_", "", -1)
labels[fieldName] = l.Value
fieldName := strings.Trim(l.Name, "_")
if fieldName == "name" && promSrv.config.NameUnderRoot {
event[fieldName] = l.Value
} else {
labels[fieldName] = l.Value
}
}
event["labels"] = labels

Expand Down
5 changes: 5 additions & 0 deletions prometheusbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
############################# Prometheusbeat ######################################

prometheusbeat:
# Listen port of the server. Defaults to :8080
listen: ":8080"
# Context path. Defaults to /prometheus
context: "/prometheus"

# If this setting is set to true the metric name field is stored as a top-level field. Defaults to false
name_under_root: true

#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
Expand Down

0 comments on commit ced4038

Please sign in to comment.