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

Telegraf prometheus doesn't detect pods added and deleted #5281

Closed
simoelmou opened this issue Jan 13, 2019 · 3 comments
Closed

Telegraf prometheus doesn't detect pods added and deleted #5281

simoelmou opened this issue Jan 13, 2019 · 3 comments
Assignees
Labels
bug unexpected problem or unintended behavior
Milestone

Comments

@simoelmou
Copy link

Relevant telegraf.conf:

Input plugin: Prometheus
Output plugin : OpenTSDB

System info:

Telegraf version : 1.9.1
Platform: Openshift 3.7

Steps to reproduce:

  1. Generic configuration of Prometheus plugin and OpenTSDB plugin
  2. monitoring_pods is enabled in the Prometheus plugin

Expected behavior:

Metrics are retrieved successfully from all pods that contain Prometheus annotations, even if I added a pod or deleted a pod, telegraf picks up on that and start/stop retrieving metrics from the pod.

Actual behavior:

Metrics are retrieved successfully from all pods that are present the minute I deploy telegraf, but if I add a pod then telegraf doesn't detect it and if I delete a pod then telegraf starts showing errors because the pod's IP is not present anymore so it can't connect to it.

@simoelmou
Copy link
Author

simoelmou commented Jan 14, 2019

I saw that it was a problem of openshift roles so I created a service account with watch verb and it detects deletion and also the creation of pods but it doesn't scrape the added pods and when I saw the plugin it seems as if it tries to get the pod's IP but it finds the string is empty so it can't scrape metrics.

@danielnelson danielnelson added this to the 1.9.3 milestone Jan 14, 2019
@danielnelson danielnelson added the bug unexpected problem or unintended behavior label Jan 14, 2019
@glinton glinton self-assigned this Jan 14, 2019
@simoelmou
Copy link
Author

I modified the Prometheus plugin by taking into account the k8s.EventModified where now I register the pod again after modification event so that this way it handles the case where the IP assignment is too late. I do suggest you that you do not leave the case k8s.EventModified empty and register again the pod if there were any big changes ( like IP :) )

@simoelmou
Copy link
Author

func updatePod(pod *corev1.Pod, p *Prometheus) {
	targetURL := getScrapeURL(pod)
	if targetURL == nil {
		return
	}
	var registered bool = false
	for _, v := range p.kubernetesPods {
		if v.URL.String() == *targetURL {
			registered = true;
		}
	}
	if registered == false {
		log.Printf("D! [inputs.prometheus] Register an updated pod : %s", *targetURL)
		registerPod(pod, p)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants