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

in k8s prometheus receiver does not have the ability to only scrape the metrics of pods on its own node #27642

Closed
yutingcaicyt opened this issue Oct 12, 2023 · 7 comments
Labels
enhancement New feature or request question Further information is requested receiver/prometheus Prometheus receiver Stale

Comments

@yutingcaicyt
Copy link
Contributor

Component(s)

receiver/prometheus

Is your feature request related to a problem? Please describe.

The collector is deployed by deamonset in my project. I want to collect metrics of apps in each pod with the Prometheus receiver, but I found the receiver can't only scrape the metrics of pods on its own node. Is there any method to solve this problem?

Describe the solution you'd like

Prometheus receiver can scrape the metrics of pods on its own node.

Describe alternatives you've considered

No response

Additional context

No response

@yutingcaicyt yutingcaicyt added enhancement New feature or request needs triage New item requiring triage labels Oct 12, 2023
@github-actions github-actions bot added the receiver/prometheus Prometheus receiver label Oct 12, 2023
@github-actions
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@jinja2
Copy link
Contributor

jinja2 commented Oct 12, 2023

You can use the receivercreator with the k8s_observer for this. Refer to the prometheus receiver example here.

@dashpole
Copy link
Contributor

You can also use the field selector in the prometheus scrape config:

  scrape_configs:
    - job_name: kubernetes_pods
      kubernetes_sd_configs:
        - role: pod
          selectors:
            - role: pod
              field: spec.nodeName=$NODE_NAME

Then on your pod spec:

  env:
  - name: NODE_NAME
    valueFrom:
      fieldRef:
        fieldPath: spec.nodeName

@crobert-1 crobert-1 removed the needs triage New item requiring triage label Oct 12, 2023
@yutingcaicyt
Copy link
Contributor Author

But in my understanding, selectors.field does not recognize environment variables. Will this really work? @dashpole

@dashpole
Copy link
Contributor

The collector does env var substitution. So $NODE_NAME is passed to the prometheus receiver config as the value of the env var, not as the "$NODE_NAME" string. This works in the otel collector, but does not work in upstream prometheus server. I've used this quite extensively myself.

@crobert-1 crobert-1 added the question Further information is requested label Oct 13, 2023
Copy link
Contributor

This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping @open-telemetry/collector-contrib-triagers. If this issue is still relevant, please ping the code owners or leave a comment explaining why it is still relevant. Otherwise, please close it.

@github-actions github-actions bot added the Stale label Dec 13, 2023
@dashpole
Copy link
Contributor

working as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested receiver/prometheus Prometheus receiver Stale
Projects
None yet
Development

No branches or pull requests

4 participants