-
Notifications
You must be signed in to change notification settings - Fork 402
/
main.go
49 lines (39 loc) · 920 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"flag"
"fmt"
"github.com/spf13/cobra"
"storj.io/common/telemetry"
"storj.io/private/process"
)
var (
addr = flag.String("addr", ":9000", "address to listen for metrics on")
)
func main() {
process.Exec(&cobra.Command{
Use: "metric-receiver",
Short: "receive metrics",
RunE: run,
})
}
func run(cmd *cobra.Command, args []string) (err error) {
ctx, _ := process.Ctx(cmd)
s, err := telemetry.Listen(*addr)
if err != nil {
return err
}
defer printError(s.Close)
fmt.Printf("listening on %s\n", s.Addr())
return s.Serve(ctx, telemetry.HandlerFunc(handle))
}
func handle(application, instance string, key []byte, val float64) {
fmt.Printf("%s %s %s %v\n", application, instance, string(key), val)
}
func printError(fn func() error) {
err := fn()
if err != nil {
fmt.Println(err)
}
}