diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2018-10-22 14:45:21 +0200 |
---|---|---|
committer | Ondrej Fabry <ofabry@cisco.com> | 2018-10-22 14:56:09 +0200 |
commit | 28df7c855784e784fb0e614c1cca0e565a7ef75f (patch) | |
tree | 7d2eb1b3522d57680df8a6f576356f9dd4dc706c /examples | |
parent | 62d19032621c7db801b313a1e19e787cfb1fbc3e (diff) |
Introduce StatsAPI and it's initial implementation
- this implementation is basically Go wrapper around VPP's vppapiclient C library
Change-Id: I6f53dc3e228868834bf3a8a00c686ad05e22f3dd
Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cmd/stats-api/stats_api.go | 66 | ||||
-rw-r--r-- | examples/cmd/stats-client/stats_client.go | 9 |
2 files changed, 75 insertions, 0 deletions
diff --git a/examples/cmd/stats-api/stats_api.go b/examples/cmd/stats-api/stats_api.go new file mode 100644 index 0000000..74454ab --- /dev/null +++ b/examples/cmd/stats-api/stats_api.go @@ -0,0 +1,66 @@ +// Copyright (c) 2018 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "fmt" + "log" + + "git.fd.io/govpp.git/adapter" + "git.fd.io/govpp.git/adapter/vppapiclient" +) + +// This example shows how to work with VPP's new stats API. + +func main() { + fmt.Println("Starting VPP stats API example..") + + client := vppapiclient.NewStatClient(vppapiclient.DefaultStatSocket) + + // connect to stats API + if err := client.Connect(); err != nil { + log.Fatalln("connecting client failed:", err) + } + defer client.Disconnect() + + // list stats by patterns + // you can omit parameters to list all stats + list, err := client.ListStats("/if", "/sys") + if err != nil { + log.Fatalln("listing stats failed:", err) + } + + for _, stat := range list { + fmt.Printf(" - %v\n", stat) + } + fmt.Printf("listed %d stats\n", len(list)) + + // dump stats by patterns to retrieve stats with the stats data + stats, err := client.DumpStats() + if err != nil { + log.Fatalln("dumping stats failed:", err) + } + + for _, stat := range stats { + switch data := stat.Data.(type) { + case adapter.ErrorStat: + if data == 0 { + // skip printing errors with 0 value + continue + } + } + fmt.Printf(" - %-25s %25v %+v\n", stat.Name, stat.Type, stat.Data) + } +} diff --git a/examples/cmd/stats-client/stats_client.go b/examples/cmd/stats-client/stats_client.go index f61f975..7a2c313 100644 --- a/examples/cmd/stats-client/stats_client.go +++ b/examples/cmd/stats-client/stats_client.go @@ -28,6 +28,15 @@ import ( "git.fd.io/govpp.git/examples/bin_api/stats" ) +/* + + IMPORTANT NOTICE! + + The binary API module stats used in this example will be deprecated in VPP 19.01. + VPP's new stats API should be used, you can find basic usage of new stats API in example stats-api. + +*/ + func main() { fmt.Println("Starting stats VPP client..") |