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 Prometheus metric mappings #9948

Merged
merged 15 commits into from
Jan 25, 2019
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Metricbeat*

- Refactor Prometheus metric mappings {pull}9948[9948]
Copy link
Member

Choose a reason for hiding this comment

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

This also needs a note, that the stat metricset was removed.


*Packetbeat*

- Adjust Packetbeat `http` fields to ECS Beta 2 {pull}9645[9645]
Expand Down
54 changes: 7 additions & 47 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19275,66 +19275,26 @@ alias to: process.executable
[[exported-fields-prometheus]]
== Prometheus fields

Stats collected from Prometheus.
Stats scraped from a Prometheus endpoint.



[float]
== prometheus fields




[float]
== stats fields

Stats about the Prometheus server.



[float]
== notifications fields

Notification stats.



*`prometheus.stats.notifications.queue_length`*::
+
--
type: long

Current queue length.


--

*`prometheus.stats.notifications.dropped`*::
+
--
type: long

Number of dropped queue events.


--

*`prometheus.stats.processes.open_fds`*::
*`prometheus.labels.*`*::
+
--
type: long
type: object

Number of open file descriptors.
Prometheus metric labels


--

*`prometheus.stats.storage.chunks_to_persist`*::
*`prometheus.*`*::
+
--
type: long
type: object

Number of memory chunks that are not yet persisted to disk.
Prometheus metric - release: ga


--
Expand Down
23 changes: 4 additions & 19 deletions metricbeat/docs/modules/prometheus.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ This file is generated! See scripts/docs_collector.py
[[metricbeat-module-prometheus]]
== Prometheus module

This module periodically fetches metrics from
This module periodically scrapes metrics from
Copy link
Member

Choose a reason for hiding this comment

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

As you remove the stats metricset, we could already be here more specific that it scrapes metrics from prometheus exporters?

https://prometheus.io/docs/[Prometheus].

The default metricset is `collector`.


[float]
=== Example configuration
Expand All @@ -21,20 +19,11 @@ in <<configuration-metricbeat>>. Here is an example configuration:
----
metricbeat.modules:
- module: prometheus
metricsets: ["stats"]
enabled: true
period: 10s
hosts: ["localhost:9090"]
#metrics_path: /metrics
#namespace: example

- module: prometheus
metricsets: ["collector"]
enabled: true
period: 10s
hosts: ["localhost:9090"]
#metrics_path: /metrics
#namespace: example
metrics_path: /metrics
#username: "user"
#password: "secret"

# This can be used for service account based authorization:
# bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
Expand All @@ -52,9 +41,5 @@ The following metricsets are available:

* <<metricbeat-metricset-prometheus-collector,collector>>

* <<metricbeat-metricset-prometheus-stats,stats>>

include::prometheus/collector.asciidoc[]

include::prometheus/stats.asciidoc[]

23 changes: 0 additions & 23 deletions metricbeat/docs/modules/prometheus/stats.asciidoc

This file was deleted.

3 changes: 1 addition & 2 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ This file is generated! See scripts/docs_collector.py
|<<metricbeat-metricset-postgresql-database,database>>
|<<metricbeat-metricset-postgresql-statement,statement>>
|<<metricbeat-module-prometheus,Prometheus>> |image:./images/icon-no.png[No prebuilt dashboards] |
.2+| .2+| |<<metricbeat-metricset-prometheus-collector,collector>>
|<<metricbeat-metricset-prometheus-stats,stats>> beta[]
.1+| .1+| |<<metricbeat-metricset-prometheus-collector,collector>>
|<<metricbeat-module-rabbitmq,RabbitMQ>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.4+| .4+| |<<metricbeat-metricset-rabbitmq-connection,connection>>
|<<metricbeat-metricset-rabbitmq-exchange,exchange>>
Expand Down
1 change: 0 additions & 1 deletion metricbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -577,20 +577,11 @@ metricbeat.modules:

#----------------------------- Prometheus Module -----------------------------
- module: prometheus
metricsets: ["stats"]
enabled: true
period: 10s
hosts: ["localhost:9090"]
#metrics_path: /metrics
#namespace: example

- module: prometheus
metricsets: ["collector"]
enabled: true
period: 10s
hosts: ["localhost:9090"]
#metrics_path: /metrics
#namespace: example
metrics_path: /metrics
#username: "user"
#password: "secret"

# This can be used for service account based authorization:
# bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/prometheus/_meta/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM prom/prometheus:v1.5.1
FROM prom/prometheus:v2.6.0
HEALTHCHECK --interval=1s --retries=90 CMD nc -w 1 localhost 9090 </dev/null
EXPOSE 9090
20 changes: 0 additions & 20 deletions metricbeat/module/prometheus/_meta/config.reference.yml

This file was deleted.

3 changes: 0 additions & 3 deletions metricbeat/module/prometheus/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
- module: prometheus
#metricsets:
# - stats
period: 10s
hosts: ["localhost:9090"]
metrics_path: /metrics
#namespace: example
#username: "user"
#password: "secret"

Expand Down
4 changes: 1 addition & 3 deletions metricbeat/module/prometheus/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
This module periodically fetches metrics from
This module periodically scrapes metrics from
https://prometheus.io/docs/[Prometheus].

The default metricset is `collector`.
16 changes: 12 additions & 4 deletions metricbeat/module/prometheus/_meta/fields.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
- key: prometheus
title: "Prometheus"
description: >
Stats collected from Prometheus.
Stats scraped from a Prometheus endpoint.
short_config: false
release: ga
settings: ["ssl", "http"]
fields:
- name: prometheus
type: group
# Order is important here, labels will match first, the rest are double
Copy link
Member

Choose a reason for hiding this comment

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

What about placing labels in the base level to avoid possible issues with this? This is also the recommendation in ECS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to keep it like this for now, main reasons are:

  • It seems there is no way to do alias on labels.*
  • If other modules push labels there, it could lead to mapping issues if they are using dots

I want to make sure this module won't end on mapping issues and we can use these metrics reliably, not against this change once the problem is gone (for instance, if/when index per module is implemented).

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

LGTM, but I wonder some things (not blocking this PR)

It seems there is no way to do alias on labels.*

Why would we want to do it here?

If other modules push labels there, it could lead to mapping issues if they are using dots

I guess this is no different with any other module, maybe we shouldn't have a field for labels in ECS till we don't have a complete solution for these mapping issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this is no different with any other module, maybe we shouldn't have a field for labels in ECS till we don't have a complete solution for these mapping issues.

That could make sense, I still have some doubts on how ECS will play out in cases like this, I would prefer to play it safe on this module and learn from the process with others 😇

- name: prometheus.labels.*
type: object
object_type: keyword
description: >
fields:
Prometheus metric labels
- name: prometheus.*
type: object
object_type: double
Copy link
Member

Choose a reason for hiding this comment

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

👍

object_type_mapping_type: "*"
description: >
Prometheus metric
33 changes: 19 additions & 14 deletions metricbeat/module/prometheus/collector/_meta/data.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
{
"@timestamp": "2017-10-12T08:05:34.853Z",
"beat": {
"agent": {
"hostname": "host.example.com",
"name": "host.example.com"
},
"event": {
"dataset": "prometheus.collector",
"duration": 115000,
"module": "prometheus"
},
"metricset": {
"host": "prometheus:9090",
"module": "prometheus",
"name": "collector",
"namespace": "collector",
"rtt": 115
"name": "collector"
},
"prometheus": {
"collector": {
"label": {
"event": "add",
"role": "node"
},
"prometheus_sd_kubernetes_events_total": {
"value": 0
}
"http_request_duration_microseconds_count": 0,
Copy link
Member

Choose a reason for hiding this comment

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

An alternative here would have been prometheus.metrics.* to not conflict with labels. Will also allow us to add more metadata in the future.

"http_request_duration_microseconds_sum": 0,
"http_request_size_bytes_count": 0,
"http_request_size_bytes_sum": 0,
"http_response_size_bytes_count": 0,
"http_response_size_bytes_sum": 0,
"labels": {
"handler": "drop_series"
}
},
"service": {
"address": "172.29.0.2:9090",
"type": "prometheus"
Copy link
Member

Choose a reason for hiding this comment

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

This is an interesting one. We should probably make it configurable so the user can set service.type and service.name.

}
}
46 changes: 42 additions & 4 deletions metricbeat/module/prometheus/collector/_meta/docs.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
The Prometheus `collector` metricset fetches data from https://prometheus.io/docs/instrumenting/exporters/[prometheus exporters].
The Prometheus `collector` metricset scrapes data from https://prometheus.io/docs/instrumenting/exporters/[prometheus exporters].

All events with the same labels are grouped together as one event. The fields
exported by this metricset vary depending on the Prometheus exporter that you're
using.

[float]
=== Scraping from a Prometheus exporter

To scrape metrics from a Prometheus exporter, configure the `hosts` field to it. The path
to retrieve the metrics from (`/metrics` by default) can be configured with `metrics_path`.

[source,yaml]
-------------------------------------------------------------------------------------
- module: prometheus
period: 10s
hosts: ["localhost:9090"]
metrics_path: /metrics

#username: "user"
#password: "secret"

# This can be used for service account based authorization:
#bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
#ssl.certificate_authorities:
# - /var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt
-------------------------------------------------------------------------------------


[float]
=== Scraping all metrics from a Prometheus server

This module can scrape all metrics stored in a Prometheus server, by using the
https://prometheus.io/docs/prometheus/latest/federation/[federation API]. By pointing this
config to the Prometheus server:

[source,yaml]
-------------------------------------------------------------------------------------
metricbeat.modules:
- module: prometheus
Copy link
Member

Choose a reason for hiding this comment

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

This is kind of like a second "flawor" of the metricset. In the future we potentially could add a simple config federate.enabled: true which will set the correct settings directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it, it would be a nice addition, I agree it can be added later

period: 10s
hosts: ["localhost:9090"]
metrics_path: '/federate'
query:
'match[]': '{__name__!=""}'
-------------------------------------------------------------------------------------
Loading