Skip to content

gnmic monitoring H3C switch, returning JSON data but Prometheus metrics are abnormal #878

Description

@wm55555

I am using gnmic to subscribe to telemetry from an H3C switch. The subscription successfully returns JSON data (shown below), but when I scrape the Prometheus exporter endpoint, the metric only shows h3c_Ifmgr_Statistics_Interface{...} 1 instead of exposing the individual fields from the JSON response (like InPkts, InOctets, InRate, etc.).

Configuration (gnmic.yaml):

tingyu@630-10.16.254.114:~/gnmic$ cat gnmic.yaml
targets:
h3c_switch:
address: 10.88.43.21:50051
insecure: true
metadata:
token_id: "00000000116e17359db5141af3ed55c879c1"

subscriptions:
if_stats:
paths:
- "Ifmgr/Statistics/Interface[Name=GigabitEthernet1/0/48]"
mode: stream
stream-mode: sample
sample-interval: 3s
encoding: json_ietf

outputs:
console:
type: file
filename: /dev/stdout
format: event
my_prom_exporter:
type: prometheus
listen: ":9273"
path: "/metrics"
metric-prefix: "h3c"
strings-as-labels: true

Command output

tingyu@630-10.16.254.114:~/gnmic$ gnmic --config gnmic.yaml subscribe --log
time=2026-06-12T11:25:56.707+08:00 level=INFO msg="gnmic version" version=0.46.0 commit=0e753af5 date=2026-05-14T22:18:43Z gitURL=https://github.com/openconfig/gnmic docs=https://gnmic.openconfig.net
time=2026-06-12T11:25:56.707+08:00 level=INFO msg="using config file" path=gnmic.yaml
time=2026-06-12T11:25:56.707+08:00 level=INFO msg="starting output" type=file
time=2026-06-12T11:25:56.708+08:00 level=INFO msg="initialized file output" output=file name=console config="{"Name":"console","FileName":"/dev/stdout","FileType":"","Format":"event","Multiline":false,"Indent":"","Separator":"\n","SplitEvents":false,"OverrideTimestamps":false,"AddTarget":"","TargetTemplate":"","EventProcessors":null,"MsgTemplate":"","ConcurrencyLimit":1000,"EnableMetrics":false,"Debug":false,"CalculateLatency":false,"Rotation":null}"
time=2026-06-12T11:25:56.708+08:00 level=INFO msg="starting output" type=prometheus
time=2026-06-12T11:25:56.709+08:00 level=INFO msg="initialized prometheus output" output=prometheus name=my_prom_exporter config="{"buffer-size":10000,"expiration":60000000000,"listen":":9273","metric-prefix":"h3c","name":"my_prom_exporter","num-workers":1,"path":"/metrics","strings-as-labels":true,"timeout":10000000000}"
time=2026-06-12T11:25:56.709+08:00 level=INFO msg="queuing target" target=h3c_switch
time=2026-06-12T11:25:56.709+08:00 level=INFO msg="subscribing to target" target=h3c_switch
time=2026-06-12T11:25:56.709+08:00 level=INFO msg="starting target listener" target=h3c_switch
time=2026-06-12T11:25:56.709+08:00 level=INFO msg="target gNMI client created" target=h3c_switch
time=2026-06-12T11:25:56.709+08:00 level=INFO msg="sending gNMI SubscribeRequest" target=h3c_switch subscribe="subscribe:{subscription:{path:{elem:{name:"Ifmgr"} elem:{name:"Statistics"} elem:{name:"Interface" key:{key:"Name" value:"GigabitEthernet1/0/48"}}} mode:SAMPLE sample_interval:3000000000} encoding:JSON_IETF}" mode=STREAM encoding=JSON_IETF
[{"name":"if_stats","timestamp":1796527565878966000,"tags":{"Interface_Name":"GigabitEthernet1/0/48","source":"h3c_switch","subscription-name":"if_stats"},"values":{"/Ifmgr/Statistics/Interface":[{"ifmgr-data:AbbreviatedName":"GE1/0/48","ifmgr-data:IfIndex":48,"ifmgr-data:InDiscards":4452,"ifmgr-data:InErrors":0,"ifmgr-data:InNUcastPkts":127963063,"ifmgr-data:InOctets":86628066417,"ifmgr-data:InPktRate":23,"ifmgr-data:InPkts":893957015,"ifmgr-data:InRate":2332,"ifmgr-data:InUcastPkts":765993952,"ifmgr-data:InUnknownProtos":0,"ifmgr-data:LastClear":"0000-00-00T00:00:00","ifmgr-data:Name":"GigabitEthernet1/0/48","ifmgr-data:OutDiscards":0,"ifmgr-data:OutErrors":0,"ifmgr-data:OutNUcastPkts":23136465,"ifmgr-data:OutOctets":1530879888879,"ifmgr-data:OutPktRate":25,"ifmgr-data:OutPkts":1629851559,"ifmgr-data:OutRate":6253,"ifmgr-data:OutUcastPkts":1606715094}]}}]

Prometheus /metrics output:

tingyu@630-10.16.254.114:~/gnmic$ curl http://127.0.0.1:9273/metrics

HELP h3c_Ifmgr_Statistics_Interface gNMIc generated metric

TYPE h3c_Ifmgr_Statistics_Interface untyped

h3c_Ifmgr_Statistics_Interface{Interface="",Interface_Name="GigabitEthernet1/0/48",source="h3c_switch",subscription_name="if_stats"} 1
Why does the Prometheus metric show a value of 1 instead of the actual statistics values from the JSON? How can I configure gnmic to expose each field (e.g., InPkts, InOctets, InRate, etc.) as separate Prometheus metrics?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions