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

How to use optional HTTP URL parameters. #1417

Closed
andriisoldatenko opened this Issue Feb 22, 2016 · 10 comments

Comments

Projects
None yet
5 participants
@andriisoldatenko
Copy link

andriisoldatenko commented Feb 22, 2016

I try to use different versions of using this params in prometheus.yml and it is not working for me :(
My prometheus.yml looks like:

global:
  scrape_interval:     1s # By default, scrape targets every 15 seconds.
  evaluation_interval: 1s # By default, scrape targets every 15 seconds.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'example-random'
    metrics_path: /api/metrics
    params:
      format: 'prometheus'
    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 1s
    scrape_timeout: 1s

    target_groups:
      - targets: ['localhost:3000']
        labels:
          group: 'production'

Also I can't find any tests.

# Optional HTTP URL parameters.
params:
  [ <string>: [<string>, ...] ]

I see only this error:

➜  prometheus-0.17.0rc2.darwin-amd64  ./prometheus -config.file=/Users/andrii/workspace/demon/prometheus/prometheus.yml -log.level "error"
prometheus, version 0.17.0rc2 (branch: release-0.17, revision: 667c221)
  build user:       fabianreinartz@macpro
  build date:       20160205-13:34:21
  go version:       1.5.3
ERRO[0000] Couldn't load configuration (-config.file=/Users/andrii/workspace/demon/prometheus/prometheus.yml): yaml: unmarshal errors:
  line 18: cannot unmarshal !!str `prometheus` into []string  source=main.go:213

Do you have ideas how to fix it?

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Feb 22, 2016

Params is a list, so do:

 params:
      format: ['prometheus']
@andriisoldatenko

This comment has been minimized.

Copy link
Author

andriisoldatenko commented Feb 22, 2016

Thanks!

@andriisoldatenko

This comment has been minimized.

Copy link
Author

andriisoldatenko commented Feb 22, 2016

@brian-brazil Does it equivalent to http://localhost:3000/api/metrics?format=prometheus?

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Feb 22, 2016

Yes, that's what it does,

@brian-brazil

This comment has been minimized.

Copy link
Member

brian-brazil commented Feb 22, 2016

Also prometheus does Content-Type negotiation, so you may want to consider using that.

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Feb 22, 2016

Yep, Prometheus currently sends this Accept header to any target it scrapes:

Accept: application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily;encoding=delimited;q=0.7,text/plain;version=0.0.4;q=0.3,application/json;schema="prometheus/telemetry";version=0.0.2;q=0.2,*/*;q=0.1

That's maybe a better way of determining the format to serve.

@paixaop

This comment has been minimized.

Copy link

paixaop commented Feb 22, 2018

Brian

Is it possible to have different params or metric_path per host?

file_sd_configs:
  - files:
    - prom/*.json

Then have the following JSON file

[
  {
    "targets": [ "localhost:3333" ],
    "metrics_path":"/metrics/a3-1",
    "labels": {
      "customer": "Customer 1",
      "location": "Container 1",
      "job": "Antminers"
    },
    "basic_auth": {
      "username": "user",
      "password": "pass"
    },
    "params": {
      "format": ["test"]
    }
  }
]

The devices I need to monitor cannot have a /metrics installed, so I wrote a "proxy" web service that would need the host name as a param. What can I do to support this use case if params don't work this way?

@juliusv

This comment has been minimized.

Copy link
Member

juliusv commented Feb 23, 2018

@paixaop You can set the metrics path and HTTP params via the __metrics_path__ and __params_<paramname>__ meta labels, but setting authentication details per target in this way is not supported (one reason being that it could be dangerous for auth data to be part of SD).

@alvaroaleman

This comment has been minimized.

Copy link

alvaroaleman commented Mar 9, 2018

Quick correction on that one for other folks that may find this via Google:

The meta label for params is __param_<paramname>

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.