DefaultSocketName = adapter.DefaultBinapiSocket
)
+const socketMissing = `
+------------------------------------------------------------
+ VPP binary API socket file %s is missing!
+
+ - is VPP running with socket for binapi enabled?
+ - is the correct socket name configured?
+
+ To enable it add following section to your VPP config:
+ socksvr {
+ default
+ }
+------------------------------------------------------------
+`
+
var (
// DefaultConnectTimeout is default timeout for connecting
DefaultConnectTimeout = time.Second * 3
}
func (c *vppClient) Connect() error {
- Log.Debugf("Connecting to: %v", c.sockAddr)
+ // check if socket exists
+ if _, err := os.Stat(c.sockAddr); os.IsNotExist(err) {
+ fmt.Fprintf(os.Stderr, socketMissing, c.sockAddr)
+ return fmt.Errorf("VPP API socket file %s does not exist", c.sockAddr)
+ } else if err != nil {
+ return fmt.Errorf("VPP API socket error: %v", err)
+ }
if err := c.connect(c.sockAddr); err != nil {
return err
func (c *vppClient) connect(sockAddr string) error {
addr := &net.UnixAddr{Name: sockAddr, Net: "unix"}
+ Log.Debugf("Connecting to: %v", c.sockAddr)
+
conn, err := net.DialUnix("unix", nil, addr)
if err != nil {
// we try different type of socket for backwards compatbility with VPP<=19.04
if strings.Contains(err.Error(), "wrong type for socket") {
addr.Net = "unixpacket"
- Log.Warnf("%s, retrying connect with type unixpacket", err)
+ Log.Debugf("%s, retrying connect with type unixpacket", err)
conn, err = net.DialUnix("unixpacket", nil, addr)
}
if err != nil {
header := c.readHeader()
Log.Debugf("stat segment header: %+v", header)
- // older VPP (19.04) did not have version in stat segment header
+ // older VPP (<=19.04) did not have version in stat segment header
// we try to provide fallback support by skipping it in header
if header.version > MaxVersion && header.inProgress > 1 && header.epoch == 0 {
h := c.readHeaderOld()
- Log.Warnf("statsclient: falling back to old stat segment version (VPP 19.04): %+v", h)
+ Log.Debugf("statsclient: falling back to old stat segment version (VPP <=19.04): %+v", h)
c.oldHeader = true
}
"git.fd.io/govpp.git/adapter"
)
+const (
+ // DefaultSocketName is default VPP stats socket file path.
+ DefaultSocketName = adapter.DefaultStatsSocket
+)
+
+const socketMissing = `
+------------------------------------------------------------
+ VPP stats socket file %s is missing!
+
+ - is VPP running with stats segment enabled?
+ - is the correct socket name configured?
+
+ To enable it add following section to your VPP config:
+ statseg {
+ default
+ }
+------------------------------------------------------------
+`
+
var (
// Debug is global variable that determines debug mode
Debug = os.Getenv("DEBUG_GOVPP_STATS") != ""
// NewStatsClient returns new VPP stats API client.
func NewStatsClient(sockAddr string) *StatsClient {
if sockAddr == "" {
- sockAddr = adapter.DefaultStatsSocket
+ sockAddr = DefaultSocketName
}
return &StatsClient{
sockAddr: sockAddr,
}
}
-const sockNotFoundWarn = `stats socket not found at: %s
-------------------------------------------------------------
- VPP stats socket is missing!
- Is VPP running with stats segment enabled?
-
- To enable it add following section to startup config:
- statseg {
- default
- }
-------------------------------------------------------------
-`
-
func (c *StatsClient) Connect() error {
// check if socket exists
if _, err := os.Stat(c.sockAddr); os.IsNotExist(err) {
- Log.Warnf(sockNotFoundWarn, c.sockAddr)
+ fmt.Fprintf(os.Stderr, socketMissing, c.sockAddr)
return fmt.Errorf("stats socket file %s does not exist", c.sockAddr)
} else if err != nil {
return fmt.Errorf("stats socket error: %v", err)
+// Copyright (c) 2019 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 api
// SystemStats represents global system statistics.
The following requirements are required to run this example:
-- install **VPP 18.10+** (VPP 19.04+ for goclient)
+- install VPP **18.10+** (VPP 19.04+ for statsclient)
- enable stats in VPP
To enable stats add following section to you VPP config:
// ------------------------------------------------------------------
var (
- statsSocket = flag.String("socket", adapter.DefaultStatsSocket, "Path to VPP stats socket")
+ statsSocket = flag.String("socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
dumpAll = flag.Bool("all", false, "Dump all stats including ones with zero values")
-
- goclient = flag.Bool("goclient", false, "Use pure Go client for stats API")
+ oldclient = flag.Bool("oldclient", false, "Use old client for stats API (vppapiclient)")
)
func init() {
}
var client adapter.StatsAPI
- if *goclient {
- client = statsclient.NewStatsClient(*statsSocket)
- } else {
+ if *oldclient {
client = vppapiclient.NewStatClient(*statsSocket)
+ } else {
+ client = statsclient.NewStatsClient(*statsSocket)
}
fmt.Printf("Connecting to stats socket: %s\n", *statsSocket)
case "dump":
dumpStats(client, patterns, skipZeros)
+
default:
listStats(client, patterns)
}