kube-router/kube-router.go
Joakim Karlsson f3e7aced1a Metrics + Logging update (#294)
* - added protocol & port label to metrics
- removed some redundant code

* added example dashboard

* added dashboard screenshot

* updated dashboard json & screenshot

* ammend bad dashboard export

* first new metric

* .

* more metrics: controller_publish_metrics_time & controller_iptables_sync_time

* namespace redeclared

* fix typo in name

* smal fixes

* new metric controller_bgp_peers & controller_bgp_internal_peers_sync_time

* typo fix

* new metric controller_ipvs_service_sync_time

* fix

* register metric

* fix

* fix

* added more metrics

* service controller log levels

* fix

* fix

* added metrics controller

* fixes

* fix

* fix

* fixed more log levels

* server and graceful shutdown

* fix

* fix

* fix

* code cleanup

* docs

* move metrics exporting to controller

* fix

* fix

* fixes

* fix

* fix missing

* fix

* fix

* test

* test

* fix

* fix

* fix

* updated dashboard

* updates to metric controller

* fixed order in newmetricscontroller

* err declared and not used

* updated dashboard

* updated dashboard screenshot

* removed --metrics & changed --metrics-port to enable / disable metrics

* https://github.com/cloudnativelabs/kube-router/issues/271

* cannot use config.MetricsPort (type uint16) as type int in assignment

* cannot use mc.MetricsPort (type uint16) as type int in argument to strconv.Itoa

* updated docs

* changed default metric port to 0, disabled

* added missing newline to .dockerignore

* add lag parse to pickup on -v directives

* test

* test

* test

* fix regression

* syntax error: non-declaration statement outside function body

* fix

* changed nsc to mc

* updated docs

* markdown fix

* moved metrics registration out to respective controller so only metrics for running parts will be exposed

* removed junk that came from visual studio code

* fixed some typos

* Moved the metrics back into each controller and added expose behaviour so only the running components metrics would be published

* removed to much, added back instanciation of metricscontroller

* fixed some invalid  variable names

* fixed last typos on config name

* fixed order in newnetworkservicecontroller

* updated metrics docs & removed the metrics sync period as it will obey the controllers sync period

* forgott to save options.go

* cleanup

* Updated metric name & docs

* updated metrics.md

* fixed a high cpu usage bug in the metrics_controller's wait loop
2018-01-25 22:56:51 +05:30

62 lines
1.2 KiB
Go

package main
import (
"flag"
"fmt"
"net/http"
"os"
_ "net/http/pprof"
"github.com/cloudnativelabs/kube-router/app"
"github.com/cloudnativelabs/kube-router/app/options"
"github.com/spf13/pflag"
)
func main() {
config := options.NewKubeRouterConfig()
config.AddFlags(pflag.CommandLine)
pflag.Parse()
// Workaround for this issue:
// https://github.com/kubernetes/kubernetes/issues/17162
flag.CommandLine.Parse([]string{})
flag.Set("logtostderr", "true")
flag.Set("v", config.VLevel)
if config.HelpRequested {
pflag.Usage()
os.Exit(0)
}
if os.Geteuid() != 0 {
fmt.Fprintf(os.Stderr, "kube-router needs to be run with privileges to execute iptables, ipset and configure ipvs\n")
os.Exit(1)
}
if config.CleanupConfig {
app.CleanupConfigAndExit()
os.Exit(0)
}
kubeRouter, err := app.NewKubeRouterDefault(config)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to parse kube-router config: %v\n", err)
os.Exit(1)
}
if config.EnablePprof {
go func() {
fmt.Fprintf(os.Stdout, http.ListenAndServe("0.0.0.0:6060", nil).Error())
}()
}
err = kubeRouter.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to run kube-router: %v\n", err)
os.Exit(1)
}
}