func collect() { // start collect data for lvs cluster. var interval int64 = g.Config().Transfer.Interval var ticker = time.NewTicker(time.Duration(interval) * time.Second) ipvs.Init() for { <-ticker.C mvs := []*model.MetricValue{} // Collect metrics from /proc/net/ip_vs vips, err := GetIPVSStats() if err != nil { glog.Errorf("%s", err.Error()) } mvs, _ = ConvertVIPs2Metrics(vips) g.SendMetrics(mvs) // Collect metrics from /proc/net/ip_vs_stats mvs, err = ParseIPVSStats(IPVSSTATSFILE) if os.IsNotExist(err) { glog.Fatalf("%s", err.Error()) } g.SendMetrics(mvs) } }
// initIPVS initialises the IPVS sub-component. func initIPVS() { ipvsMutex.Lock() defer ipvsMutex.Unlock() log.Infof("Initialising IPVS...") if err := ipvs.Init(); err != nil { // TODO(jsing): modprobe ip_vs and try again. log.Fatalf("IPVS initialisation failed: %v", err) } log.Infof("IPVS version %s", ipvs.Version()) }
func main() { if err := ipvs.Init(); err != nil { log.Fatalf("IPVS initialisation failed: %v\n", err) } log.Printf("IPVS version %s\n", ipvs.Version()) testIPVS() testIPVSModification() // Clean up after ourselves... if err := ipvs.Flush(); err != nil { log.Fatalf("Failed to flush IPVS table: %v\n", err) } }
//New creates a new ipvs struct and flushes the IPVS Table func New() (*Ipvs, error) { if err := loadIpvsModule(); err != nil { return nil, err } if err := gipvs.Init(); err != nil { return nil, fmt.Errorf("[ipvs] Initialisation failed: %v", err) } ipvs := &Ipvs{} if err := ipvs.Flush(); err != nil { return nil, fmt.Errorf("[ipvs] Flushing table failed: %v", err) } return ipvs, nil }