-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add stats poller service for retrieving VPP stats (#1495)
* Update govpp Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Split stats and CLI telemetry handlers - move telemetry handler for vpp stats to vppcalls - add method for retrieving system stats to vppcalls API - define FallbackToCli variable Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Update ifplugin for govpp changes Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Add StatsPoller service for retrieving stats periodically Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Begin PollStats with polling not period delay Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Validate poll period Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Fix vpp integration test for telemetry Signed-off-by: Ondrej Fabry <ofabry@cisco.com> * Fix closing channel Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
- Loading branch information
1 parent
1ab57a3
commit f3ed152
Showing
37 changed files
with
2,395 additions
and
1,389 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// 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 main | ||
|
||
import ( | ||
"log" | ||
"net" | ||
"time" | ||
|
||
"github.com/ligato/cn-infra/agent" | ||
"github.com/ligato/cn-infra/infra" | ||
"github.com/namsral/flag" | ||
"golang.org/x/net/context" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/ligato/vpp-agent/api/configurator" | ||
) | ||
|
||
var ( | ||
address = flag.String("address", "localhost:9111", "address of GRPC server") | ||
socketType = flag.String("socket-type", "tcp", "[tcp, tcp4, tcp6, unix, unixpacket]") | ||
period = flag.Uint("period", 3, "Polling period (in seconds)") | ||
) | ||
|
||
func main() { | ||
ep := &ExamplePlugin{} | ||
ep.SetName("stats-poller-example") | ||
ep.Setup() | ||
|
||
a := agent.NewAgent( | ||
agent.AllPlugins(ep), | ||
) | ||
if err := a.Run(); err != nil { | ||
log.Fatal() | ||
} | ||
} | ||
|
||
// ExamplePlugin demonstrates the use of grpc to watch on VPP notifications using vpp-agent. | ||
type ExamplePlugin struct { | ||
infra.PluginDeps | ||
|
||
conn *grpc.ClientConn | ||
} | ||
|
||
// Init initializes example plugin. | ||
func (p *ExamplePlugin) Init() (err error) { | ||
// Set up connection to the server. | ||
p.conn, err = grpc.Dial("unix", | ||
grpc.WithInsecure(), | ||
grpc.WithDialer(dialer(*socketType, *address, time.Second*3))) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
client := configurator.NewStatsPollerClient(p.conn) | ||
|
||
// Start stats poller. | ||
go p.pollStats(client) | ||
|
||
return err | ||
} | ||
|
||
// Get is an implementation of client-side statistics streaming. | ||
func (p *ExamplePlugin) pollStats(client configurator.StatsPollerClient) { | ||
p.Log.Infof("Polling every %v seconds..", *period) | ||
|
||
req := &configurator.PollStatsRequest{ | ||
PeriodSec: uint32(*period), | ||
} | ||
|
||
ctx := context.Background() | ||
stream, err := client.PollStats(ctx, req) | ||
if err != nil { | ||
p.Log.Fatalln("PollStats failed:", err) | ||
} | ||
|
||
var lastSeq uint32 | ||
for { | ||
resp, err := stream.Recv() | ||
if err != nil { | ||
p.Log.Fatalln("Recv failed:", err) | ||
} | ||
|
||
if resp.PollSeq != lastSeq { | ||
p.Log.Infof(" --- Poll sequence: %-3v", resp.PollSeq) | ||
} | ||
lastSeq = resp.PollSeq | ||
|
||
vppStats := resp.GetStats().GetVppStats() | ||
p.Log.Infof("VPP stats: %v", vppStats) | ||
} | ||
} | ||
|
||
// Dialer for unix domain socket | ||
func dialer(socket, address string, timeoutVal time.Duration) func(string, time.Duration) (net.Conn, error) { | ||
return func(addr string, timeout time.Duration) (net.Conn, error) { | ||
// Pass values | ||
addr, timeout = address, timeoutVal | ||
// Dial with timeout | ||
return net.DialTimeout(socket, addr, timeoutVal) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.