mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
build: internal metrics for packaging.
This commit is contained in:
parent
81a5b90022
commit
2e8c4699b0
@ -1,7 +1,7 @@
|
|||||||
[run]
|
[run]
|
||||||
init_cmds = [
|
init_cmds = [
|
||||||
["go", "run", "build.go", "-dev", "build-server"],
|
["go", "run", "build.go", "-dev", "build-server"],
|
||||||
["./bin/grafana-server", "cfg:app_mode=development"]
|
["./bin/grafana-server", "-packaging=dev", "cfg:app_mode=development"]
|
||||||
]
|
]
|
||||||
watch_all = true
|
watch_all = true
|
||||||
follow_symlinks = true
|
follow_symlinks = true
|
||||||
@ -14,5 +14,5 @@ watch_exts = [".go", ".ini", ".toml", ".template.html"]
|
|||||||
build_delay = 1500
|
build_delay = 1500
|
||||||
cmds = [
|
cmds = [
|
||||||
["go", "run", "build.go", "-dev", "build-server"],
|
["go", "run", "build.go", "-dev", "build-server"],
|
||||||
["./bin/grafana-server", "cfg:app_mode=development"]
|
["./bin/grafana-server", "-packaging=dev", "cfg:app_mode=development"]
|
||||||
]
|
]
|
||||||
|
2
Makefile
2
Makefile
@ -25,7 +25,7 @@ build: build-go build-js
|
|||||||
|
|
||||||
build-docker-dev:
|
build-docker-dev:
|
||||||
@echo "\033[92mInfo:\033[0m the frontend code is expected to be built already."
|
@echo "\033[92mInfo:\033[0m the frontend code is expected to be built already."
|
||||||
go run build.go -goos linux -pkg-arch amd64 ${OPT} build package-only latest
|
go run build.go -goos linux -pkg-arch amd64 ${OPT} build pkg-archive latest
|
||||||
cp dist/grafana-latest.linux-x64.tar.gz packaging/docker
|
cp dist/grafana-latest.linux-x64.tar.gz packaging/docker
|
||||||
cd packaging/docker && docker build --tag grafana/grafana:dev .
|
cd packaging/docker && docker build --tag grafana/grafana:dev .
|
||||||
|
|
||||||
|
2
build.go
2
build.go
@ -128,6 +128,8 @@ func main() {
|
|||||||
if goos == linux {
|
if goos == linux {
|
||||||
createLinuxPackages()
|
createLinuxPackages()
|
||||||
}
|
}
|
||||||
|
case "pkg-archive":
|
||||||
|
grunt(gruntBuildArg("package")...)
|
||||||
|
|
||||||
case "pkg-rpm":
|
case "pkg-rpm":
|
||||||
grunt(gruntBuildArg("release")...)
|
grunt(gruntBuildArg("release")...)
|
||||||
|
@ -56,7 +56,7 @@ if [ -f "$DEFAULT" ]; then
|
|||||||
. "$DEFAULT"
|
. "$DEFAULT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"
|
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} --packaging=deb cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"
|
||||||
|
|
||||||
function checkUser() {
|
function checkUser() {
|
||||||
if [ `id -u` -ne 0 ]; then
|
if [ `id -u` -ne 0 ]; then
|
||||||
|
@ -17,6 +17,7 @@ RuntimeDirectoryMode=0750
|
|||||||
ExecStart=/usr/sbin/grafana-server \
|
ExecStart=/usr/sbin/grafana-server \
|
||||||
--config=${CONF_FILE} \
|
--config=${CONF_FILE} \
|
||||||
--pidfile=${PID_FILE_DIR}/grafana-server.pid \
|
--pidfile=${PID_FILE_DIR}/grafana-server.pid \
|
||||||
|
--packaging=deb \
|
||||||
cfg:default.paths.logs=${LOG_DIR} \
|
cfg:default.paths.logs=${LOG_DIR} \
|
||||||
cfg:default.paths.data=${DATA_DIR} \
|
cfg:default.paths.data=${DATA_DIR} \
|
||||||
cfg:default.paths.plugins=${PLUGINS_DIR} \
|
cfg:default.paths.plugins=${PLUGINS_DIR} \
|
||||||
|
@ -80,6 +80,7 @@ fi
|
|||||||
exec grafana-server \
|
exec grafana-server \
|
||||||
--homepath="$GF_PATHS_HOME" \
|
--homepath="$GF_PATHS_HOME" \
|
||||||
--config="$GF_PATHS_CONFIG" \
|
--config="$GF_PATHS_CONFIG" \
|
||||||
|
--packaging docker \
|
||||||
"$@" \
|
"$@" \
|
||||||
cfg:default.log.mode="console" \
|
cfg:default.log.mode="console" \
|
||||||
cfg:default.paths.data="$GF_PATHS_DATA" \
|
cfg:default.paths.data="$GF_PATHS_DATA" \
|
||||||
|
@ -60,7 +60,7 @@ fi
|
|||||||
# overwrite settings from default file
|
# overwrite settings from default file
|
||||||
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
[ -e /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
|
||||||
|
|
||||||
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"
|
DAEMON_OPTS="--pidfile=${PID_FILE} --config=${CONF_FILE} --packaging=rpm cfg:default.paths.provisioning=$PROVISIONING_CFG_DIR cfg:default.paths.data=${DATA_DIR} cfg:default.paths.logs=${LOG_DIR} cfg:default.paths.plugins=${PLUGINS_DIR}"
|
||||||
|
|
||||||
function isRunning() {
|
function isRunning() {
|
||||||
status -p $PID_FILE $NAME > /dev/null 2>&1
|
status -p $PID_FILE $NAME > /dev/null 2>&1
|
||||||
|
@ -17,6 +17,7 @@ RuntimeDirectoryMode=0750
|
|||||||
ExecStart=/usr/sbin/grafana-server \
|
ExecStart=/usr/sbin/grafana-server \
|
||||||
--config=${CONF_FILE} \
|
--config=${CONF_FILE} \
|
||||||
--pidfile=${PID_FILE_DIR}/grafana-server.pid \
|
--pidfile=${PID_FILE_DIR}/grafana-server.pid \
|
||||||
|
--packaging=rpm \
|
||||||
cfg:default.paths.logs=${LOG_DIR} \
|
cfg:default.paths.logs=${LOG_DIR} \
|
||||||
cfg:default.paths.data=${DATA_DIR} \
|
cfg:default.paths.data=${DATA_DIR} \
|
||||||
cfg:default.paths.plugins=${PLUGINS_DIR} \
|
cfg:default.paths.plugins=${PLUGINS_DIR} \
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
extensions "github.com/grafana/grafana/pkg/extensions"
|
"github.com/grafana/grafana/pkg/extensions"
|
||||||
"github.com/grafana/grafana/pkg/log"
|
"github.com/grafana/grafana/pkg/log"
|
||||||
"github.com/grafana/grafana/pkg/metrics"
|
"github.com/grafana/grafana/pkg/metrics"
|
||||||
_ "github.com/grafana/grafana/pkg/services/alerting/conditions"
|
_ "github.com/grafana/grafana/pkg/services/alerting/conditions"
|
||||||
@ -39,6 +39,7 @@ var buildstamp string
|
|||||||
var configFile = flag.String("config", "", "path to config file")
|
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 homePath = flag.String("homepath", "", "path to grafana install/home path, defaults to working directory")
|
||||||
var pidFile = flag.String("pidfile", "", "path to pid file")
|
var pidFile = flag.String("pidfile", "", "path to pid file")
|
||||||
|
var packaging = flag.String("packaging", "unknown", "describes the way Grafana was installed")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
v := flag.Bool("v", false, "prints current version and exits")
|
v := flag.Bool("v", false, "prints current version and exits")
|
||||||
@ -79,6 +80,7 @@ func main() {
|
|||||||
setting.BuildStamp = buildstampInt64
|
setting.BuildStamp = buildstampInt64
|
||||||
setting.BuildBranch = buildBranch
|
setting.BuildBranch = buildBranch
|
||||||
setting.IsEnterprise = extensions.IsEnterprise
|
setting.IsEnterprise = extensions.IsEnterprise
|
||||||
|
setting.Packaging = validPackaging(*packaging)
|
||||||
|
|
||||||
metrics.SetBuildInformation(version, commit, buildBranch)
|
metrics.SetBuildInformation(version, commit, buildBranch)
|
||||||
|
|
||||||
@ -95,6 +97,16 @@ func main() {
|
|||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validPackaging(packaging string) string {
|
||||||
|
validTypes := []string{"dev", "deb", "rpm", "docker", "brew", "hosted", "unknown"}
|
||||||
|
for _, vt := range validTypes {
|
||||||
|
if packaging == vt {
|
||||||
|
return packaging
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
func listenToSystemSignals(server *GrafanaServerImpl) {
|
func listenToSystemSignals(server *GrafanaServerImpl) {
|
||||||
signalChan := make(chan os.Signal, 1)
|
signalChan := make(chan os.Signal, 1)
|
||||||
sighupChan := make(chan os.Signal, 1)
|
sighupChan := make(chan os.Signal, 1)
|
||||||
|
@ -313,7 +313,7 @@ func init() {
|
|||||||
|
|
||||||
// SetBuildInformation sets the build information for this binary
|
// SetBuildInformation sets the build information for this binary
|
||||||
func SetBuildInformation(version, revision, branch string) {
|
func SetBuildInformation(version, revision, branch string) {
|
||||||
// We export this info twice for backwards compability.
|
// We export this info twice for backwards compatibility.
|
||||||
// Once this have been released for some time we should be able to remote `M_Grafana_Version`
|
// Once this have been released for some time we should be able to remote `M_Grafana_Version`
|
||||||
// The reason we added a new one is that its common practice in the prometheus community
|
// The reason we added a new one is that its common practice in the prometheus community
|
||||||
// to name this metric `*_build_info` so its easy to do aggregation on all programs.
|
// to name this metric `*_build_info` so its easy to do aggregation on all programs.
|
||||||
@ -402,6 +402,7 @@ func sendUsageStats(oauthProviders map[string]bool) {
|
|||||||
"os": runtime.GOOS,
|
"os": runtime.GOOS,
|
||||||
"arch": runtime.GOARCH,
|
"arch": runtime.GOARCH,
|
||||||
"edition": getEdition(),
|
"edition": getEdition(),
|
||||||
|
"packaging": setting.Packaging,
|
||||||
}
|
}
|
||||||
|
|
||||||
statsQuery := models.GetSystemStatsQuery{}
|
statsQuery := models.GetSystemStatsQuery{}
|
||||||
@ -447,6 +448,8 @@ func sendUsageStats(oauthProviders map[string]bool) {
|
|||||||
}
|
}
|
||||||
metrics["stats.ds.other.count"] = dsOtherCount
|
metrics["stats.ds.other.count"] = dsOtherCount
|
||||||
|
|
||||||
|
metrics["stats.packaging."+setting.Packaging+".count"] = 1
|
||||||
|
|
||||||
dsAccessStats := models.GetDataSourceAccessStatsQuery{}
|
dsAccessStats := models.GetDataSourceAccessStatsQuery{}
|
||||||
if err := bus.Dispatch(&dsAccessStats); err != nil {
|
if err := bus.Dispatch(&dsAccessStats); err != nil {
|
||||||
metricsLogger.Error("Failed to get datasource access stats", "error", err)
|
metricsLogger.Error("Failed to get datasource access stats", "error", err)
|
||||||
|
@ -176,6 +176,7 @@ func TestMetrics(t *testing.T) {
|
|||||||
setting.BasicAuthEnabled = true
|
setting.BasicAuthEnabled = true
|
||||||
setting.LdapEnabled = true
|
setting.LdapEnabled = true
|
||||||
setting.AuthProxyEnabled = true
|
setting.AuthProxyEnabled = true
|
||||||
|
setting.Packaging = "deb"
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
sendUsageStats(oauthProviders)
|
sendUsageStats(oauthProviders)
|
||||||
@ -243,6 +244,8 @@ func TestMetrics(t *testing.T) {
|
|||||||
So(metrics.Get("stats.auth_enabled.oauth_google.count").MustInt(), ShouldEqual, 1)
|
So(metrics.Get("stats.auth_enabled.oauth_google.count").MustInt(), ShouldEqual, 1)
|
||||||
So(metrics.Get("stats.auth_enabled.oauth_generic_oauth.count").MustInt(), ShouldEqual, 1)
|
So(metrics.Get("stats.auth_enabled.oauth_generic_oauth.count").MustInt(), ShouldEqual, 1)
|
||||||
So(metrics.Get("stats.auth_enabled.oauth_grafana_com.count").MustInt(), ShouldEqual, 1)
|
So(metrics.Get("stats.auth_enabled.oauth_grafana_com.count").MustInt(), ShouldEqual, 1)
|
||||||
|
|
||||||
|
So(metrics.Get("stats.packaging.deb.count").MustInt(), ShouldEqual, 1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -57,6 +57,9 @@ var (
|
|||||||
IsEnterprise bool
|
IsEnterprise bool
|
||||||
ApplicationName string
|
ApplicationName string
|
||||||
|
|
||||||
|
// packaging
|
||||||
|
Packaging = "unknown"
|
||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
HomePath string
|
HomePath string
|
||||||
PluginsPath string
|
PluginsPath string
|
||||||
|
Loading…
Reference in New Issue
Block a user