karimra / gnmic

gNMIc is a gNMI CLI client and collector
https://gnmic.kmrd.dev
Apache License 2.0
217 stars 32 forks source link

path /lldp/... output on Prometheus different that the subscribe return. #375

Closed pmeffre closed 3 years ago

pmeffre commented 3 years ago

Hello, I have Juniper Infrastructure and I am experiences some problems that I do not understand. When I subscribe the path "/network-instances/network-instance/protocols/protocol/evpn/peer", all works fine and i get my result in Prometheus. When I subscribe the path "/lldp/interfaces/interface/neighbors/neighbor/state", the result in Prometheus is very partial: only few counters are available. (

gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_junos_re_payload_get_timestamp gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_junos_re_stream_creation_timestamp gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_timestamp gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_custom_tlvs_tlv_state_oui_subtype gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_custom_tlvs_tlv_state_type gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_custom_tlvs_tlv_state_value gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_state_age gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_state_last_update gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_state_port_id gnmic_lldp_nei_lldp_interfaces_interface_neighbors_neighbor_state_ttl

)

But When I request direct GNMIc with docker exec -ti dd16 /app/gnmic --address 10.9.5.104 --port 50051 --username xxx --password xxxxx --insecure --encoding proto subscribe --mode once --path "/lldp/interfaces/interface/neighbors/neighbor/state", I got all leafs and values (conform to lldp yang model):

{ "source": "10.9.5.104:50051", "subscription-name": "default-1618822725", "timestamp": 1618822729406749085, "time": "2021-04-19T08:58:49.406749085Z", "prefix": "lldp/interfaces/interface[name=em0]/neighbors/neighbor[id=2c:73:a0:65:e7:80-Gi1/0/2]", "updates": [ { "Path": "state/system-name", "values": { "state/system-name": "SW2960X-OOB-B16CPU-POD2-S10.oob.aca.fr" } }, { "Path": "state/system-description", "values": { "state/system-description": "Cisco IOS Software, C2960X Software (C2960X-UNIVERSALK9-M), Version 15.2(2)E7, RELEASE SOFTWARE (fc3)\nTechnical Support: http://www.cisco.com/techsupport\nCopyright (c) 1986-2017 by Cisco Systems, Inc.\nCompiled Wed 12-Jul-17 13:06 by prod_rel_team" } }, { "Path": "state/chassis-id", "values": { "state/chassis-id": "2c:73:a0:65:e7:80" } }, { "Path": "state/chassis-id-type", "values": { "state/chassis-id-type": "MAC_ADDRESS" } }, { "Path": "state/id", "values": { "state/id": "2c:73:a0:65:e7:80-Gi1/0/2" } }, { "Path": "state/age", "values": { "state/age": 3537744 } }, { "Path": "state/last-update", "values": { "state/last-update": 28 } }, { "Path": "state/ttl", "values": { "state/ttl": 120 } }, { "Path": "state/port-id", "values": { "state/port-id": "Gi1/0/2" } }, { "Path": "state/port-id-type", "values": { "state/port-id-type": "INTERFACE_NAME" } }, { "Path": "state/port-description", "values": { "state/port-description": "Port Vlan OOB_ILO" } }, [...]

Find next my gnmic.yml file :

# gNMI target address; CLI flag --port
port: 50051
# gNMI target user name; CLI flag --username
username: root
# gNMI target user password; CLI flag --password
password: 11-05-rticciloic! 
# gNMI target user password; CLI flag --timeout
timeout: 5s
# Connection mode; CLI flag --insecure
insecure: true
# Targets
targets:
  10.9.5.11: { subscriptions: [ lldp_nei, evpn_peers ], outputs: [ prom ] }
  10.9.5.12: { subscriptions: [ lldp_nei, evpn_peers ], outputs: [ prom ] }
  10.9.5.13: { subscriptions: [ lldp_nei, evpn_peers   ], outputs: [ prom ] }
  10.9.5.104: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.105: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.110: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.111: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.112: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.113: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.116: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
  10.9.5.117: { subscriptions: [ lldp_nei ], outputs: [ prom ] }
# Subscriptions
subscriptions:
  # Count locally learned mac addresses for a switch
  evpn_peers:
  # Counters for evpn peers  -- Apply only on spine --
    paths:
      - "/network-instances/network-instance/protocols/protocol/evpn/peer"
    stream-mode: sample
    sample-interval: 60s
    encoding: proto
  lldp_nei:
  # Collect the lldp neighbors only on change
    paths:
      - "/lldp/interfaces/interface/neighbors/neighbor/state"
    stream-mode: on-change
    encoding: proto
outputs:
  prom:
      type: prometheus
      # Port to listen on for incoming scape requests
      listen: :9117
      # Path to query to get the metrics
      path: /metrics
      # Maximum lifetime of metrics in the local cache
      expiration: 60s
      # Enable debug for prometheus output
      debug: false
      # a string to be used as the metric namespace
      metric-prefix: "gnmic"
      # a boolean, if true the subscription name will be appended to the metric name after the prefix
      append-subscription-name: true
      # a boolean, enables exporting timestamps received from the gNMI target as part of the metrics
      export-timestamps: false 

I do not know what is wrong in my config, and why I could not see all values returned in Prometheus ?

karimra commented 3 years ago

Hi,

Prometheus supports numerical values only ( converted to floats ), all other values are dropped.

If you want the string values (like state/port-id) to show up as labels of your prometheus metric, you have to set strings-as-labels to true under your prom output:

outputs:
  prom
    #...
    # other settings
    #...
    # a boolean, enables setting string type values as prometheus metric labels.
    strings-as-labels: true 

ref: https://gnmic.kmrd.dev/user_guide/outputs/prometheus_output/

pmeffre commented 3 years ago

Thanks a lot

It works like a charm ....

Pierre