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

object loop #250

Open
yosefy opened this issue Aug 5, 2023 · 1 comment
Open

object loop #250

yosefy opened this issue Aug 5, 2023 · 1 comment

Comments

@yosefy
Copy link

yosefy commented Aug 5, 2023

hi we have this from nginx unit state

    "connections": {
        "accepted": 245214,
        "active": 0,
        "idle": 0,
        "closed": 245214
    },
    "requests": {
        "total": 245178
    },
    "applications": {
        "site2.com": {
            "processes": {
                "running": 1,
                "starting": 0,
                "idle": 1
            },
            "requests": {
                "active": 0
            }
        },
        "site1.com": {
            "processes": {
                    "running": 1,
                    "starting": 0,
                    "idle": 1
            },
            "requests": {
                "active": 0
            }
        }
    }
}```

so we need add metrics adding "application name" as label

@meorkamalmeorsulaiman
Copy link

meorkamalmeorsulaiman commented Nov 15, 2023

I came across similar situation:

---
modules:
  device_stats:
    metrics:
    - name: status
      help: Connected Switches
      type: object
      path: '{ @ }'
      labels:
        status: '{ .status }'
      values:
        return: 1

    - name: list_of_interfaces
      help: list interfaces
      type: object
      path: '{ @.if_stat.* }'
      labels:
        ifname: '{ .port_id }'
      values:
        return: 1

JSON:

{
   "status": "connected",
    "hostname": "X",
    "if_stat": {
        "em0.0": {
            "tx_pkts": 238084479,
            "rx_pkts": 187104366,
            "rx_bytes": 28492395648,
            "port_id": "em0",
            "up": true,
            "tx_bytes": 144260009035
        },
        "irb.80": {
            "tx_pkts": 133010,
            "vlan": 80,
            "rx_pkts": 41813989,
            "rx_bytes": 14102487191,
            "port_id": "irb",
            "up": true,
            "tx_bytes": 7384805
        }
    }
}

I tried to iterate the interface however received the errors:

19 error(s) occurred:
* collected metric "list_of_interfaces_return" { label:{name:"ifname" value:"irb"} untyped:{value:1}} was collected before with the same name and label values
* collected metric "list_of_interfaces_return" { label:{name:"ifname" value:"irb"} untyped:{value:1}} was collected before with the same name and label values
* <snipped>

Would it be possible or is there a way that if we can iterate the nested object so that the metric comes like below?

list_of_interfaces_return{ifname="em0"} 1
list_of_interfaces_return{ifname="irb.80"} 1

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

2 participants