Aggregating two metrics to one metric based on common tag values

Hello,
We are trying to monitor all the subscribers data from the BNG(Broadband Network Gateway) devices using gRPC telemetry. BNG device we are using is Juniper router. Telegraf is being used as collector. We are getting the expected data from the sensor in the router but the issue we are finding is that we’re not able to get the specific metrics which can be used to monitor the users data.

One metric gives us “user_name” of the users whereas other gives subscriber statistics like “ip_in_bytes”. Both metric have common tag session id as “SID” . We can query subscriber statistics using “SID” but its not persistent compared to “user_name”. We need to have one common metric which contains field “ip_in_bytes” and tag “user_name” and “SID”. Metrics we are using are:

  1. ifsubscription_subscriber_statistics/interface/ip_in_bytes{db=“telemetrydb-subscriber”,host=“telemetry-dev”,path=“/junos/system/subscriber-management/dynamic-interfaces/interfaces/subscriber-statistics/interface”,sid=“10070382”,source=“bras-snpl-01”} → 1005354

  2. ifsubscription_meta_data/interface/user_name{db=“telemetrydb-subscriber”,host=“telemetry-dev”,path=path=“/junos/system/subscriber-management/dynamic-interfaces/interfaces/meta-data/interface”,sid=“10070382”,source=“bras-snpl-01”} → david001

Is it possible to append “user_name” as tag in 1st metric on the basis of “SID” like:
ifsubscription_subscriber_statistics/interface/ip_in_bytes{db=“telemetrydb-subscriber”,host=“telemetry-dev”,path=“/junos/system/subscriber-management/dynamic-interfaces/interfaces/subscriber-statistics/interface”,sid=“10070382”,source=“bras-snpl-01”,user_name=“david001”}

It would be grateful if anyone could lend some help.

Thanks in advance.

Hi,

Which input plugin are you using?

Can you show the metrics in line protocol format as well please, not prometheus style? To gather this, use the [[outputs.file]] output. It helps to see what the metrics look like internally to better provide you options to use.

Hello,
We are using gnmi subscription.Here is my input config:

[[inputs.gnmi.subscription]]
    name = "ifsubscription"
    path = "/junos/system/subscriber-management/dynamic-interfaces/interfaces"
    subscription_mode = "sample"
    sample_interval = "300s"

Protocol format for meta data is as below. I need to extract user_name=david001 from here on basis of given sid=50685261.

ifsubscription,host=telemetry-dev,path=/junos/system/subscriber-management/dynamic-interfaces/interfaces/meta-data/interface,sid=50685261,source=bras-snpl-01 meta_data/interface/interface_index=124663i,meta_data/interface/session_type="1",meta_data/interface/user_name="david001",meta_data/interface/interface_name="demux0.3221349959",meta_data/interface/interface_set_name="",meta_data/interface/underlying_interface_name="demux0.3221512153",meta_data/interface/cvlan_tag=11i,meta_data/interface/svlan_tag=6651i 1705455784267196988

And for subscriber statistics with same sid=50685261:

ifsubscription,host=telemetry-dev,path=/junos/system/subscriber-management/dynamic-interfaces/interfaces/subscriber-statistics/interface,sid=50685261,source=bras-snpl-01 subscriber_statistics/interface/ip_in_packets=2658971i,subscriber_statistics/interface/ip_out_packets=9657015i,subscriber_statistics/interface/ip_in_bytes=279771994i,subscriber_statistics/interface/ip_out_bytes=12937456023i,subscriber_statistics/interface/ipv6_in_packets=627201i,subscriber_statistics/interface/ipv6_out_packets=3426141i,subscriber_statistics/interface/ipv6_in_bytes=150981203i,subscriber_statistics/interface/ipv6_out_bytes=4143185163i 1705458935019505485

Two resources path used for this are:

  • /junos/system/subscriber-management/dynamicinterfaces/interfaces/meta-data/interface[sid=‘sid-value’]/
  • /junos/system/subscriber-management/dynamicinterfaces/interfaces/subscriber-statistics/
    interface[sid=‘sid-value’]/

Hi,

Effectively it sounds like you want to match a user name with a sid on all other metrics?

Grabbing values from another metric is not particularly easy as you cannot count on the order of metrics. We do have processors, like starlark, that can do arbitrary logic like this, but again you may run into ordering issues, when you have to first find the username and then update all the other metrics.

If you know the uid and usernames in advanced you could use the lookup processor.

I am also trying with starlark but not able to make it work logically. Could you please help how we can work to get required result. Anything about it will be helpful.

I was able to solve this using [[processor.execd]] plugin. Its working as out requirements.