2019-01-21 17:43:05 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/kit/cli"
|
|
|
|
influxlogger "github.com/influxdata/influxdb/logger"
|
2019-01-22 04:02:24 +00:00
|
|
|
"github.com/influxdata/influxdb/prometheus"
|
2019-01-21 17:43:05 +00:00
|
|
|
"github.com/influxdata/influxdb/telemetry"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-12-04 23:10:23 +00:00
|
|
|
log = influxlogger.New(os.Stdout)
|
|
|
|
addr string
|
2019-01-21 17:43:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
prog := &cli.Program{
|
|
|
|
Run: run,
|
|
|
|
Name: "telemetryd",
|
|
|
|
Opts: []cli.Opt{
|
|
|
|
{
|
|
|
|
DestP: &addr,
|
|
|
|
Flag: "bind-addr",
|
|
|
|
Default: ":8080",
|
|
|
|
Desc: "binding address for telemetry server",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
cmd := cli.NewCommand(prog)
|
|
|
|
|
|
|
|
var exitCode int
|
|
|
|
if err := cmd.Execute(); err != nil {
|
|
|
|
exitCode = 1
|
2019-12-04 23:10:23 +00:00
|
|
|
log.Error("Command returned error", zap.Error(err))
|
2019-01-21 17:43:05 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 23:10:23 +00:00
|
|
|
if err := log.Sync(); err != nil {
|
2019-01-21 17:43:05 +00:00
|
|
|
exitCode = 1
|
|
|
|
fmt.Fprintf(os.Stderr, "Error syncing logs: %v\n", err)
|
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
os.Exit(exitCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func run() error {
|
2019-12-04 23:10:23 +00:00
|
|
|
log := log.With(zap.String("service", "telemetryd"))
|
|
|
|
store := telemetry.NewLogStore(log)
|
|
|
|
svc := telemetry.NewPushGateway(log, store)
|
2019-01-22 04:02:24 +00:00
|
|
|
// Print data as line protocol
|
|
|
|
svc.Encoder = &prometheus.LineProtocol{}
|
|
|
|
|
2019-01-21 17:43:05 +00:00
|
|
|
handler := http.HandlerFunc(svc.Handler)
|
2019-12-04 23:10:23 +00:00
|
|
|
log.Info("Starting telemetryd server", zap.String("addr", addr))
|
2019-01-21 17:43:05 +00:00
|
|
|
|
|
|
|
srv := http.Server{
|
|
|
|
Addr: addr,
|
|
|
|
Handler: handler,
|
2019-12-04 23:10:23 +00:00
|
|
|
ErrorLog: zap.NewStdLog(log),
|
2019-01-21 17:43:05 +00:00
|
|
|
}
|
|
|
|
return srv.ListenAndServe()
|
|
|
|
}
|