예제 #1
0
func (nmon *Nmon) InitGrafanaSession() *grafanaclient.Session {
	//check if datasource for nmon2influxdb exist
	grafana := grafanaclient.NewSession(nmon.Params.Guser, nmon.Params.Gpass, nmon.Params.Gurl)
	err := grafana.DoLogon()
	check(err)

	resDs, err := grafana.GetDataSource(nmon.Params.DS)
	if resDs.Name == "" {
		plugins, err := grafana.GetDataSourcePlugins()
		check(err)
		if _, present := plugins["influxdb"]; !present {
			fmt.Printf("No plugin for influxDB in Grafana !\n")
			os.Exit(1)
		}

		var ds = grafanaclient.DataSource{Name: nmon.Params.DS,
			Type:     plugins["influxdb"].Type,
			Access:   "proxy",
			URL:      nmon.DbURL(),
			User:     nmon.Params.User,
			Password: nmon.Params.Password,
			Database: nmon.Params.Db,
		}
		err = grafana.CreateDataSource(ds)
		check(err)
		fmt.Printf("Grafana %s DataSource created.\n", nmon.Params.DS)
	}

	return grafana
}
예제 #2
0
func (nmon *Nmon) InitGrafanaSession() *grafanaclient.Session {
	//check if datasource for nmon2influxdb exist
	grafana := grafanaclient.NewSession(nmon.Params.Guser, nmon.Params.Gpass, nmon.Params.Gurl)
	err := grafana.DoLogon()
	check(err)

	resDs, err := grafana.GetDataSource(nmon.Params.DS)
	if resDs.Name == "" {
		var ds = grafanaclient.DataSource{Name: nmon.Params.DS,
			Type:     "influxdb_09",
			Access:   "direct",
			URL:      nmon.DbURL(),
			User:     nmon.Params.User,
			Password: nmon.Params.Password,
			Database: nmon.Params.Db,
		}
		err = grafana.CreateDataSource(ds)
		check(err)
		fmt.Printf("Grafana %s DataSource created.\n", nmon.Params.DS)
	}

	return grafana
}