gnmic
gnmic copied to clipboard
Converting string to int
@karimra
Can you help with this question
Sample data
[{"name":"intf_admin_state","timestamp":1753640825630398022,"tags":{"interface_name":"Ethernet66","source":"txdr-iah13a-r304-lab-prod-roce-leaf-21","subscription-name":"intf_admin_state"},"values":{"admin-status":"1"}}]
[{"name":"intf_admin_state","timestamp":1753640825586605632,"tags":{"interface_name":"Management1","source":"txdr-iah13a-r304-lab-prod-roce-leaf-21","subscription-name":"intf_admin_state"},"values":{"admin-status":"1"}}]
For some reason I can trim the opencofig path , and apply this bounce map procesor , but it just won't convert the admin-status string to an int , when I write this to prom it not happy . Can you help me understand if the processor is correct ?
username: gnmic
password: *******
port: 6030
timeout: 10s
insecure: true
#encoding: json_ietf
debug: false
set-timestamp: true
targets:
node-a:
address: 1.1.1.1.1:6030
timeout: 10s
insecure: true
subscriptions:
bgp_neighbors:
paths:
- /network-instances/network-instance[name=default]/protocols/protocol[name=BGP]/bgp/neighbors
mode: stream
stream-mode: sample
sample-interval: 5s
cpu:
paths:
- components/component/cpu
mode: stream
stream-mode: sample
sample-interval: 5s
cpu_load_avg:
paths:
- eos_native:/Kernel/sysinfo
mode: stream
stream-mode: sample
sample-interval: 5s
dom:
paths:
- components/component/transceiver/physical-channels/channel/state/
mode: stream
stream-mode: sample
sample-interval: 5s
memory:
paths:
- components/component/state/memory/
- system/memory/kernel/state
- system/memory/state
mode: stream
stream-mode: sample
sample-interval: 5s
intf_ctrs:
paths:
- /interfaces/interface[name=*]/state/counters
mode: stream
stream-mode: on-change
intf_admin_state:
paths:
- /interfaces/interface[name=*]/state/admin-status
mode: stream
stream-mode: sample
sample-interval: 5s
intf_oper_state:
paths:
- /interfaces/interface[name=*]/state/oper-status
mode: stream
stream-mode: sample
sample-interval: 5s
intf_config:
paths:
- interfaces/interface/subinterfaces/subinterface/ipv4/addresses/address/config
mode: stream
stream-mode: sample
sample-interval: 5s
# show_ver:
# paths:
# - eos_native:/Eos/image
# mode: stream
# stream-mode: sample
# sample-interval: 60s
hardware:
paths:
- components/component/state
- eos_native:/Sysdb/hardware/entmib
mode: stream
stream-mode: sample
sample-interval: 60s
outputs:
nats-output:
type: nats
address: nats:4222
subject: gnmic
strings-as-labels: true
debug: true
path: /metrics
metric-prefix: gnmic
append-subscription-name: true
export-timestamps: true
event-processors:
- trim-prefixes
- bounce-map
#- set-timestamp-processor
vmetrics:
type: prometheus_write
listen: :9273
path: /metrics
url: http://victoriametrics:8428/api/v1/write
metric-prefix: eos
append-subscription-name: true
strings-as-labels: true
debug: true
event-processors:
- trim-prefixes
- bounce-map
processors:
eos-version:
event-strings:
value-names:
- ".*version$"
- ".*arch$"
transforms:
- replace:
apply-on: "value"
old: "EOS"
new: "eos"
trim-prefixes:
event-strings:
value-names:
- ".*"
transforms:
# strings function name
- path-base:
apply-on: "name"
bounce-map:
event-strings:
value-names:
- oper-status
- admin-status
transforms:
- replace:
apply-on: value
old: "UP"
new: "1"
- replace:
apply-on: value
old: "DOWN"
new: "0"
- replace:
apply-on: value
old: "NOT_PRESENT"
new: "-1"
- convert: # ✅ Correct conversion
apply-on: value
type: int
event-convert:
# list of regex to be matched with the values names
value-names:
- ".*status$"
# the desired value type, one of: int, uint, string, float, bool
type: int
set-timestamp-processor:
# processor type
event-override-ts:
# timestamp precision, s, ms, us, ns (default)
precision: ms
convert-int-processor:
# processor type
event-convert:
# list of regex to be matched with the values names
value-names:
- "admin-status"
# the desired value type, one of: int, uint, string, float, bool
type: int
This works in my environment
processors:
# processor name
convert-int-processor:
# processor type
event-convert:
# list of regex to be matched with the values names
value-names:
- ".*octets$"
- ".*oper-state$"
# the desired value type, one of: int, uint, string, float, bool
type: int
up-down-map:
event-strings:
value-names:
- oper-state
transforms:
- replace:
apply-on: "value"
old: "up"
new: "1"
- replace:
apply-on: "value"
old: "down"
new: "0"
@gavmckee80 the event-strings processor doesn't have a convert transform.
Prometheus output (both pull-based and remote write) should auto convert strings to float when possible. What kind of error do you see on Prom side ?