gnmi-streamer

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

README

gNMI Streamer

GoDoc Test codecov Go Report Card

gNMI Server to stream arbitrary data. It produces a random metric for the targets and data paths listed in a JSON file.

Server

Run the server on a tab with make server.

$ make server
I1119 09:02:54.822880   29014 main.go:149] listening on [::]:9339
I1119 09:03:02.164796   29014 subscribe.go:283] peer: 127.0.0.1:51101 target: "dev2" subscription: subscribe:{prefix:{target:"dev2"} subscription:{path:{element:"a" elem:{name:"a"}}}}
I1119 09:03:07.014033   29014 subscribe.go:323] peer: 127.0.0.1:51101 target "dev2" subscription: end: "subscribe:{prefix:{target:\"dev2\"} subscription:{path:{element:\"a\" elem:{name:\"a\"}}}}"

You can configure the following environmental variables:

  • GNMI_HOST: Server IP address. Default "".
  • GNMI_PORT: Server port. Default "9339".
  • GNMI_FILE: JSON file with list of devices and paths to stream. Default "updates.json".
  • GNMI_CADENCE: How often to generate a metric for the device path. Default 5.

Client

Run the server on a different tab with make client.

$ make client
2024/11/19 09:03:02 Subscribing
RESPONSE:
  PATH: elem:{name:"a"}  elem:{name:"b"  key:{key:"n"  value:"c"}}  elem:{name:"d"}
  VALUE: int_val:929
RESPONSE:
  PATH: elem:{name:"a"}  elem:{name:"b"  key:{key:"n"  value:"c"}}  elem:{name:"d"}
  VALUE: int_val:18
...
gNMIc

You can alternatively subscribe to the server with gNMIc.

bash -c "$(curl -sL https://get-gnmic.openconfig.net)"
$ gnmic -a [::]:9339 --skip-verify --target dev1 subscribe --path "/state/router[router-name=*]/interface[interface-name=*]/statistics/ip/in-octets"
{
  "sync-response": true
}
{
  "source": ":9339",
  "subscription-name": "default-1732025210",
  "timestamp": 1732025204640357001,
  "time": "2024-11-19T09:06:44.640357001-05:00",
  "target": "dev1",
  "updates": [
    {
      "Path": "state/router[router-name=dev1]/interface[interface-name=*]/statistics/ip/in-octets",
      "values": {
        "state/router/interface/statistics/ip/in-octets": 213
      }
    }
  ]
}
$ gnmic -a [::]:9339 --skip-verify --target dev2 subscribe --path "a" --format prototext
sync_response: true

update: {
  timestamp: 1732025259640538002
  prefix: {
    target: "dev2"
  }
  update: {
    path: {
      elem: {
        name: "a"
      }
      elem: {
        name: "b"
        key: {
          key: "n"
          value: "c"
        }
      }
      elem: {
        name: "d"
      }
    }
    val: {
      int_val: 424
    }
  }
}
...

Credits

This is copy & paste from the following packages.

References

  • SNMP is dead: Describes the a gNMI caching collector from multiple gNMI sources (targets) to multiple gNMI clients. recording

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL