Add optional namespace restriction to prometheus input plugin (#5697)
This commit is contained in:
parent
90593a07b8
commit
b2baa2fdd5
|
@ -24,6 +24,9 @@ in Prometheus format.
|
||||||
## - prometheus.io/path: If the metrics path is not /metrics, define it with this annotation.
|
## - 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
|
## - prometheus.io/port: If port is not 9102 use this annotation
|
||||||
# monitor_kubernetes_pods = true
|
# monitor_kubernetes_pods = true
|
||||||
|
## Restricts Kubernetes monitoring to a single namespace
|
||||||
|
## ex: monitor_kubernetes_pods_namespace = "default"
|
||||||
|
# monitor_kubernetes_pods_namespace = ""
|
||||||
|
|
||||||
## Use bearer token for authorization. ('bearer_token' takes priority)
|
## Use bearer token for authorization. ('bearer_token' takes priority)
|
||||||
# bearer_token = "/path/to/bearer/token"
|
# bearer_token = "/path/to/bearer/token"
|
||||||
|
@ -64,6 +67,8 @@ Currently the following annotation are supported:
|
||||||
* `prometheus.io/path` Override the path for the metrics endpoint on the service. (default '/metrics')
|
* `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)
|
* `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
|
#### Bearer Token
|
||||||
|
|
||||||
If set, the file specified by the `bearer_token` parameter will be read on
|
If set, the file specified by the `bearer_token` parameter will be read on
|
||||||
|
|
|
@ -83,7 +83,7 @@ func (p *Prometheus) start(ctx context.Context) error {
|
||||||
// directed to do so by K8s.
|
// directed to do so by K8s.
|
||||||
func (p *Prometheus) watch(ctx context.Context, client *k8s.Client) error {
|
func (p *Prometheus) watch(ctx context.Context, client *k8s.Client) error {
|
||||||
pod := &corev1.Pod{}
|
pod := &corev1.Pod{}
|
||||||
watcher, err := client.Watch(ctx, "", &corev1.Pod{})
|
watcher, err := client.Watch(ctx, p.PodNamespace, &corev1.Pod{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,8 @@ type Prometheus struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|
||||||
// Should we scrape Kubernetes services for prometheus annotations
|
// 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
|
lock sync.Mutex
|
||||||
kubernetesPods map[string]URLAndAddress
|
kubernetesPods map[string]URLAndAddress
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
|
@ -65,6 +66,9 @@ var sampleConfig = `
|
||||||
## - prometheus.io/path: If the metrics path is not /metrics, define it with this annotation.
|
## - 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
|
## - prometheus.io/port: If port is not 9102 use this annotation
|
||||||
# monitor_kubernetes_pods = true
|
# monitor_kubernetes_pods = true
|
||||||
|
## Restricts Kubernetes monitoring to a single namespace
|
||||||
|
## ex: monitor_kubernetes_pods_namespace = "default"
|
||||||
|
# monitor_kubernetes_pods_namespace = ""
|
||||||
|
|
||||||
## Use bearer token for authorization. ('bearer_token' takes priority)
|
## Use bearer token for authorization. ('bearer_token' takes priority)
|
||||||
# bearer_token = "/path/to/bearer/token"
|
# bearer_token = "/path/to/bearer/token"
|
||||||
|
|
Loading…
Reference in New Issue