Beispiel #1
0
// Start edda, to listen for logging data from services
func Start(name string) {
	// use a waitgroup so whoever starts edda can tell the logs have been flushed
	Wg.Add(1)
	defer Wg.Done()
	if Logchan == nil {
		return
	}
	var msg gotocol.Message
	microservices := make(map[string]bool, archaius.Conf.Dunbar)
	edges := make(map[string]bool, archaius.Conf.Dunbar)
	var ok bool
	hist := collect.NewHist(name)
	log.Println(name + ": starting")
	if archaius.Conf.GraphmlFile != "" {
		graphml.Setup(archaius.Conf.GraphmlFile)
	}
	if archaius.Conf.GraphjsonFile != "" {
		graphjson.Enabled = true
		graphjson.Setup(archaius.Conf.GraphjsonFile)
	}
	for {
		msg, ok = <-Logchan
		collect.Measure(hist, time.Since(msg.Sent))
		if !ok {
			break // channel was closed
		}
		if archaius.Conf.Msglog {
			log.Printf("%v(backlog %v): %v\n", name, len(Logchan), msg)
		}
		switch msg.Imposition {
		case gotocol.Inform:
			edge := names.FilterEdge(msg.Intention)
			if edges[edge] == false { // only log an edge once
				edges[edge] = true
				graphml.WriteEdge(edge)
				graphjson.WriteEdge(edge, msg.Sent)
			}
		case gotocol.Put:
			node := names.FilterNode(msg.Intention)
			if microservices[node] == false { // only log a node once
				microservices[node] = true
				graphml.WriteNode(node + " " + names.Package(msg.Intention))
				graphjson.WriteNode(node+" "+names.Package(msg.Intention), msg.Sent)
			}
		case gotocol.Forget: // forget the edge
			graphjson.WriteForget(msg.Intention, msg.Sent)
		case gotocol.Delete: // remove the node
			if microservices[msg.Intention] == true { // only remove nodes that exist, and only log it once
				microservices[msg.Intention] = false
				graphjson.WriteDone(msg.Intention, msg.Sent)
			}
		}
	}
	log.Println(name + ": closing")
	graphml.Close()
	graphjson.Close()
}
Beispiel #2
0
func main() {
	flag.IntVar(&Population, "p", 100, "Pirate population")
	flag.IntVar(&duration, "d", 10, "Simulation duration in seconds")
	flag.BoolVar(&graphml.Enabled, "g", false, "Enable GraphML logging")
	flag.Parse()
	fmt.Println("Spigo population", Population, "pirates")
	graphml.Setup()
	noodles := make(map[string]chan gotocol.Message, Population)
	for i := 1; i <= Population; i++ {
		name := fmt.Sprintf("Pirate%d", i)
		graphml.Node(name)
		noodles[name] = make(chan gotocol.Message)
		go pirate.Listen(noodles[name])
	}
	fsm.ChatSleep = time.Duration(duration) * time.Second
	fsm.Touch(noodles)
	graphml.Close()
}