storj/pkg/process/metrics.go
JT Olio 22b1fe4e21 pkg/process: add pkg/telemetry plumbing (#47)
* pkg/process: add pkg/telemetry plumbing

* pkg/process: add debug endpoints

* fix linting
2018-05-30 10:03:44 -04:00

48 lines
1.2 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package process
import (
"context"
"flag"
"os"
"path/filepath"
"github.com/zeebo/admission/admproto"
"gopkg.in/spacemonkeygo/monkit.v2"
"gopkg.in/spacemonkeygo/monkit.v2/environment"
"storj.io/storj/pkg/telemetry"
)
var (
metricInterval = flag.Duration("metrics.interval", telemetry.DefaultInterval,
"how frequently to send up telemetry")
metricCollector = flag.String("metrics.addr", "collector.storj.io:9000",
"address to send telemetry to")
metricApp = flag.String("metrics.app", filepath.Base(os.Args[0]),
"application name for telemetry identification")
metricAppSuffix = flag.String("metrics.app_suffix", "-dev",
"application suffix")
)
func initMetrics(ctx context.Context, r *monkit.Registry, instanceID string) (
err error) {
if *metricCollector == "" || *metricInterval == 0 {
return Error.New("telemetry disabled")
}
c, err := telemetry.NewClient(*metricCollector, telemetry.ClientOpts{
Interval: *metricInterval,
Application: *metricApp + *metricAppSuffix,
Instance: instanceID,
Registry: r,
FloatEncoding: admproto.Float32Encoding,
})
if err != nil {
return err
}
environment.Register(r)
go c.Run(ctx)
return nil
}