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

confused by labels, names, values #343

Open
stefangweichinger opened this issue Nov 15, 2024 · 1 comment
Open

confused by labels, names, values #343

stefangweichinger opened this issue Nov 15, 2024 · 1 comment

Comments

@stefangweichinger
Copy link

Forgive me asking newbie questions maybe, I am new to this json handling thing and trying to learn things right.

I use json_exporter successfully for extracting values from various appliances at a customer already.

Right now I try to

 # cat inst.json 

{
  "INST_VALUES": {
    "LOCAL_TIME": "2024-07-25T16:51:01+01:00",
    "V_L1": {
      "value": 229.906,
      "unit": "V"
    },
    "V_L2": {
      "value": 231.950,
      "unit": "V"
    },
    "V_L3": {
      "value": 231.341,
      "unit": "V"
    },
    "V_L12": {
      "value": 398.990,
      "unit": "V"
    },
    "V_L23": {
      "value": 401.072,
      "unit": "V"
    },

[..]

At first I tried something like:

  siemens_pac_inst:
    headers:
      X-Dummy: my-siemenspac-header3
    metrics:
    - name: inst_values
      type: object
      path: '{ .INST_VALUES }'
      help: somehelp
      values:
        V_L1: '{.V_L1}'
        V_L2: '{.V_L2}'
        V_L3: '{.V_L3}'
        V_L12: '{.V_L12}'
        V_L23: '{.V_L23}'

[..]

but I assume it should be more like

    - name: inst_values
      type: object
      path: '{ .INST_VALUES.V_L1 }'
      help: somehelp
      values:
        V_L1: '{.value}'

I also assume there is an elegant way of iterating over all these values ... but I could need some example and help for doing so.

If possible: is there an explanation for when to use labels and names?
I have modules in place and get metrics but I think my naming might be sub-optimal ...

thanks in advance!

@stefangweichinger
Copy link
Author

I get good metrics with something like:

   - name: inst_values
      type: object
      path: '{ .INST_VALUES.V_L1 }'
      help: somehelp
      values:
        v_l1: '{.value}'
    - name: inst_values
      type: object
      path: '{ .INST_VALUES.V_L2 }'
      help: somehelp
      values:
        v_l2: '{.value}'
    - name: inst_values
      type: object
      path: '{ .INST_VALUES.V_L3 }'
      help: somehelp
      values:
        v_l3: '{.value}'
    - name: inst_values
      type: object
      path: '{ .INST_VALUES.P_L1 }'
      help: somehelp
      values:
        p_l1: '{.value}'
    - name: inst_values
      type: object
      path: '{ .INST_VALUES.P_L2 }'
      help: somehelp
      values:
        p_l2: '{.value}'

etc

Is there a shorter way to do that? thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant