mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 17:12:41 +08:00

* Add new build info metrics that contains more info The goal was to add more information about Grafana. But rather than just adding those to the current metrics I created a new metric since its a common pattern in the prometheus community to expose that info in a metric named `*_build_info`. We keep the old metric to avoid introducing any breaking changes but we should be able to remove it the next breaking change
114 lines
2.8 KiB
Go
114 lines
2.8 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
_ "net/http/pprof"
|
|
"os"
|
|
"os/signal"
|
|
"runtime"
|
|
"runtime/trace"
|
|
"strconv"
|
|
"syscall"
|
|
"time"
|
|
|
|
extensions "github.com/grafana/grafana/pkg/extensions"
|
|
"github.com/grafana/grafana/pkg/log"
|
|
"github.com/grafana/grafana/pkg/metrics"
|
|
_ "github.com/grafana/grafana/pkg/services/alerting/conditions"
|
|
_ "github.com/grafana/grafana/pkg/services/alerting/notifiers"
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/cloudwatch"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/elasticsearch"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/graphite"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/influxdb"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/mysql"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/opentsdb"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/postgres"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/prometheus"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/stackdriver"
|
|
_ "github.com/grafana/grafana/pkg/tsdb/testdata"
|
|
)
|
|
|
|
var version = "5.0.0"
|
|
var commit = "NA"
|
|
var buildBranch = "master"
|
|
var buildstamp string
|
|
|
|
var configFile = flag.String("config", "", "path to config file")
|
|
var homePath = flag.String("homepath", "", "path to grafana install/home path, defaults to working directory")
|
|
var pidFile = flag.String("pidfile", "", "path to pid file")
|
|
|
|
func main() {
|
|
v := flag.Bool("v", false, "prints current version and exits")
|
|
profile := flag.Bool("profile", false, "Turn on pprof profiling")
|
|
profilePort := flag.Int("profile-port", 6060, "Define custom port for profiling")
|
|
flag.Parse()
|
|
if *v {
|
|
fmt.Printf("Version %s (commit: %s, branch: %s)\n", version, commit, buildBranch)
|
|
os.Exit(0)
|
|
}
|
|
|
|
if *profile {
|
|
runtime.SetBlockProfileRate(1)
|
|
go func() {
|
|
http.ListenAndServe(fmt.Sprintf("localhost:%d", *profilePort), nil)
|
|
}()
|
|
|
|
f, err := os.Create("trace.out")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer f.Close()
|
|
|
|
err = trace.Start(f)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer trace.Stop()
|
|
}
|
|
|
|
buildstampInt64, _ := strconv.ParseInt(buildstamp, 10, 64)
|
|
if buildstampInt64 == 0 {
|
|
buildstampInt64 = time.Now().Unix()
|
|
}
|
|
|
|
setting.BuildVersion = version
|
|
setting.BuildCommit = commit
|
|
setting.BuildStamp = buildstampInt64
|
|
setting.BuildBranch = buildBranch
|
|
setting.IsEnterprise = extensions.IsEnterprise
|
|
|
|
metrics.SetBuildInformation(version, commit, buildBranch)
|
|
|
|
server := NewGrafanaServer()
|
|
|
|
go listenToSystemSignals(server)
|
|
|
|
err := server.Run()
|
|
|
|
code := server.Exit(err)
|
|
trace.Stop()
|
|
log.Close()
|
|
|
|
os.Exit(code)
|
|
}
|
|
|
|
func listenToSystemSignals(server *GrafanaServerImpl) {
|
|
signalChan := make(chan os.Signal, 1)
|
|
sighupChan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sighupChan, syscall.SIGHUP)
|
|
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
|
|
|
|
for {
|
|
select {
|
|
case <-sighupChan:
|
|
log.Reload()
|
|
case sig := <-signalChan:
|
|
server.Shutdown(fmt.Sprintf("System signal: %s", sig))
|
|
}
|
|
}
|
|
}
|