Skip to content

Instantly share code, notes, and snippets.

@franktate
Last active April 18, 2023 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franktate/a13a0b66568ac1fbc690e55cef5131d7 to your computer and use it in GitHub Desktop.
Save franktate/a13a0b66568ac1fbc690e55cef5131d7 to your computer and use it in GitHub Desktop.
Prometheus JSON Exporter example

config.yml, prometheus.yml and reddit.json should be in /tmp/json_exporter/examples docker-compose.yml should be in /tmp/json_exporter.

Edit the IP address as needed in the files. My host is 172.16.30.194. You may be able to use "localhost" instead, but that didn't work for me.

After editing the IP address, run the following commands:

cd /tmp/json_exporter
python3 -m http.server 8000 &
docker-compose up -d

This will create two containers:

json_exporter, listening on port 7979
prometheus, listening on port 9090

Point your browser to http://localhost:9090/targets and you should see your target named "json" along with two other targets - one for the json_exporter container metrics, and one for metrics from the prometheus container.

If you click on the "json" target, you should see the same value in the above results.prometheus file.

---
modules:
default:
headers:
MyHeader: MyHeaderValue
metrics:
- name: json_testfile1
type: object
help: help...
path: '{[*]}'
labels:
time_start: '{.time_start}'
time_end: '{.time_end}'
values:
SEK_per_kWh: '{.SEK_per_kWh}'
EUR_per_kWh: '{.EUR_per_kWh}'
version: "3.8"
services:
json_exporter:
image: quay.io/prometheuscommunity/json-exporter:v0.5.0
volumes:
- $PWD/examples/config.yml:/config.yml:ro
ports:
- 7979:7979
prometheus:
image: quay.io/prometheus/prometheus
container_name: prometheus
volumes:
- $PWD/examples/prometheus.yml:/etc/prometheus/prometheus.yml:ro
ports:
- 9090:9090
scrape_configs:
## gather metrics of prometheus itself
- job_name: prometheus
static_configs:
- targets:
- localhost:9090 # equivalent to "localhost:9090"
## gather the metrics of json_exporter application itself
- job_name: json_exporter
static_configs:
- targets:
## Location of the json exporter's real <hostname>:<port>
- 172.16.30.194:7979 # equivalent to "localhost:7979"
## gather the metrics from third party json sources, via the json exporter
- job_name: json
metrics_path: /probe
params:
module: [default]
static_configs:
- targets:
- http://172.16.30.194:8000/examples/reddit.json
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
## Location of the json exporter's real <hostname>:<port>
replacement: 172.16.30.194:7979 # equivalent to "localhost:7979"
[{"SEK_per_kWh":0.82517,"EUR_per_kWh":0.07361,"EXR":11.210032,"time_start":"2023-03-08T00:00:00+01:00","time_end":"2023-03-08T01:00:00+01:00"},{"SEK_per_kWh":0.79602,"EUR_per_kWh":0.07101,"EXR":11.210032,"time_start":"2023-03-08T01:00:00+01:00","time_end":"2023-03-08T02:00:00+01:00"},{"SEK_per_kWh":0.78549,"EUR_per_kWh":0.07007,"EXR":11.210032,"time_start":"2023-03-08T02:00:00+01:00","time_end":"2023-03-08T03:00:00+01:00"},{"SEK_per_kWh":0.93402,"EUR_per_kWh":0.08332,"EXR":11.210032,"time_start":"2023-03-08T03:00:00+01:00","time_end":"2023-03-08T04:00:00+01:00"},{"SEK_per_kWh":1.20822,"EUR_per_kWh":0.10778,"EXR":11.210032,"time_start":"2023-03-08T04:00:00+01:00","time_end":"2023-03-08T05:00:00+01:00"},{"SEK_per_kWh":1.28433,"EUR_per_kWh":0.11457,"EXR":11.210032,"time_start":"2023-03-08T05:00:00+01:00","time_end":"2023-03-08T06:00:00+01:00"},{"SEK_per_kWh":1.53914,"EUR_per_kWh":0.1373,"EXR":11.210032,"time_start":"2023-03-08T06:00:00+01:00","time_end":"2023-03-08T07:00:00+01:00"},{"SEK_per_kWh":1.77713,"EUR_per_kWh":0.15853,"EXR":11.210032,"time_start":"2023-03-08T07:00:00+01:00","time_end":"2023-03-08T08:00:00+01:00"},{"SEK_per_kWh":1.94046,"EUR_per_kWh":0.1731,"EXR":11.210032,"time_start":"2023-03-08T08:00:00+01:00","time_end":"2023-03-08T09:00:00+01:00"},{"SEK_per_kWh":1.82724,"EUR_per_kWh":0.163,"EXR":11.210032,"time_start":"2023-03-08T09:00:00+01:00","time_end":"2023-03-08T10:00:00+01:00"},{"SEK_per_kWh":1.71502,"EUR_per_kWh":0.15299,"EXR":11.210032,"time_start":"2023-03-08T10:00:00+01:00","time_end":"2023-03-08T11:00:00+01:00"},{"SEK_per_kWh":1.61615,"EUR_per_kWh":0.14417,"EXR":11.210032,"time_start":"2023-03-08T11:00:00+01:00","time_end":"2023-03-08T12:00:00+01:00"},{"SEK_per_kWh":1.53768,"EUR_per_kWh":0.13717,"EXR":11.210032,"time_start":"2023-03-08T12:00:00+01:00","time_end":"2023-03-08T13:00:00+01:00"},{"SEK_per_kWh":1.51448,"EUR_per_kWh":0.1351,"EXR":11.210032,"time_start":"2023-03-08T13:00:00+01:00","time_end":"2023-03-08T14:00:00+01:00"},{"SEK_per_kWh":1.54048,"EUR_per_kWh":0.13742,"EXR":11.210032,"time_start":"2023-03-08T14:00:00+01:00","time_end":"2023-03-08T15:00:00+01:00"},{"SEK_per_kWh":1.58151,"EUR_per_kWh":0.14108,"EXR":11.210032,"time_start":"2023-03-08T15:00:00+01:00","time_end":"2023-03-08T16:00:00+01:00"},{"SEK_per_kWh":1.61951,"EUR_per_kWh":0.14447,"EXR":11.210032,"time_start":"2023-03-08T16:00:00+01:00","time_end":"2023-03-08T17:00:00+01:00"},{"SEK_per_kWh":1.71525,"EUR_per_kWh":0.15301,"EXR":11.210032,"time_start":"2023-03-08T17:00:00+01:00","time_end":"2023-03-08T18:00:00+01:00"},{"SEK_per_kWh":1.87084,"EUR_per_kWh":0.16689,"EXR":11.210032,"time_start":"2023-03-08T18:00:00+01:00","time_end":"2023-03-08T19:00:00+01:00"},{"SEK_per_kWh":1.90593,"EUR_per_kWh":0.17002,"EXR":11.210032,"time_start":"2023-03-08T19:00:00+01:00","time_end":"2023-03-08T20:00:00+01:00"},{"SEK_per_kWh":1.72377,"EUR_per_kWh":0.15377,"EXR":11.210032,"time_start":"2023-03-08T20:00:00+01:00","time_end":"2023-03-08T21:00:00+01:00"},{"SEK_per_kWh":1.50932,"EUR_per_kWh":0.13464,"EXR":11.210032,"time_start":"2023-03-08T21:00:00+01:00","time_end":"2023-03-08T22:00:00+01:00"},{"SEK_per_kWh":1.44408,"EUR_per_kWh":0.12882,"EXR":11.210032,"time_start":"2023-03-08T22:00:00+01:00","time_end":"2023-03-08T23:00:00+01:00"},{"SEK_per_kWh":1.33399,"EUR_per_kWh":0.119,"EXR":11.210032,"time_start":"2023-03-08T23:00:00+01:00","time_end":"2023-03-09T00:00:00+01:00"}]
# HELP json_testfile1_EUR_per_kWh help...
# TYPE json_testfile1_EUR_per_kWh untyped
json_testfile1_EUR_per_kWh{time_end="2023-03-08T01:00:00+01:00",time_start="2023-03-08T00:00:00+01:00"} 0.07361
json_testfile1_EUR_per_kWh{time_end="2023-03-08T02:00:00+01:00",time_start="2023-03-08T01:00:00+01:00"} 0.07101
json_testfile1_EUR_per_kWh{time_end="2023-03-08T03:00:00+01:00",time_start="2023-03-08T02:00:00+01:00"} 0.07007
json_testfile1_EUR_per_kWh{time_end="2023-03-08T04:00:00+01:00",time_start="2023-03-08T03:00:00+01:00"} 0.08332
json_testfile1_EUR_per_kWh{time_end="2023-03-08T05:00:00+01:00",time_start="2023-03-08T04:00:00+01:00"} 0.10778
json_testfile1_EUR_per_kWh{time_end="2023-03-08T06:00:00+01:00",time_start="2023-03-08T05:00:00+01:00"} 0.11457
json_testfile1_EUR_per_kWh{time_end="2023-03-08T07:00:00+01:00",time_start="2023-03-08T06:00:00+01:00"} 0.1373
json_testfile1_EUR_per_kWh{time_end="2023-03-08T08:00:00+01:00",time_start="2023-03-08T07:00:00+01:00"} 0.15853
json_testfile1_EUR_per_kWh{time_end="2023-03-08T09:00:00+01:00",time_start="2023-03-08T08:00:00+01:00"} 0.1731
json_testfile1_EUR_per_kWh{time_end="2023-03-08T10:00:00+01:00",time_start="2023-03-08T09:00:00+01:00"} 0.163
json_testfile1_EUR_per_kWh{time_end="2023-03-08T11:00:00+01:00",time_start="2023-03-08T10:00:00+01:00"} 0.15299
json_testfile1_EUR_per_kWh{time_end="2023-03-08T12:00:00+01:00",time_start="2023-03-08T11:00:00+01:00"} 0.14417
json_testfile1_EUR_per_kWh{time_end="2023-03-08T13:00:00+01:00",time_start="2023-03-08T12:00:00+01:00"} 0.13717
json_testfile1_EUR_per_kWh{time_end="2023-03-08T14:00:00+01:00",time_start="2023-03-08T13:00:00+01:00"} 0.1351
json_testfile1_EUR_per_kWh{time_end="2023-03-08T15:00:00+01:00",time_start="2023-03-08T14:00:00+01:00"} 0.13742
json_testfile1_EUR_per_kWh{time_end="2023-03-08T16:00:00+01:00",time_start="2023-03-08T15:00:00+01:00"} 0.14108
json_testfile1_EUR_per_kWh{time_end="2023-03-08T17:00:00+01:00",time_start="2023-03-08T16:00:00+01:00"} 0.14447
json_testfile1_EUR_per_kWh{time_end="2023-03-08T18:00:00+01:00",time_start="2023-03-08T17:00:00+01:00"} 0.15301
json_testfile1_EUR_per_kWh{time_end="2023-03-08T19:00:00+01:00",time_start="2023-03-08T18:00:00+01:00"} 0.16689
json_testfile1_EUR_per_kWh{time_end="2023-03-08T20:00:00+01:00",time_start="2023-03-08T19:00:00+01:00"} 0.17002
json_testfile1_EUR_per_kWh{time_end="2023-03-08T21:00:00+01:00",time_start="2023-03-08T20:00:00+01:00"} 0.15377
json_testfile1_EUR_per_kWh{time_end="2023-03-08T22:00:00+01:00",time_start="2023-03-08T21:00:00+01:00"} 0.13464
json_testfile1_EUR_per_kWh{time_end="2023-03-08T23:00:00+01:00",time_start="2023-03-08T22:00:00+01:00"} 0.12882
json_testfile1_EUR_per_kWh{time_end="2023-03-09T00:00:00+01:00",time_start="2023-03-08T23:00:00+01:00"} 0.119
# HELP json_testfile1_SEK_per_kWh help...
# TYPE json_testfile1_SEK_per_kWh untyped
json_testfile1_SEK_per_kWh{time_end="2023-03-08T01:00:00+01:00",time_start="2023-03-08T00:00:00+01:00"} 0.82517
json_testfile1_SEK_per_kWh{time_end="2023-03-08T02:00:00+01:00",time_start="2023-03-08T01:00:00+01:00"} 0.79602
json_testfile1_SEK_per_kWh{time_end="2023-03-08T03:00:00+01:00",time_start="2023-03-08T02:00:00+01:00"} 0.78549
json_testfile1_SEK_per_kWh{time_end="2023-03-08T04:00:00+01:00",time_start="2023-03-08T03:00:00+01:00"} 0.93402
json_testfile1_SEK_per_kWh{time_end="2023-03-08T05:00:00+01:00",time_start="2023-03-08T04:00:00+01:00"} 1.20822
json_testfile1_SEK_per_kWh{time_end="2023-03-08T06:00:00+01:00",time_start="2023-03-08T05:00:00+01:00"} 1.28433
json_testfile1_SEK_per_kWh{time_end="2023-03-08T07:00:00+01:00",time_start="2023-03-08T06:00:00+01:00"} 1.53914
json_testfile1_SEK_per_kWh{time_end="2023-03-08T08:00:00+01:00",time_start="2023-03-08T07:00:00+01:00"} 1.77713
json_testfile1_SEK_per_kWh{time_end="2023-03-08T09:00:00+01:00",time_start="2023-03-08T08:00:00+01:00"} 1.94046
json_testfile1_SEK_per_kWh{time_end="2023-03-08T10:00:00+01:00",time_start="2023-03-08T09:00:00+01:00"} 1.82724
json_testfile1_SEK_per_kWh{time_end="2023-03-08T11:00:00+01:00",time_start="2023-03-08T10:00:00+01:00"} 1.71502
json_testfile1_SEK_per_kWh{time_end="2023-03-08T12:00:00+01:00",time_start="2023-03-08T11:00:00+01:00"} 1.61615
json_testfile1_SEK_per_kWh{time_end="2023-03-08T13:00:00+01:00",time_start="2023-03-08T12:00:00+01:00"} 1.53768
json_testfile1_SEK_per_kWh{time_end="2023-03-08T14:00:00+01:00",time_start="2023-03-08T13:00:00+01:00"} 1.51448
json_testfile1_SEK_per_kWh{time_end="2023-03-08T15:00:00+01:00",time_start="2023-03-08T14:00:00+01:00"} 1.54048
json_testfile1_SEK_per_kWh{time_end="2023-03-08T16:00:00+01:00",time_start="2023-03-08T15:00:00+01:00"} 1.58151
json_testfile1_SEK_per_kWh{time_end="2023-03-08T17:00:00+01:00",time_start="2023-03-08T16:00:00+01:00"} 1.61951
json_testfile1_SEK_per_kWh{time_end="2023-03-08T18:00:00+01:00",time_start="2023-03-08T17:00:00+01:00"} 1.71525
json_testfile1_SEK_per_kWh{time_end="2023-03-08T19:00:00+01:00",time_start="2023-03-08T18:00:00+01:00"} 1.87084
json_testfile1_SEK_per_kWh{time_end="2023-03-08T20:00:00+01:00",time_start="2023-03-08T19:00:00+01:00"} 1.90593
json_testfile1_SEK_per_kWh{time_end="2023-03-08T21:00:00+01:00",time_start="2023-03-08T20:00:00+01:00"} 1.72377
json_testfile1_SEK_per_kWh{time_end="2023-03-08T22:00:00+01:00",time_start="2023-03-08T21:00:00+01:00"} 1.50932
json_testfile1_SEK_per_kWh{time_end="2023-03-08T23:00:00+01:00",time_start="2023-03-08T22:00:00+01:00"} 1.44408
json_testfile1_SEK_per_kWh{time_end="2023-03-09T00:00:00+01:00",time_start="2023-03-08T23:00:00+01:00"} 1.33399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment