コード例 #1
0
ファイル: gmc.go プロジェクト: wptad/dvara
func main() {
	hostname, _ := os.Hostname()
	client := gmetric.ClientFromFlag("ganglia")
	value := flag.String("value", "", "Value of the metric")
	groups := flag.String("group", "", "Group(s) of the metric (comma-separated)")
	metric := &gmetric.Metric{}
	flag.StringVar(&metric.Name, "name", "", "Name of the metric")
	flag.StringVar(&metric.Title, "title", "", "Title of the metric")
	flag.StringVar(&metric.Host, "host", hostname, "Hostname")
	flag.StringVar((*string)(&metric.ValueType), "type", "", "Either string|int8|uint8|int16|uint16|int32|uint32|float|double")
	flag.StringVar(&metric.Units, "units", "", "Unit of measure for the value e.g. Kilobytes, Celcius")
	flag.StringVar((*string)(&metric.Slope), "slope", "both", "Either zero|positive|negative|both")
	flag.DurationVar(&metric.TickInterval, "tmax", 60*time.Second, "The maximum time between gmetric calls")
	flag.DurationVar(&metric.Lifetime, "dmax", 0, "The lifetime in seconds of this metric")
	flag.StringVar(&metric.Description, "desc", "", "Description of the metric")
	flag.StringVar(&metric.Spoof, "spoof", "", "IP address and name of host/device (colon separated) we are spoofing")
	flag.Parse()

	if metric.Name == "" || metric.ValueType == "" || *value == "" {
		fmt.Fprintln(os.Stderr, "name, type and value are required")
		flag.Usage()
		os.Exit(2)
	}

	if *groups != "" {
		metric.Groups = strings.Split(*groups, ",")
	}

	if err := client.Open(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}

	if err := client.WriteMeta(metric); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}

	if err := client.WriteValue(metric, *value); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}

	if err := client.Close(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(2)
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: wptad/dvara
func main() {
	gmrgroups := []string{"gmrtest"}
	server := &Server{
		ConcurrentRequests: &gangliamr.Counter{
			Name:   "concurrent_requests",
			Title:  "Number of concurrent requests",
			Units:  "requests",
			Groups: gmrgroups,
		},
		NumRequests: &gangliamr.Meter{
			Name:   "num_requests",
			Title:  "Number of requests",
			Units:  "requests",
			Groups: gmrgroups,
		},
		ResponseTime: &gangliamr.Timer{
			Name:   "num_requests",
			Title:  "Response time",
			Groups: gmrgroups,
		},
		PageSize: &gangliamr.Histogram{
			Name:   "page_size",
			Title:  "Page size",
			Units:  "bytes",
			Groups: gmrgroups,
		},
	}

	client := gmetric.ClientFromFlag("ganglia")
	registry := &gangliamr.Registry{
		Prefix:            "gmrtest",
		WriteTickDuration: 20 * time.Second,
		Client:            client,
	}

	addr := flag.String("addr", "0.0.0.0:8077", "server address")
	gomaxprocs := flag.Int("gomaxprocs", runtime.NumCPU(), "gomaxprocs")
	flag.DurationVar(&server.MaxSleep, "max-sleep", time.Second*5, "max sleep")
	flag.IntVar(&server.MaxSentences, "max-sentences", 500, "max sentences")

	flag.Parse()
	runtime.GOMAXPROCS(*gomaxprocs)

	if err := client.Open(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	registry.Register(server.ConcurrentRequests)
	registry.Register(server.NumRequests)
	registry.Register(server.ResponseTime)
	registry.Register(server.PageSize)

	fmt.Printf("Serving on http://%s/\n", *addr)

	if err := http.ListenAndServe(*addr, server); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	if err := client.Close(); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}