aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-07-19 05:42:41 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-07-19 05:42:41 +0200
commitbde85d422c7949ec32fb067e9c36320ccc47fb9e (patch)
tree10203b958ed04f12da7556356b5dcf3f70571bc7
parent4dca07c803308611275f78b490ac0352c1052fe2 (diff)
Print info for users to stderr when socket files are missing
Change-Id: Ibdbfcb78b05cf80945a93ed424a7a2a03b6ea06d Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
-rw-r--r--adapter/socketclient/socketclient.go26
-rw-r--r--adapter/statsclient/stat_segment.go4
-rw-r--r--adapter/statsclient/statsclient.go35
-rw-r--r--api/stats.go14
-rw-r--r--examples/stats-api/README.md2
-rw-r--r--examples/stats-api/stats_api.go12
6 files changed, 68 insertions, 25 deletions
diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go
index 96f23e6..2144d24 100644
--- a/adapter/socketclient/socketclient.go
+++ b/adapter/socketclient/socketclient.go
@@ -40,6 +40,20 @@ const (
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
@@ -165,7 +179,13 @@ func (c *vppClient) SetMsgCallback(cb adapter.MsgCallback) {
}
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
@@ -212,12 +232,14 @@ func (c *vppClient) Disconnect() error {
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 {
diff --git a/adapter/statsclient/stat_segment.go b/adapter/statsclient/stat_segment.go
index 1875f17..e8d20b0 100644
--- a/adapter/statsclient/stat_segment.go
+++ b/adapter/statsclient/stat_segment.go
@@ -117,11 +117,11 @@ func (c *statSegment) connect(sockName string) error {
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
}
diff --git a/adapter/statsclient/statsclient.go b/adapter/statsclient/statsclient.go
index f715a70..6381b9f 100644
--- a/adapter/statsclient/statsclient.go
+++ b/adapter/statsclient/statsclient.go
@@ -27,6 +27,25 @@ import (
"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") != ""
@@ -55,29 +74,17 @@ type StatsClient struct {
// 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)
diff --git a/api/stats.go b/api/stats.go
index 0bf9908..e254eae 100644
--- a/api/stats.go
+++ b/api/stats.go
@@ -1,3 +1,17 @@
+// 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.
diff --git a/examples/stats-api/README.md b/examples/stats-api/README.md
index 5511bf4..f3d33b1 100644
--- a/examples/stats-api/README.md
+++ b/examples/stats-api/README.md
@@ -6,7 +6,7 @@ This example demonstrates how to retrieve statistics from VPP using [the new Sta
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:
diff --git a/examples/stats-api/stats_api.go b/examples/stats-api/stats_api.go
index a42e3d2..175bb27 100644
--- a/examples/stats-api/stats_api.go
+++ b/examples/stats-api/stats_api.go
@@ -35,10 +35,9 @@ import (
// ------------------------------------------------------------------
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() {
@@ -66,10 +65,10 @@ func main() {
}
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)
@@ -138,6 +137,7 @@ func main() {
case "dump":
dumpStats(client, patterns, skipZeros)
+
default:
listStats(client, patterns)
}