Merge branch 'master' into alerting
Conflicts: conf/sample.ini
This commit is contained in:
@@ -8,39 +8,11 @@ import (
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
||||
)
|
||||
|
||||
var version = "master"
|
||||
|
||||
func getGrafanaPluginDir() string {
|
||||
currentOS := runtime.GOOS
|
||||
defaultNix := "/var/lib/grafana/plugins"
|
||||
|
||||
if currentOS == "windows" {
|
||||
return "../data/plugins"
|
||||
}
|
||||
|
||||
pwd, err := os.Getwd()
|
||||
|
||||
if err != nil {
|
||||
logger.Error("Could not get current path. using default")
|
||||
return defaultNix
|
||||
}
|
||||
|
||||
if isDevenvironment(pwd) {
|
||||
return "../data/plugins"
|
||||
}
|
||||
|
||||
return defaultNix
|
||||
}
|
||||
|
||||
func isDevenvironment(pwd string) bool {
|
||||
// if ../conf/defaults.ini exists, grafana is not installed as package
|
||||
// that its in development environment.
|
||||
_, err := os.Stat("../conf/defaults.ini")
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
setupLogging()
|
||||
|
||||
@@ -54,7 +26,7 @@ func main() {
|
||||
cli.StringFlag{
|
||||
Name: "pluginsDir",
|
||||
Usage: "path to the grafana plugin directory",
|
||||
Value: getGrafanaPluginDir(),
|
||||
Value: utils.GetGrafanaPluginDir(runtime.GOOS),
|
||||
EnvVar: "GF_PLUGIN_DIR",
|
||||
},
|
||||
cli.StringFlag{
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
||||
)
|
||||
|
||||
func GetGrafanaPluginDir(currentOS string) string {
|
||||
//currentOS := runtime.GOOS
|
||||
|
||||
if currentOS == "windows" {
|
||||
return returnOsDefault(currentOS)
|
||||
}
|
||||
|
||||
pwd, err := os.Getwd()
|
||||
|
||||
if err != nil {
|
||||
logger.Error("Could not get current path. using default")
|
||||
return returnOsDefault(currentOS)
|
||||
}
|
||||
|
||||
if isDevenvironment(pwd) {
|
||||
return "../data/plugins"
|
||||
}
|
||||
|
||||
return returnOsDefault(currentOS)
|
||||
}
|
||||
|
||||
func isDevenvironment(pwd string) bool {
|
||||
// if ../conf/defaults.ini exists, grafana is not installed as package
|
||||
// that its in development environment.
|
||||
_, err := os.Stat("../conf/defaults.ini")
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func returnOsDefault(currentOs string) string {
|
||||
switch currentOs {
|
||||
case "windows":
|
||||
return "../data/plugins"
|
||||
case "darwin":
|
||||
return "/usr/local/var/lib/grafana/plugins"
|
||||
default: //"linux"
|
||||
return "/var/lib/grafana/plugins"
|
||||
}
|
||||
}
|
||||
@@ -24,20 +24,25 @@ func CreateGraphitePublisher() (*GraphitePublisher, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
address := graphiteSection.Key("address").String()
|
||||
if address == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
publisher := &GraphitePublisher{}
|
||||
publisher.prevCounts = make(map[string]int64)
|
||||
publisher.protocol = "tcp"
|
||||
publisher.address = graphiteSection.Key("address").MustString("localhost:2003")
|
||||
publisher.prefix = graphiteSection.Key("prefix").MustString("prod.grafana.%(instance_name)s")
|
||||
publisher.address = address
|
||||
|
||||
safeInstanceName := strings.Replace(setting.InstanceName, ".", "_", -1)
|
||||
prefix := graphiteSection.Key("prefix").Value()
|
||||
|
||||
if prefix == "" {
|
||||
prefix = "service.grafana.%(instance_name)s."
|
||||
prefix = "prod.grafana.%(instance_name)s."
|
||||
}
|
||||
|
||||
publisher.prefix = strings.Replace(prefix, "%(instance_name)s", safeInstanceName, -1)
|
||||
|
||||
return publisher, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestGraphitePublisher(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
sec, err := setting.Cfg.NewSection("metrics.graphite")
|
||||
sec.NewKey("prefix", "service.grafana.%(instance_name)s.")
|
||||
sec.NewKey("prefix", "prod.grafana.%(instance_name)s.")
|
||||
sec.NewKey("address", "localhost:2001")
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
@@ -30,7 +30,30 @@ func TestGraphitePublisher(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(publisher, ShouldNotBeNil)
|
||||
|
||||
So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
|
||||
So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
|
||||
So(publisher.address, ShouldEqual, "localhost:2001")
|
||||
})
|
||||
|
||||
Convey("Test graphite publisher default prefix", t, func() {
|
||||
var err error
|
||||
err = setting.NewConfigContext(&setting.CommandLineArgs{
|
||||
HomePath: "../../",
|
||||
})
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
sec, err := setting.Cfg.NewSection("metrics.graphite")
|
||||
sec.NewKey("address", "localhost:2001")
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
setting.InstanceName = "hostname.with.dots.com"
|
||||
publisher, err := CreateGraphitePublisher()
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(publisher, ShouldNotBeNil)
|
||||
|
||||
So(publisher.prefix, ShouldEqual, "prod.grafana.hostname_with_dots_com.")
|
||||
So(publisher.address, ShouldEqual, "localhost:2001")
|
||||
})
|
||||
|
||||
@@ -48,9 +71,6 @@ func TestGraphitePublisher(t *testing.T) {
|
||||
publisher, err := CreateGraphitePublisher()
|
||||
|
||||
So(err, ShouldBeNil)
|
||||
So(publisher, ShouldNotBeNil)
|
||||
|
||||
So(publisher.prefix, ShouldEqual, "service.grafana.hostname_with_dots_com.")
|
||||
So(publisher.address, ShouldEqual, "localhost:2003")
|
||||
So(publisher, ShouldBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user