Skip to content

Values from parent node #132

@fredr

Description

@fredr

With JSONPath it is not possible to reach a parent node afaict. Is there any other way to achieve the following with json_exporter?

Consider this json payload

[
  {
    "name": "parent-name",
    "children": [
      {
        "name": "child-1"
      },
      {
        "name": "child-2"
      }
    ]
  }
]

Let say we want to produce metrics like this:

some_metric_vector{name="child-1",parent="parent-name"} 1
some_metric_vector{name="child-2",parent="parent-name"} 1

With this configuration:

metrics:
- name: some_metric
  type: object
  path: '{[*]}'
  labels:
    parent: '{.name}'
    name: '{.children[*].name}'
  values:
    vector: 1

only one metric is produced

some_metric_vector{name="child-1 child-2",parent="parent-name"} 1

Changing the path to {[*].children[*]} I get a metric per child, but there is no way of reaching the parent name in the label selector.

Is there any other way to achieve this in json_exporter that I have overlooked? If not, would you be open to such a feature? Since JSONPath doesn't seem to support it, it would need some other solution, maybe having a configuration for parsing the json via go-templates as a step before the metrics path config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions