cmd/metric-receiver: restore minimal metrics server
Change-Id: I33ac9d7ccf21f41ef3077c64506df63607ed6b15
This commit is contained in:
parent
02cbf1e72a
commit
20a50f0906
49
cmd/metric-receiver/main.go
Normal file
49
cmd/metric-receiver/main.go
Normal file
@ -0,0 +1,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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user