本文整理汇总了Golang中minilog.Debugln函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugln函数的具体用法?Golang Debugln怎么用?Golang Debugln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugln函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sshClientActivity
func sshClientActivity(index int) {
sc := sshConns[index]
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
// generate a random byte slice
l := r.Intn(128)
b := make([]byte, l)
for i, _ := range b {
b[i] = byte(r.Int())
}
data := base64.StdEncoding.EncodeToString(b)
log.Debug("ssh activity to %v with %v", sc.Host, data)
start := time.Now().UnixNano()
sc.Stdin.Write([]byte(data))
sc.Stdin.Write([]byte{'\r', '\n'})
sshReportChan <- uint64(len(data))
expected := fmt.Sprintf("> %v\r\n%v\r\n> ", data, data)
for i := 0; i < 10 && sc.StdoutBuf.String() != expected; i++ {
time.Sleep(100 * time.Millisecond)
}
stop := time.Now().UnixNano()
log.Info("ssh %v %vns", sc.Host, uint64(stop-start))
log.Debugln("ssh: ", sc.StdoutBuf.String())
sc.StdoutBuf.Reset()
}
示例2: smtpServer
func smtpServer(p string) {
log.Debugln("smtpServer")
certfile, keyfile := generateCerts()
cert, err := tls.LoadX509KeyPair(certfile, keyfile)
if err != nil {
log.Fatalln("couldn't get cert: ", err)
}
TLSconfig = &tls.Config{Certificates: []tls.Certificate{cert}, ClientAuth: tls.VerifyClientCertIfGiven, ServerName: myFQDN}
listener, err := net.Listen(p, "0.0.0.0"+smtpPort)
if err != nil {
log.Fatalln(err)
}
for {
conn, err := listener.Accept()
if err != nil {
log.Debugln(err)
continue
}
client := NewSMTPClientSession(conn)
go client.Handler()
smtpReportChan <- 1
}
}
示例3: mux
// incoming message mux. Routes messages to the correct handlers based on
// message type
func (s *Server) mux() {
for {
m := <-s.in
switch m.Type {
case MESSAGE_CLIENT:
// handle a client response
log.Debugln("ron MESSAGE_CLIENT")
s.responses <- m.Client
case MESSAGE_TUNNEL:
// handle a tunnel message
log.Debugln("ron MESSAGE_TUNNEL")
s.routeTunnel(m)
case MESSAGE_COMMAND:
// route a command to one or all clients
log.Debugln("ron MESSAGE_COMMAND")
s.route(m)
case MESSAGE_FILE:
// send a file if it exists
s.sendFile(m)
default:
log.Error("unknown message type: %v", m.Type)
return
}
}
}
示例4: hostStatsMemory
func hostStatsMemory() (int, int, error) {
memory, err := os.Open("/proc/meminfo")
if err != nil {
return 0, 0, err
}
defer memory.Close()
scanner := bufio.NewScanner(memory)
var memTotal int
var memFree int
var memCached int
var memBuffers int
for scanner.Scan() {
d := strings.Fields(scanner.Text())
switch d[0] {
case "MemTotal:":
m, err := strconv.Atoi(d[1])
if err != nil {
return 0, 0, fmt.Errorf("cannot parse meminfo MemTotal: %v", err)
}
memTotal = m
log.Debugln("got memTotal %v", memTotal)
case "MemFree:":
m, err := strconv.Atoi(d[1])
if err != nil {
return 0, 0, fmt.Errorf("cannot parse meminfo MemFree: %v", err)
}
memFree = m
log.Debugln("got memFree %v", memFree)
case "Buffers:":
m, err := strconv.Atoi(d[1])
if err != nil {
return 0, 0, fmt.Errorf("cannot parse meminfo Buffers: %v", err)
}
memBuffers = m
log.Debugln("got memBuffers %v", memBuffers)
case "Cached:":
m, err := strconv.Atoi(d[1])
if err != nil {
return 0, 0, fmt.Errorf("cannot parse meminfo Cached: %v", err)
}
memCached = m
log.Debugln("got memCached %v", memCached)
}
}
if err := scanner.Err(); err != nil {
log.Error("reading meminfo:", err)
}
outputMemUsed := (memTotal - (memFree + memBuffers + memCached)) / 1024
outputMemTotal := memTotal / 1024
return outputMemTotal, outputMemUsed, nil
}
示例5: MSA
// MSA issues a Meshage State Annoucement, which contains a list of all the nodes connected to the broadcaster
func (n *Node) MSA() {
log.Debugln("MSA")
// rate limit MSA spam to once per MSA timeout / 2
n.msaLock.Lock()
defer n.msaLock.Unlock()
if time.Now().Sub(n.lastMSA) < (n.msaTimeout / 2) {
return
}
n.lastMSA = time.Now()
n.clientLock.Lock()
var clients []string
for k, _ := range n.clients {
clients = append(clients, k)
}
n.clientLock.Unlock()
sort.Strings(clients)
n.meshLock.Lock()
diff := false
if len(n.network[n.name]) != len(clients) {
diff = true
} else {
for i, v := range n.network[n.name] {
if clients[i] != v {
diff = true
break
}
}
}
if diff {
log.Debugln("client list changed, recalculating topology")
n.network[n.name] = clients
n.updateNetwork = true
}
n.meshLock.Unlock()
if log.WillLog(log.DEBUG) {
log.Debug("client list: %v", clients)
}
if len(clients) == 0 {
log.Debugln("not issuing MSA, no connected clients")
return
}
m := &Message{
Source: n.name,
CurrentRoute: []string{n.name},
ID: n.sequence(),
Command: MSA,
Body: clients,
}
n.flood(m)
}
示例6: bandwidthCollector
// enumerate bytes/second on all interfaces owned by minimega
func bandwidthCollector() {
var err error
for {
time.Sleep(BANDWIDTH_INTERVAL * time.Second)
stats := make(map[string]*TapStat)
// get a list of every tap we own
for _, v := range vms {
for _, net := range v.Config().Networks {
stats[net.Tap] = &TapStat{
Bridge: net.Bridge,
}
}
}
// for each tap, get rx/tx bytes
for k, v := range stats {
v.RxStart, err = readNetStats(k, "rx")
if err != nil {
log.Debugln(err)
continue
}
v.TxStart, err = readNetStats(k, "tx")
if err != nil {
log.Debugln(err)
continue
}
v.Start = time.Now()
}
time.Sleep(1 * time.Second)
// and again
for k, v := range stats {
v.RxStop, err = readNetStats(k, "rx")
if err != nil {
log.Debugln(err)
continue
}
v.TxStop, err = readNetStats(k, "tx")
if err != nil {
log.Debugln(err)
continue
}
v.Stop = time.Now()
}
bandwidthLock.Lock()
bandwidthStats = stats
bandwidthLock.Unlock()
}
}
示例7: Xfer
// Transfer a single filepart to a temporary transfer directory.
func (iom *IOMeshage) Xfer(filename string, part int64, from string) error {
TID := genTID()
c := make(chan *IOMMessage)
err := iom.registerTID(TID, c)
defer iom.unregisterTID(TID)
if err != nil {
// a collision in int64, we should tell someone about this
log.Fatalln(err)
}
m := &IOMMessage{
From: iom.node.Name(),
Type: TYPE_XFER,
Filename: filename,
TID: TID,
Part: part,
}
_, err = iom.node.Set([]string{from}, m)
if err != nil {
return err
}
// wait for a response, or a timeout
select {
case resp := <-c:
if log.WillLog(log.DEBUG) {
log.Debugln("got part: ", resp.Part)
}
if resp.ACK {
if log.WillLog(log.DEBUG) {
log.Debugln("got part from: ", resp.From)
}
// write the part out to disk
iom.transferLock.RLock()
defer iom.transferLock.RUnlock()
if t, ok := iom.transfers[filename]; ok {
outfile := fmt.Sprintf("%v/%v.part_%v", t.Dir, filepath.Base(filename), part)
err := ioutil.WriteFile(outfile, resp.Data, 0664)
if err != nil {
return err
}
} else {
return fmt.Errorf("no transfer temporary directory to write to!")
}
} else {
return fmt.Errorf("received NACK from xfer node")
}
case <-time.After(timeout):
return fmt.Errorf("timeout")
}
return nil
}
示例8: httpClientRequest
func httpClientRequest(h string, client *http.Client) (elapsed uint64) {
httpSiteCache = append(httpSiteCache, h)
if len(httpSiteCache) > MAX_CACHE {
httpSiteCache = httpSiteCache[len(httpSiteCache)-MAX_CACHE:]
}
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
url := httpSiteCache[r.Int31()%int32(len(httpSiteCache))]
log.Debugln("http using url: ", url)
// url notation requires leading and trailing [] on ipv6 addresses
if isIPv6(url) {
url = "[" + url + "]"
}
if !strings.HasPrefix(url, "http://") {
url = "http://" + url
}
start := time.Now().UnixNano()
resp, err := client.Get(url)
if err != nil {
log.Errorln(err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
stop := time.Now().UnixNano()
elapsed = uint64(stop - start)
log.Info("http %v %v %vns", h, url, elapsed)
// make sure to grab any images, javascript, css
extraFiles := parseBody(string(body))
for _, v := range extraFiles {
log.Debugln("grabbing extra file: ", v)
httpGet(url, v, false, client)
}
links := parseLinks(string(body))
if len(links) > 0 {
httpSiteCache = append(httpSiteCache, links...)
if len(httpSiteCache) > MAX_CACHE {
httpSiteCache = httpSiteCache[len(httpSiteCache)-MAX_CACHE:]
}
}
return
}
示例9: broadcastListener
// broadcastListener listens for broadcast connection solicitations and connects to
// soliciting nodes.
func (n *Node) broadcastListener() {
listenAddr := net.UDPAddr{
IP: net.IPv4(0, 0, 0, 0),
Port: n.port,
}
ln, err := net.ListenUDP("udp4", &listenAddr)
if err != nil {
log.Fatal("broadcastListener: %v", err)
}
for {
d := make([]byte, 1024)
read, _, err := ln.ReadFromUDP(d)
if err != nil {
log.Error("broadcastListener ReadFromUDP: %v", err)
continue
}
data := strings.Split(string(d[:read]), ":")
if len(data) != 3 {
log.Warn("got malformed udp data: %v", data)
continue
}
if data[0] != "meshage" {
log.Warn("got malformed udp data: %v", data)
continue
}
namespace := data[1]
host := data[2]
if namespace != n.namespace {
log.Debug("got solicitation from namespace %v, dropping", namespace)
continue
}
if host == n.name {
log.Debugln("got solicitation from myself, dropping")
continue
}
log.Debug("got solicitation from %v", host)
// to avoid spamming the node with connections, only 1/8 of the
// nodes should try to connect. If there are < 16 nodes, then
// always try.
if len(n.clients) > SOLICIT_LIMIT {
s := rand.NewSource(time.Now().UnixNano())
r := rand.New(s)
n := r.Intn(SOLICIT_RATIO)
if n != 0 {
log.Debugln("randomly skipping this solicitation")
continue
}
}
go n.dial(host, true)
}
}
示例10: runCommand
// runCommand runs a command through a JSON pipe.
func runCommand(cmd Command) chan *localResponse {
conn, err := net.Dial("unix", path.Join(*f_minimega, "minimega"))
if err != nil {
log.Errorln(err)
return nil
}
enc := json.NewEncoder(conn)
dec := json.NewDecoder(conn)
log.Debug("encoding command: %v", cmd)
err = enc.Encode(cmd)
if err != nil {
log.Errorln("local command json encode: %v", err)
return nil
}
log.Debugln("encoded command:", cmd)
respChan := make(chan *localResponse)
go func() {
defer close(respChan)
for {
var r localResponse
err = dec.Decode(&r)
if err != nil {
if err == io.EOF {
log.Infoln("server disconnected")
return
}
log.Errorln("local command json decode: %v", err)
return
}
respChan <- &r
if !r.More {
log.Debugln("got last message")
break
} else {
log.Debugln("expecting more data")
}
}
}()
return respChan
}
示例11: findRemoteVM
// findRemoteVM attempts to find the VM ID of a VM by name or ID on a remote
// minimega node. It returns the ID of the VM on the remote host or an error,
// which may also be an error communicating with the remote node.
func findRemoteVM(host, vm string) (int, string, error) {
log.Debug("findRemoteVM: %v %v", host, vm)
// check for our own host
if host == hostname || host == Localhost {
log.Debugln("host is local node")
vm := vms.findVm(vm)
if vm != nil {
log.Debug("got vm: %v %v %v", host, vm.ID, vm.Name)
return vm.ID, vm.Name, nil
}
} else {
log.Debugln("remote host")
var cmdStr string
v, err := strconv.Atoi(vm)
if err == nil {
cmdStr = fmt.Sprintf(".filter id=%v .columns name,id vm info", v)
} else {
cmdStr = fmt.Sprintf(".filter name=%v .columns name,id vm info", v)
}
cmd := minicli.MustCompile(cmdStr)
remoteRespChan := make(chan minicli.Responses)
go func() {
meshageSend(cmd, host, remoteRespChan)
close(remoteRespChan)
}()
for resps := range remoteRespChan {
// Find a response that is not an error
for _, resp := range resps {
if resp.Error == "" && len(resp.Tabular) > 0 {
// Found it!
row := resp.Tabular[0] // should be name,id
name := row[0]
id, err := strconv.Atoi(row[1])
if err != nil {
log.Debug("malformed response: %#v", resp)
} else {
return id, name, nil
}
}
}
}
}
return 0, "", vmNotFound(vm)
}
示例12: Overlays
// Overlays copies any overlay directories indicated in c into the build
// directory build_path. Overlays are copied in depth-first order, so that
// the oldest parent overlay data is copied in first. This allows a child
// to overwrite any overlay data created by a parent.
func Overlays(buildPath string, c vmconfig.Config) error {
// copy the overlays in order
for i, o := range c.Overlays {
log.Infoln("copying overlay:", o)
var sourcePath string
// check if overlay exists as absolute path or relative to cwd
if _, err := os.Stat(o); os.IsNotExist(err) {
// it doesn't, so we'll check relative to config file
log.Debugln("overlay directory '%v' does not exist as an absolute path or relative to the current working directory.", o)
var path string
base := filepath.Base(o) // get base path of overlay directory
if i == len(c.Overlays)-1 { // if this is the last overlay, we'll check relative to c.Path
log.Debugln("non-parent overlay")
path = filepath.Join(filepath.Dir(c.Path), base)
} else { // if not, it's a parent overlay and we'll check relative to c.Parents[i]
log.Debugln("parent overlay")
path = filepath.Join(filepath.Dir(c.Parents[i]), base)
}
log.Debugln("checking path relative to config location: '%v'", path)
if _, err := os.Stat(path); os.IsNotExist(err) { // check if we can find overlay relative to config file
return err // nope
} else { // yep
sourcePath = path
}
} else {
sourcePath = o
}
p := process("cp")
cmd := exec.Command(p, "-r", "-v", sourcePath+"/.", buildPath)
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
log.LogAll(stdout, log.INFO, "cp")
log.LogAll(stderr, log.ERROR, "cp")
err = cmd.Run()
if err != nil {
return err
}
}
return nil
}
示例13: matchCIDR
func matchCIDR(cidr string, ip string) bool {
if !strings.Contains(cidr, "/") {
return false
}
d := strings.Split(cidr, "/")
log.Debugln("subnet ", d)
if len(d) != 2 {
return false
}
if !isIPv4(d[0]) {
return false
}
netmask, err := strconv.Atoi(d[1])
if err != nil {
return false
}
network := toInt32(d[0])
ipmask := toInt32(ip) & ^((1 << uint32(32-netmask)) - 1)
log.Debug("got network %v and ipmask %v", network, ipmask)
if ipmask == network {
return true
}
return false
}
示例14: handleMSA
func (n *Node) handleMSA(m *Message) {
log.Debug("handleMSA: %v", m)
n.meshLock.Lock()
defer n.meshLock.Unlock()
if len(n.network[m.Source]) == len(m.Body.([]string)) {
diff := false
for i, v := range n.network[m.Source] {
if m.Body.([]string)[i] != v {
diff = true
break
}
}
if !diff {
log.Debugln("MSA discarded, client data hasn't changed")
return
}
}
n.network[m.Source] = m.Body.([]string)
if log.WillLog(log.DEBUG) {
log.Debug("new network is: %v", n.network)
}
n.updateNetwork = true
}
示例15: httpClient
func httpClient(protocol string) {
log.Debugln("httpClient")
t := NewEventTicker(*f_mean, *f_stddev, *f_min, *f_max)
transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
Dial: func(network, addr string) (net.Conn, error) {
dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}
return dialer.Dial(protocol, addr)
},
}
client := &http.Client{
Transport: transport,
// TODO: max client read timeouts configurable?
//Timeout: 30 * time.Second,
}
for {
t.Tick()
h, o := randomHost()
log.Debug("http host %v from %v", h, o)
httpClientRequest(h, client)
httpReportChan <- 1
}
}