diff options
author | Ondrej Fabry <ofabry@cisco.com> | 2018-10-22 14:21:28 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@fd.io> | 2018-10-22 14:21:28 +0000 |
commit | c00356ec332203f353fcd5f5992226940d90da92 (patch) | |
tree | f848f4b40300982c913d17eda3feb52b6ef3c697 /examples | |
parent | 56e997fc27c775790fcce5eda92bb2baee82d881 (diff) | |
parent | 28df7c855784e784fb0e614c1cca0e565a7ef75f (diff) |
Merge "Introduce StatsAPI and it's initial implementation"
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..") |