예제 #1
0
func main() {
	connection := noaa.NewConsumer(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
	connection.SetDebugPrinter(ConsoleDebugPrinter{})

	messages, err := connection.RecentLogs(appGuid, authToken)

	if err != nil {
		fmt.Printf("===== Error getting recent messages: %v\n", err)
	} else {
		fmt.Println("===== Recent logs")
		for _, msg := range messages {
			fmt.Println(msg)
		}
	}

	fmt.Println("===== Streaming metrics")
	msgChan := make(chan *events.Envelope)
	go func() {
		defer close(msgChan)
		errorChan := make(chan error)
		go connection.Stream(appGuid, authToken, msgChan, errorChan)

		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	for msg := range msgChan {
		fmt.Printf("%v \n", msg)
	}
}
예제 #2
0
func main() {
	var messages map[string][]metricCategory // [origin]{metricCategory To []names}]
	messages = make(map[string][]metricCategory)
	connection := noaa.NewConsumer(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
	connection.SetDebugPrinter(ConsoleDebugPrinter{})

	fmt.Println("===== Streaming Firehose (will only succeed if you have admin credentials)")

	msgChan := make(chan *events.Envelope)
	go func() {
		defer close(msgChan)
		errorChan := make(chan error)
		go connection.Firehose(firehoseSubscriptionId, authToken, msgChan, errorChan)

		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	go startHttp(messages)

	for msg := range msgChan {
		vm := msg.GetValueMetric()
		if vm == nil {
			continue
		}
		origin := msg.GetOrigin()

		category, subCategory := parseMetric(*vm.Name)

		index := indexOf(messages[origin], category)
		if index >= 0 {
			metricCategoryGroup := messages[origin][index]
			switch f := metricCategoryGroup.(type) {
			case *metricCategoryWithSubCategory:
				if len(subCategory) > 0 {
					if contains(f.SubCategory, subCategory) == false {
						f.SubCategory = append(f.SubCategory, subCategory)
					}
				}
			default:
			}
		} else {
			if len(subCategory) > 0 {
				messages[origin] = append(messages[origin], &metricCategoryWithSubCategory{
					Category:    category,
					SubCategory: []string{subCategory},
				})
			} else {
				messages[origin] = append(messages[origin], &metricCategoryOnly{
					Category: category,
				})
			}
		}
	}
}
예제 #3
0
func main() {
	connection := noaa.NewConsumer(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
	connection.SetDebugPrinter(ConsoleDebugPrinter{})

	fmt.Println("===== Streaming Firehose (will only succeed if you have admin credentials)")

	msgChan := make(chan *events.Envelope)
	go func() {
		defer close(msgChan)
		errorChan := make(chan error)
		go connection.Firehose(firehoseSubscriptionId, authToken, msgChan, errorChan)

		for err := range errorChan {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}
	}()

	for msg := range msgChan {
		fmt.Printf("%v \n", msg)
	}
}
예제 #4
0
func main() {
	connection := noaa.NewConsumer(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
	connection.SetDebugPrinter(ConsoleDebugPrinter{})

	fmt.Println("===== Streaming ContainerMetrics (will only succeed if you have admin credentials)")

	for {
		containerMetrics, err := connection.ContainerMetrics(appId, authToken)

		for _, cm := range containerMetrics {
			fmt.Printf("%v \n", cm)
		}

		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
		}

		time.Sleep(3 * time.Second)
	}

}