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

Add optional namespace restriction to prometheus input plugin #5697

Merged
merged 2 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions plugins/inputs/prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ in Prometheus format.
## - prometheus.io/path: If the metrics path is not /metrics, define it with this annotation.
## - prometheus.io/port: If port is not 9102 use this annotation
# monitor_kubernetes_pods = true
## Only monitor one namespace
# monitor_kubernetes_pods_namespace = "test-namespace"
Benjamintf1 marked this conversation as resolved.
Show resolved Hide resolved

## Use bearer token for authorization. ('bearer_token' takes priority)
# bearer_token = "/path/to/bearer/token"
Expand Down Expand Up @@ -64,6 +66,8 @@ Currently the following annotation are supported:
* `prometheus.io/path` Override the path for the metrics endpoint on the service. (default '/metrics')
* `prometheus.io/port` Used to override the port. (default 9102)

Using the `monitor_kubernetes_pods_namespace` option allows you to limit which pods you are scraping.

#### Bearer Token

If set, the file specified by the `bearer_token` parameter will be read on
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/prometheus/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (p *Prometheus) start(ctx context.Context) error {
// directed to do so by K8s.
func (p *Prometheus) watch(ctx context.Context, client *k8s.Client) error {
pod := &corev1.Pod{}
watcher, err := client.Watch(ctx, "", &corev1.Pod{})
watcher, err := client.Watch(ctx, p.PodNamespace, &corev1.Pod{})
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion plugins/inputs/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ type Prometheus struct {
client *http.Client

// Should we scrape Kubernetes services for prometheus annotations
MonitorPods bool `toml:"monitor_kubernetes_pods"`
MonitorPods bool `toml:"monitor_kubernetes_pods"`
PodNamespace string `toml:"monitor_kubernetes_pods_namespace"`
lock sync.Mutex
kubernetesPods map[string]URLAndAddress
cancel context.CancelFunc
Expand All @@ -65,6 +66,8 @@ var sampleConfig = `
## - prometheus.io/path: If the metrics path is not /metrics, define it with this annotation.
## - prometheus.io/port: If port is not 9102 use this annotation
# monitor_kubernetes_pods = true
## Only monitor one namespace
# monitor_kubernetes_pods_namespace = "test-namespace"

## Use bearer token for authorization. ('bearer_token' takes priority)
# bearer_token = "/path/to/bearer/token"
Expand Down