當前位置: 首頁>>代碼示例>>Golang>>正文


Golang g.Config函數代碼示例

本文整理匯總了Golang中github.com/gaochao1/swcollector/g.Config函數的典型用法代碼示例。如果您正苦於以下問題:Golang Config函數的具體用法?Golang Config怎麽用?Golang Config使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Config函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: swIfMetrics

func swIfMetrics() (L []*model.MetricValue) {
	initVariable()

	allIp := AllSwitchIp()

	chs := make([]chan ChIfStat, len(allIp))
	limitCh := make(chan bool, g.Config().Switch.LimitConcur)

	startTime := time.Now()
	log.Printf("UpdateIfStats start. The number of concurrent limited to %d. IP addresses number is %d", g.Config().Switch.LimitConcur, len(allIp))

	for i, ip := range allIp {
		chs[i] = make(chan ChIfStat)
		limitCh <- true
		go coreSwIfMetrics(ip, chs[i], limitCh)
		time.Sleep(5 * time.Millisecond)
	}

	for _, ch := range chs {
		chIfStat := <-ch

		if chIfStat.PingResult == true && !slice.ContainsString(AliveIp, chIfStat.Ip) {
			AliveIp = append(AliveIp, chIfStat.Ip)
		}

		if chIfStat.IfStatsList != nil {

			if g.Config().Debug {
				log.Println(chIfStat.Ip, chIfStat.PingResult, len(*chIfStat.IfStatsList), chIfStat.UseTime)
			}

			for _, ifStat := range *chIfStat.IfStatsList {
				ifNameTag := "ifName=" + ifStat.IfName
				ifIndexTag := "ifIndex=" + strconv.Itoa(ifStat.IfIndex)
				ip := chIfStat.Ip

				L = append(L, CounterValueIp(ifStat.TS, ip, "switch.if.In", ifStat.IfHCInOctets, ifNameTag, ifIndexTag))
				L = append(L, CounterValueIp(ifStat.TS, ip, "switch.if.Out", ifStat.IfHCOutOctets, ifNameTag, ifIndexTag))

				//如果IgnorePkt為false,采集Pkt
				if g.Config().Switch.IgnorePkt == false {
					L = append(L, CounterValueIp(ifStat.TS, ip, "switch.if.InPkts", ifStat.IfHCInUcastPkts, ifNameTag, ifIndexTag))
					L = append(L, CounterValueIp(ifStat.TS, ip, "switch.if.OutPkts", ifStat.IfHCOutUcastPkts, ifNameTag, ifIndexTag))
				}

			}
		}
	}

	endTime := time.Now()
	log.Printf("UpdateIfStats complete. Process time %s. Number of active ip is %d", endTime.Sub(startTime), len(AliveIp))

	if g.Config().Debug {
		for i, v := range AliveIp {
			log.Println("AliveIp:", i, v)
		}
	}

	return
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:60,代碼來源:swifstat.go

示例2: swSystemInfo

func swSystemInfo(ip string, ch chan SwSystem) {
	var swSystem SwSystem
	swSystem.Ip = ip

	//ping timeout.Millisecond
	timeout := 1000
	pingCount := 1

	ping, err := sw.PingStatSummary(ip, pingCount, timeout)
	if err != nil {
		log.Println(err)
		ch <- swSystem
		return
	} else {
		swSystem.Ping = ping["max"]

		uptime, err := sw.SysUpTime(ip, g.Config().Switch.Community, timeout)
		if err != nil {
			log.Println(err)
			ch <- swSystem
			return
		} else {
			swSystem.Uptime = uptime

			cpuUtili, err := sw.CpuUtilization(ip, g.Config().Switch.Community, timeout, 1)
			if err != nil {
				log.Println(err)
			} else {
				swSystem.Cpu = cpuUtili
			}

			memUtili, err := sw.MemUtilization(ip, g.Config().Switch.Community, timeout, 1)
			if err != nil {
				log.Println(err)
			} else {
				swSystem.Mem = memUtili
			}

			swModel, err := sw.SysModel(ip, g.Config().Switch.Community, timeout)
			if err != nil {
				log.Println(err)
			} else {
				swSystem.Model = swModel
			}

			swName, err := sw.SysName(ip, g.Config().Switch.Community, timeout)
			if err != nil {
				log.Println(err)
			} else {
				swSystem.Hostname = swName
			}

		}

	}

	ch <- swSystem
	return
}
開發者ID:freedomkk-qfeng,項目名稱:swcollector,代碼行數:59,代碼來源:swsystem.go

示例3: Collect

func Collect() {
	if !g.Config().Transfer.Enabled {
		return
	}

	if g.Config().Transfer.Addr == "" {
		return
	}

	for _, v := range funcs.Mappers {
		go collect(int64(v.Interval), v.Fs)
	}
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:13,代碼來源:collector.go

示例4: cpuMetrics

func cpuMetrics(ip string, ch chan SwCpu) {
	var swCpu SwCpu

	cpuUtili, err := sw.CpuUtilization(ip, g.Config().Switch.Community, g.Config().Switch.SnmpTimeout, g.Config().Switch.SnmpRetry)
	if err != nil {
		log.Println(err)
	}

	swCpu.Ip = ip
	swCpu.CpuUtil = cpuUtili
	ch <- swCpu

	return
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:14,代碼來源:swcpu.go

示例5: memMetrics

func memMetrics(ip string, ch chan SwMem) {
	var swMem SwMem

	memUtili, err := sw.MemUtilization(ip, g.Config().Switch.Community, g.Config().Switch.SnmpTimeout, g.Config().Switch.SnmpRetry)
	if err != nil {
		log.Println(err)
	}

	swMem.Ip = ip
	swMem.MemUtili = memUtili
	ch <- swMem

	return
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:14,代碼來源:swmem.go

示例6: configAdminRoutes

func configAdminRoutes() {
	http.HandleFunc("/exit", func(w http.ResponseWriter, r *http.Request) {
		if g.IsTrustable(r.RemoteAddr) {
			w.Write([]byte("exiting..."))
			go func() {
				time.Sleep(time.Second)
				os.Exit(0)
			}()
		} else {
			w.Write([]byte("no privilege"))
		}
	})

	http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) {
		if g.IsTrustable(r.RemoteAddr) {
			g.ParseConfig(g.ConfigFile)
			RenderDataJson(w, g.Config())
		} else {
			w.Write([]byte("no privilege"))
		}
	})

	http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, file.SelfDir())
	})

	http.HandleFunc("/ips", func(w http.ResponseWriter, r *http.Request) {
		RenderDataJson(w, g.TrustableIps())
	})
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:30,代碼來源:admin.go

示例7: configSwRoutes

func configSwRoutes() {

	http.HandleFunc("/page/sw/time", func(w http.ResponseWriter, req *http.Request) {
		RenderDataJson(w, time.Now().Format("2006-01-02 15:04:05"))
	})

	http.HandleFunc("/page/sw/iprange", func(w http.ResponseWriter, req *http.Request) {
		RenderDataJson(w, strings.Join(g.Config().Switch.IpRange, "\n"))
	})

	http.HandleFunc("/page/sw/live", func(w http.ResponseWriter, req *http.Request) {
		RenderDataJson(w, len(funcs.AliveIp))
	})

	http.HandleFunc("/page/sw/list", func(w http.ResponseWriter, r *http.Request) {

		var ret [][]interface{} = make([][]interface{}, 0)
		for _, swSystem := range funcs.SwSystemInfo() {
			ret = append(ret,
				[]interface{}{
					swSystem.Ip,
					swSystem.Hostname,
					swSystem.Model,
					swSystem.Uptime,
					fmt.Sprintf("%d%%", swSystem.Cpu),
					fmt.Sprintf("%d%%", swSystem.Mem),
					fmt.Sprintf("%sms", swSystem.Ping),
				})
		}
		RenderDataJson(w, ret)
	})
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:32,代碼來源:sw.go

示例8: connMetrics

func connMetrics(ip string, ch chan SwConn) {
	var swConn SwConn
	vendor, _ := sw.SysVendor(ip, community, snmpTimeout)
	if !strings.Contains(vendor, "Cisco_ASA") {
		ch <- swConn
		return
	}
	ConnectionStat, err := sw.ConnectionStat(ip, g.Config().Switch.Community, g.Config().Switch.SnmpTimeout, g.Config().Switch.SnmpRetry)
	if err != nil {
		log.Println(err)
	}

	swConn.Ip = ip
	swConn.ConnectionStat = ConnectionStat
	ch <- swConn

	return
}
開發者ID:freedomkk-qfeng,項目名稱:swcollector,代碼行數:18,代碼來源:swconn.go

示例9: Start

func Start() {
	if !g.Config().Http.Enabled {
		return
	}

	addr := g.Config().Http.Listen
	if addr == "" {
		return
	}

	s := &http.Server{
		Addr:           addr,
		MaxHeaderBytes: 1 << 30,
	}

	log.Println("listening", addr)
	log.Fatalln(s.ListenAndServe())
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:18,代碼來源:http.go

示例10: pingMetrics

func pingMetrics(ip string, ch chan SwPing) {
	var swPing SwPing
	timeout := g.Config().Switch.PingTimeout * g.Config().Switch.PingRetry
	fastPingMode := g.Config().Switch.FastPingMode
	rtt, err := sw.PingRtt(ip, timeout, fastPingMode)
	if err != nil {
		log.Println(ip, err)
		swPing.Ip = ip
		swPing.Ping = -1
		ch <- swPing
		return
	}
	if g.Config().Debug {
		log.Println(ip, rtt)
	}
	swPing.Ip = ip
	swPing.Ping = rtt
	ch <- swPing
	return

}
開發者ID:freedomkk-qfeng,項目名稱:swcollector,代碼行數:21,代碼來源:swping.go

示例11: initVariable

func initVariable() {
	pingTimeout = g.Config().Switch.PingTimeout
	pingRetry = g.Config().Switch.PingRetry

	community = g.Config().Switch.Community
	snmpTimeout = g.Config().Switch.SnmpTimeout
	snmpRetry = g.Config().Switch.SnmpRetry

	ignoreIface = g.Config().Switch.IgnoreIface
	ignorePkt = g.Config().Switch.IgnorePkt
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:11,代碼來源:swifstat.go

示例12: AllSwitchIp

func AllSwitchIp() (allIp []string) {
	switchIp := g.Config().Switch.IpRange

	if len(switchIp) > 0 {
		for _, sip := range switchIp {
			aip := sw.ParseIp(sip)
			for _, ip := range aip {
				allIp = append(allIp, ip)
			}
		}
	}
	return allIp
}
開發者ID:freedomkk-qfeng,項目名稱:swcollector,代碼行數:13,代碼來源:swifstat.go

示例13: BuildMappers

func BuildMappers() {
	interval := g.Config().Transfer.Interval
	Mappers = []FuncsAndInterval{
		FuncsAndInterval{
			Fs: []func() []*model.MetricValue{
				SwIfMetrics,
				AgentMetrics,
				CpuMetrics,
				MemMetrics,
				PingMetrics,
			},
			Interval: interval,
		},
	}
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:15,代碼來源:funcs.go

示例14: pingMetrics

func pingMetrics(ip string, ch chan SwPing) {
	var swPing SwPing
	timeout := g.Config().Switch.PingTimeout * 4

	rtt, err := sw.PingRtt(ip, timeout)
	if err != nil {
		log.Println(ip, err)
		swPing.Ping = 0
	}

	swPing.Ip = ip
	swPing.Ping = rtt
	ch <- swPing

	return
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:16,代碼來源:swping.go

示例15: syncTrustableIps

func syncTrustableIps() {

	duration := time.Duration(g.Config().Heartbeat.Interval) * time.Second

	for {
	REST:
		time.Sleep(duration)

		var ips string
		err := g.HbsClient.Call("Agent.TrustableIps", model.NullRpcRequest{}, &ips)
		if err != nil {
			log.Println("ERROR: call Agent.TrustableIps fail", err)
			goto REST
		}

		g.SetTrustableIps(ips)
	}
}
開發者ID:heafod,項目名稱:swcollector,代碼行數:18,代碼來源:ips.go


注:本文中的github.com/gaochao1/swcollector/g.Config函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。