mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-18 03:46:45 +00:00
plugins/traffic-control: separate function for clear settings
Make easier to combine latency and packet loss settings.
This commit is contained in:
@@ -285,7 +285,7 @@ func getControls() []extControl {
|
||||
Rank: 24,
|
||||
},
|
||||
handler: func(pid int) error {
|
||||
return DoTrafficControl(pid, "", "")
|
||||
return ClearTrafficControlSettings(pid)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -77,6 +77,52 @@ func DoTrafficControl(pid int, latency string, pktLoss string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func ClearTrafficControlSettings(pid int) error {
|
||||
cmds := [][]string{
|
||||
split("tc qdisc replace dev eth0 root handle 1: netem"),
|
||||
|
||||
// These steps are not required, since we don't do
|
||||
// ingress traffic control, only egress, see the TODO
|
||||
// at the beginning of the file.
|
||||
|
||||
//split("ip link add ifb0 type ifb"),
|
||||
//split("ip link set ifb0 up"),
|
||||
//split("tc qdisc add dev eth0 handle ffff: ingress"),
|
||||
//split("tc filter add dev eth0 parent ffff: protocol ip u32 match u32 0 0 action mirred egress redirect dev ifb0"),
|
||||
//split("tc qdisc replace dev ifb0 handle 1:0 root netem"),
|
||||
|
||||
// Add "loss %d%% rate %dkbit" when we add the
|
||||
// possibility to control the packet loss and
|
||||
// bandwidth. See the TODO at the beginning of the
|
||||
// file.
|
||||
|
||||
}
|
||||
netNS := fmt.Sprintf("/proc/%d/ns/net", pid)
|
||||
err := ns.WithNetNSPath(netNS, func(hostNS ns.NetNS) error {
|
||||
for _, cmd := range cmds {
|
||||
if output, err := exec.Command(cmd[0], cmd[1:]...).CombinedOutput(); err != nil {
|
||||
log.Error(string(output))
|
||||
return fmt.Errorf("failed to execute command: %v", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to perform traffic control: %v", err)
|
||||
}
|
||||
// clear cached parameters
|
||||
if netNSID, err := getNSID(netNS); err != nil {
|
||||
log.Error(netNSID)
|
||||
return fmt.Errorf("failed to get network namespace ID: %v", err)
|
||||
} else {
|
||||
//trafficControlStatusCache[netNSID] = trafficControlStatus{
|
||||
// latency: "-",
|
||||
// pktLoss: "-",
|
||||
delete(trafficControlStatusCache, netNSID)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getLatency(pid int) (string, error) {
|
||||
var status *trafficControlStatus
|
||||
var err error
|
||||
|
||||
Reference in New Issue
Block a user