json_exporter icon indicating copy to clipboard operation
json_exporter copied to clipboard

Can this read a local json file ?

Open KlavsKlavsen opened this issue 3 years ago • 6 comments

by f.ex. giving it a url like: file:///my/path/file.json ?

KlavsKlavsen avatar Dec 18 '20 09:12 KlavsKlavsen

This exporter works with the multi-target pattern. So it accepts arbitrary target locations via the URL params. It could be extremely dangerous to open that up to local files on the exporter's filesystems.

It might be safer if a flag were used to limit to only files in a specific path. For example.

./json_exporter --probe.file-path=/my/path

Then you could probe with http://json-exporter.example.com:7979/probe?target=file.json.

SuperQ avatar Dec 18 '20 11:12 SuperQ

Hi! Running 0.3.0 version, specified --probe.file-path=/tmp, and receive

json_exporter: error: unknown long flag '--probe.file-path', try --help

But in help there is no --probe flag:

/ $ json_exporter --help
usage: json_exporter [<flags>]

Flags:
  -h, --help                    Show context-sensitive help (also try --help-long and
                                --help-man).
      --config.file=config.yml  JSON exporter configuration file.
      --web.listen-address=":7979"  
                                The address to listen on for HTTP requests.
      --config.check            If true validate the config file and then exit.
      --web.config=""           [EXPERIMENTAL] Path to config yaml file that can enable TLS or
                                authentication.
      --log.level=info          Only log messages with the given severity or above. One of:
                                [debug, info, warn, error]
      --log.format=logfmt       Output format of log messages. One of: [logfmt, json]
      --version                 Show application version.

Also, tried to specify path in url, eg http://json-exporter.example.com:7979/probe?target=/tmp/my.json Got

Error response
Error code: 404
Message: File not found.
Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.

File /tmp/my.json exists and has valid json

So, how can I read json from file /tmp/my.json?

@rustycl0ck

krakazyabra avatar Mar 11 '21 16:03 krakazyabra

@rustycl0ck is it possible to read local file?

DAGorchakov avatar Jul 01 '21 14:07 DAGorchakov

@DAGorchakov , Reading from local file is a new feature request, it is not there right now.

rustycl0ck avatar Jul 05 '21 07:07 rustycl0ck

so by now should I configure the exporter to scrape local json data by modifying prometheus.yml (the prometheus configuration file)?

ss666 avatar Jul 05 '21 08:07 ss666

Simple suggestion to handle that use-case. take a simple webserver like python -m SimpleHTTPServer 9000 (or Gunicorn or nginx) and use localhost:9000/your.json as url for the exporter. For production use you should go the extra mile to harden & monitor the server. But actually works very well

msglueck avatar Jul 30 '23 21:07 msglueck