mirror of
https://github.com/openziti/zrok.git
synced 2025-01-03 04:29:19 +01:00
incorporate metrics.Agent into the controller (#270)
This commit is contained in:
parent
b4d13e15f0
commit
89202873bc
@ -10,8 +10,14 @@ import (
|
|||||||
|
|
||||||
var controllerCmd *controllerCommand
|
var controllerCmd *controllerCommand
|
||||||
|
|
||||||
|
var metricsCmd = &cobra.Command{
|
||||||
|
Use: "metrics",
|
||||||
|
Short: "Metrics related commands",
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
controllerCmd = newControllerCommand()
|
controllerCmd = newControllerCommand()
|
||||||
|
controllerCmd.cmd.AddCommand(metricsCmd)
|
||||||
rootCmd.AddCommand(controllerCmd.cmd)
|
rootCmd.AddCommand(controllerCmd.cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/michaelquigley/cf"
|
|
||||||
"github.com/openziti/zrok/controller/config"
|
|
||||||
"github.com/openziti/zrok/controller/env"
|
|
||||||
"github.com/openziti/zrok/controller/metrics"
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var metricsCmd *cobra.Command
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
metricsCmd = newMetricsCommand().cmd
|
|
||||||
controllerCmd.cmd.AddCommand(metricsCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
type metricsCommand struct {
|
|
||||||
cmd *cobra.Command
|
|
||||||
}
|
|
||||||
|
|
||||||
func newMetricsCommand() *metricsCommand {
|
|
||||||
cmd := &cobra.Command{
|
|
||||||
Use: "metrics <configPath>",
|
|
||||||
Short: "Start a zrok metrics agent",
|
|
||||||
Args: cobra.ExactArgs(1),
|
|
||||||
}
|
|
||||||
command := &metricsCommand{cmd}
|
|
||||||
cmd.Run = command.run
|
|
||||||
return command
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cmd *metricsCommand) run(_ *cobra.Command, args []string) {
|
|
||||||
cfg, err := config.LoadConfig(args[0])
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
logrus.Infof(cf.Dump(cfg, env.GetCfOptions()))
|
|
||||||
|
|
||||||
ma, err := metrics.Run(cfg.Metrics, cfg.Store)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
c := make(chan os.Signal)
|
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
|
||||||
go func() {
|
|
||||||
<-c
|
|
||||||
ma.Stop()
|
|
||||||
ma.Join()
|
|
||||||
os.Exit(0)
|
|
||||||
}()
|
|
||||||
|
|
||||||
for {
|
|
||||||
time.Sleep(30 * time.Minute)
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,6 @@ package config
|
|||||||
import (
|
import (
|
||||||
"github.com/openziti/zrok/controller/env"
|
"github.com/openziti/zrok/controller/env"
|
||||||
"github.com/openziti/zrok/controller/limits"
|
"github.com/openziti/zrok/controller/limits"
|
||||||
"github.com/openziti/zrok/controller/metrics"
|
|
||||||
"github.com/openziti/zrok/controller/metrics2"
|
"github.com/openziti/zrok/controller/metrics2"
|
||||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||||
"time"
|
"time"
|
||||||
@ -23,7 +22,7 @@ type Config struct {
|
|||||||
Email *EmailConfig
|
Email *EmailConfig
|
||||||
Limits *limits.Config
|
Limits *limits.Config
|
||||||
Maintenance *MaintenanceConfig
|
Maintenance *MaintenanceConfig
|
||||||
Metrics *metrics.Config
|
Metrics *metrics2.Config
|
||||||
Registration *RegistrationConfig
|
Registration *RegistrationConfig
|
||||||
ResetPassword *ResetPasswordConfig
|
ResetPassword *ResetPasswordConfig
|
||||||
Store *store.Config
|
Store *store.Config
|
||||||
|
@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/openziti/zrok/controller/config"
|
"github.com/openziti/zrok/controller/config"
|
||||||
|
"github.com/openziti/zrok/controller/metrics2"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/go-openapi/loads"
|
"github.com/go-openapi/loads"
|
||||||
@ -70,6 +71,17 @@ func Run(inCfg *config.Config) error {
|
|||||||
logrus.Warn("skipping influx client; no configuration")
|
logrus.Warn("skipping influx client; no configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cfg.Metrics != nil && cfg.Metrics.Agent != nil && cfg.Metrics.Influx != nil {
|
||||||
|
ma, err := metrics2.NewAgent(cfg.Metrics.Agent, str, cfg.Metrics.Influx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "error creating metrics agent")
|
||||||
|
}
|
||||||
|
if err := ma.Start(); err != nil {
|
||||||
|
return errors.Wrap(err, "error starting metrics agent")
|
||||||
|
}
|
||||||
|
defer func() { ma.Stop() }()
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer func() {
|
defer func() {
|
||||||
cancel()
|
cancel()
|
||||||
|
@ -35,10 +35,15 @@ func (a *Agent) Start() error {
|
|||||||
a.srcJoin = srcJoin
|
a.srcJoin = srcJoin
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
logrus.Info("started")
|
||||||
|
defer logrus.Info("stopped")
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-a.events:
|
case event := <-a.events:
|
||||||
if usage, err := Ingest(event); err == nil {
|
if usage, err := Ingest(event); err == nil {
|
||||||
|
if err := a.cache.addZrokDetail(usage); err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
}
|
||||||
if err := a.snk.Handle(usage); err != nil {
|
if err := a.snk.Handle(usage); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package metrics2
|
package metrics2
|
||||||
|
|
||||||
import "github.com/openziti/zrok/controller/store"
|
import (
|
||||||
|
"github.com/openziti/zrok/controller/store"
|
||||||
|
)
|
||||||
|
|
||||||
type cache struct {
|
type cache struct {
|
||||||
str *store.Store
|
str *store.Store
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
package metrics2
|
package metrics2
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Influx *InfluxConfig
|
||||||
|
Agent *AgentConfig
|
||||||
|
}
|
||||||
|
|
||||||
type AgentConfig struct {
|
type AgentConfig struct {
|
||||||
Source interface{}
|
Source interface{}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user