mirror of
https://github.com/openziti/zrok.git
synced 2024-12-24 07:39:08 +01:00
more metrics infrastructure (#128)
This commit is contained in:
parent
56606d9b01
commit
d5fb9270b6
39
cmd/zrok/metrics.go
Normal file
39
cmd/zrok/metrics.go
Normal file
@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/cf"
|
||||
"github.com/openziti/zrok/controller/metrics"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(newMetricsCommand().cmd)
|
||||
}
|
||||
|
||||
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 := metrics.LoadConfig(args[0])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logrus.Infof(cf.Dump(cfg, metrics.GetCfOptions()))
|
||||
|
||||
if err := metrics.Run(cfg); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -1,5 +1,18 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/michaelquigley/cf"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Source interface{}
|
||||
}
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
cfg := &Config{}
|
||||
if err := cf.BindYaml(cfg, path, GetCfOptions()); err != nil {
|
||||
return nil, errors.Wrapf(err, "error loading config from '%v'", path)
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
@ -1,17 +1,42 @@
|
||||
package metrics
|
||||
|
||||
import "github.com/michaelquigley/cf"
|
||||
import (
|
||||
"github.com/michaelquigley/cf"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type FileSourceConfig struct {
|
||||
Path string
|
||||
}
|
||||
|
||||
func loadFileSourceConfig(v interface{}, opts *cf.Options) (interface{}, error) {
|
||||
return nil, nil
|
||||
if submap, ok := v.(map[string]interface{}); ok {
|
||||
cfg := &FileSourceConfig{}
|
||||
if err := cf.Bind(cfg, submap, cf.DefaultOptions()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fileSource{cfg}, nil
|
||||
}
|
||||
return nil, errors.New("invalid config structure for 'file' source")
|
||||
}
|
||||
|
||||
type fileSource struct{}
|
||||
type fileSource struct {
|
||||
cfg *FileSourceConfig
|
||||
}
|
||||
|
||||
func (s *fileSource) Start() (chan struct{}, error) {
|
||||
return nil, nil
|
||||
f, err := os.Open(s.cfg.Path)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error opening '%v'", s.cfg.Path)
|
||||
}
|
||||
ch := make(chan struct{})
|
||||
go func() {
|
||||
f.Close()
|
||||
close(ch)
|
||||
}()
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
func (s *fileSource) Stop() {
|
||||
}
|
||||
|
4
etc/metrics.yml
Normal file
4
etc/metrics.yml
Normal file
@ -0,0 +1,4 @@
|
||||
source:
|
||||
type: file
|
||||
path: /tmp/fabric-usage.log
|
||||
|
Loading…
Reference in New Issue
Block a user