Add metrics and profile options (#517)
This commit is contained in:
parent
1bc1c45698
commit
79e48ffeff
2 changed files with 29 additions and 2 deletions
|
|
@ -16,6 +16,8 @@ import (
|
|||
type config struct {
|
||||
URI string
|
||||
Log string
|
||||
Metrics bool
|
||||
Profile bool
|
||||
Levels map[string]string
|
||||
Interval time.Duration
|
||||
Mqtt provider.MqttConfig
|
||||
|
|
|
|||
29
cmd/root.go
29
cmd/root.go
|
|
@ -2,6 +2,8 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
_ "net/http/pprof" // pprof handler
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
|
@ -11,8 +13,9 @@ import (
|
|||
"github.com/andig/evcc/server/updater"
|
||||
"github.com/andig/evcc/util"
|
||||
"github.com/andig/evcc/util/pipe"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
|
@ -74,6 +77,20 @@ func init() {
|
|||
"Update interval",
|
||||
)
|
||||
bind(rootCmd, "interval")
|
||||
|
||||
rootCmd.PersistentFlags().Bool(
|
||||
"metrics",
|
||||
false,
|
||||
"Expose metrics",
|
||||
)
|
||||
bind(rootCmd, "metrics")
|
||||
|
||||
rootCmd.PersistentFlags().Bool(
|
||||
"profile",
|
||||
false,
|
||||
"Expose pprof profiles",
|
||||
)
|
||||
bind(rootCmd, "profile")
|
||||
}
|
||||
|
||||
// initConfig reads in config file and ENV variables if set
|
||||
|
|
@ -164,7 +181,15 @@ func run(cmd *cobra.Command, args []string) {
|
|||
httpd := server.NewHTTPd(uri, site, socketHub, cache)
|
||||
|
||||
// metrics
|
||||
httpd.Handle("/metrics", promhttp.Handler())
|
||||
if viper.GetBool("metrics") {
|
||||
httpd.Handle("/metrics", promhttp.Handler())
|
||||
}
|
||||
|
||||
// pprof
|
||||
if viper.GetBool("profile") {
|
||||
router := httpd.Handler.(*mux.Router)
|
||||
router.PathPrefix("/debug/").Handler(http.DefaultServeMux)
|
||||
}
|
||||
|
||||
// start HEMS server
|
||||
if conf.HEMS.Type != "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue