実現したいこと
prometheusでjsonを返すエンドポイントを指定し、そのメトリクスを収集したいです。
その為に「json-exporter」を利用しようと考えてます。
環境はclusterにkubernetes podをデプロイして構築してます。
発生している問題・分からないこと
設定は上手くいってそうでなのに、メトリクスが表示(取得)できていない。
prometheusとjson-exporterどちらのpodも問題なくデプロイされてますし
targetのstatus upで問題ないことも確認が出来ております。
気になる点としてはjson-exporterのログにエラーメッセージが出ています。
エラーメッセージ
error
1info msg="Loaded config file" config="{\"Modules\":null}"
該当のソースコード
json
1apiVersion: apps/v1 2kind: Deployment 3metadata: 4 name: json-exporter 5 namespace: prometheus 6spec: 7 replicas: 1 8 selector: 9 matchLabels: 10 app: json-exporter 11 template: 12 metadata: 13 labels: 14 app: json-exporter 15 spec: 16 serviceAccountName: coordinator 17 containers: 18 - name: json-exporter 19 image: prometheuscommunity/json-exporter:latest 20 ports: 21 - containerPort: 7979 22 args: 23 - --config.file=/etc/json-exporter/config.yml 24 volumeMounts: 25 - name: config 26 mountPath: /etc/json-exporter 27 volumes: 28 - name: config 29 configMap: 30 name: json-exporter-config
json
1apiVersion: v1 2kind: Service 3metadata: 4 name: json-exporter 5 namespace: prometheus 6spec: 7 selector: 8 app: json-exporter 9 ports: 10 - protocol: TCP 11 port: 7979 12 targetPort: 7979
json
1apiVersion: v1 2kind: ConfigMap 3metadata: 4 name: json-exporter-config 5 namespace: prometheus 6data: 7 config.yml: | 8 { 9 "targets": [ 10 "https://jsonplaceholder.typicode.com/users" 11 ], 12 "metrics": [ 13 { 14 "name": "all_json_metrics", 15 "path": "$.values[*].count", 16 "type": "gauge" 17 } 18 ] 19 }
prometheus
1apiVersion: v1 2kind: ConfigMap 3metadata: 4 name: prometheus-rules 5 labels: 6 name: prometheus-rules 7 namespace: prometheus 8data: 9 alert-rules.yaml: |- 10 groups: 11 - name: Deployment 12 rules: 13 - alert: Deployment at 0 Replicas 14 annotations: 15 summary: Deployment {{$labels.deployment}} in {{$labels.namespace}} is currently having no pods running 16 expr: | 17 sum(kube_deployment_status_replicas{pod_template_hash=""}) by (deployment,namespace) < 1 18 for: 1m 19 labels: 20 team: devops 21--- 22apiVersion: v1 23kind: ConfigMap 24metadata: 25 name: prometheus-config 26 labels: 27 name: prometheus-config 28 namespace: prometheus 29data: 30 web.yml: |- 31 prometheus.yaml: |- 32 global: 33 scrape_interval: 15s 34 evaluation_interval: 15s 35 scrape_timeout: 15s 36 scrape_configs: 37 - job_name: 'json_exporter_targets' 38 scrape_interval: 50s 39 static_configs: 40 - targets: 41 - https://jsonplaceholder.typicode.com/users 42 metrics_path: /metrics 43 relabel_configs: 44 - source_labels: [__address__] 45 target_label: __param_target 46 - source_labels: [__param_target] 47 target_label: instance 48 - target_label: __address__ 49 replacement: json-exporter:7979 50 - job_name: 'json_exporter' 51 scrape_interval: 50s 52 static_configs: 53 - targets: 54 - json-exporter:7979 55 - job_name: prometheus 56 static_configs: 57 - targets: 58 - localhost:9090
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
公式サイトhttps://github.com/prometheus-community/json_exporterは全て読み込みました。
issueにも同様の事例は載っていませんでした。
またslackのprometheusチャンネルにも同様の事例はありませんでした。
コメントもしましたが、そもそもjson-exporterを利用しているユーザーが少ないので何もリアクションがありませんでした。
公式が検証用として置いているjsonファイルを対象にmodules.yamlを追加してみたりもしましたが
変わりませんでした。
apiVersion: v1 kind: ConfigMap metadata: name: json-exporter-config namespace: prometheus data: config.yml: | { "targets": [ "https://raw.githubusercontent.com/prometheus-community/json_exporter/master/examples/data.json" ], "metrics": [ { "name": "all_json_metrics", "path": "{[*]}", "type": "gauge" } ] } modules.yaml: | default: headers: X-Dummy: my-test-header metrics: - name: example_global_value path: '{ .counter }' help: Example of a top-level global value scrape in the json labels: environment: beta # static label location: 'planet-{.location}' # dynamic label - name: example_timestamped_value type: object path: '{ .values[?(@.state == "INACTIVE")] }' epochTimestamp: '{ .timestamp }' help: Example of a timestamped value scrape in the json labels: environment: beta # static label values: count: '{.count}' # dynamic value - name: example_value type: object help: Example of sub-level value scrapes from a json path: '{.values[?(@.state == "ACTIVE")]}' labels: environment: beta # static label id: '{.id}' # dynamic label values: active: 1 # static value count: '{.count}' # dynamic value boolean: '{.some_boolean}' animals: metrics: - name: animal type: object help: Example of top-level lists in a separate module path: '{ [*] }' labels: name: '{ .noun }' predator: '{ .predator }' values: population: '{ .population }'
少しでも何か解決に繋がるご助言いただけると幸いです。
よろしくお願いいたします。
補足
特になし
あなたの回答
tips
プレビュー