Add -vpp-ifindex-offset flag
This commit is contained in:
75
main.go
75
main.go
@ -1,42 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
"flag"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/posteo/go-agentx"
|
||||
|
||||
"govpp-snmp-example/vppstats"
|
||||
"github.com/posteo/go-agentx"
|
||||
|
||||
"govpp-snmp-example/ifmib"
|
||||
"govpp-snmp-example/vppstats"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr := flag.String("agentx-addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)")
|
||||
vppStatsAddr := flag.String("vpp-stats-addr", "/var/run/vpp/stats.sock", "VPP stats socket path")
|
||||
period := flag.Float64("period", 10.0, "Interval in seconds for querying VPP interface stats")
|
||||
flag.Parse()
|
||||
addr := flag.String("agentx-addr", "localhost:705", "Address to connect to (hostname:port or Unix socket path)")
|
||||
vppStatsAddr := flag.String("vpp-stats-addr", "/var/run/vpp/stats.sock", "VPP stats socket path")
|
||||
period := flag.Float64("period", 10.0, "Interval in seconds for querying VPP interface stats")
|
||||
ifIndexOffset := flag.Int("vpp-ifindex-offset", 1000, "Offset to add to VPP interface indices for SNMP")
|
||||
flag.Parse()
|
||||
|
||||
var network, address string
|
||||
if strings.HasPrefix(*addr, "/") {
|
||||
network = "unix"
|
||||
address = *addr
|
||||
} else {
|
||||
network = "tcp"
|
||||
address = *addr
|
||||
}
|
||||
var network, address string
|
||||
if strings.HasPrefix(*addr, "/") {
|
||||
network = "unix"
|
||||
address = *addr
|
||||
} else {
|
||||
network = "tcp"
|
||||
address = *addr
|
||||
}
|
||||
|
||||
client, err := agentx.Dial(network, address)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to dial %s %s: %v", network, address, err)
|
||||
}
|
||||
client.Timeout = 1 * time.Minute
|
||||
client.ReconnectInterval = 1 * time.Second
|
||||
client, err := agentx.Dial(network, address)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to dial %s %s: %v", network, address, err)
|
||||
}
|
||||
client.Timeout = 1 * time.Minute
|
||||
client.ReconnectInterval = 1 * time.Second
|
||||
|
||||
// Start VPP stats routine
|
||||
vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond)
|
||||
session, err := client.Session()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create session: %v", err)
|
||||
}
|
||||
|
||||
for {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
// Create the interface MIB
|
||||
interfaceMIB := ifmib.NewInterfaceMIB(*ifIndexOffset)
|
||||
|
||||
// Register the interface MIB with the AgentX session
|
||||
if err := interfaceMIB.RegisterWithSession(session); err != nil {
|
||||
log.Fatalf("Failed to register interface MIB: %v", err)
|
||||
}
|
||||
|
||||
// Start VPP stats routine with callback to update MIB
|
||||
vppstats.StartStatsRoutine(*vppStatsAddr, time.Duration(*period*1000)*time.Millisecond, interfaceMIB.UpdateStats)
|
||||
|
||||
for {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user