當前位置: 首頁>>代碼示例>>Golang>>正文


Golang influxdb-go.NewClient函數代碼示例

本文整理匯總了Golang中github.com/influxdb/influxdb-go.NewClient函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewClient函數的具體用法?Golang NewClient怎麽用?Golang NewClient使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewClient函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	numberOfSeries := 50000
	if len(os.Args) > 1 {
		numberOfSeries, _ = strconv.Atoi(os.Args[1])
	}
	fmt.Printf("Benchmarking writing %d series\n", numberOfSeries)

	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	if err != nil {
		panic(err)
	}

	before := time.Now()
	client.DeleteDatabase("performance")
	fmt.Printf("Deleting took %s\n", time.Now().Sub(before))
	os.Exit(0)
	if err := client.CreateDatabase("performance"); err != nil {
		panic(err)
	}

	client, err = influxdb.NewClient(&influxdb.ClientConfig{
		Database: "performance",
	})
	if err != nil {
		panic(err)
	}

	before = time.Now()

	for i := 0; i < 10; i++ {
		series := []*influxdb.Series{}
		for i := 0; i < numberOfSeries; i++ {
			name := fmt.Sprintf("series_%d", i+1)
			series = append(series, &influxdb.Series{
				Name:    name,
				Columns: []string{"value"},
				Points: [][]interface{}{
					{rand.Float64()},
				},
			})
		}
		if err := client.WriteSeries(series); err != nil {
			panic(err)
		}
	}

	fmt.Printf("Writing took %s\n", time.Now().Sub(before))
}
開發者ID:hanshenu,項目名稱:influxdb,代碼行數:48,代碼來源:main.go

示例2: TestUserWritePermissions

func (self *SingleServerSuite) TestUserWritePermissions(c *C) {
	rootUser := self.server.GetClient("", c)

	// create two users one that can only read and one that can only write. both can access test_should_read
	// series only
	/* c.Assert(rootUser.CreateDatabase("db1"), IsNil) */
	c.Assert(rootUser.CreateDatabaseUser("db1", "limited_user", "pass", "^$", "^$"), IsNil)

	config := &influxdb.ClientConfig{
		Username: "limited_user",
		Password: "pass",
		Database: "db1",
	}
	user, err := influxdb.NewClient(config)
	c.Assert(err, IsNil)

	data := `
[
  {
    "points": [
        [1]
    ],
    "name": "test_should_write",
    "columns": ["value"]
  }
]`
	invalidData := `
[
  {
    "points": [
        [2]
    ],
    "name": "test_should_not_write",
    "columns": ["value"]
  }
]`
	series := []*influxdb.Series{}
	c.Assert(json.Unmarshal([]byte(data), &series), IsNil)
	// readUser shouldn't be able to write
	c.Assert(user.WriteSeries(series), NotNil)
	content := self.server.RunQueryAsRoot("select * from test_should_write", "m", c)
	c.Assert(content, HasLen, 0)
	rootUser.ChangeDatabaseUser("db1", "limited_user", "pass", false, "^$", "test_should_write")
	// write the data to test the write permissions
	c.Assert(user.WriteSeries(series), IsNil)
	self.server.WaitForServerToSync()
	invalidSeries := []*influxdb.Series{}
	content = self.server.RunQueryAsRoot("select * from test_should_write", "m", c)
	c.Assert(content, HasLen, 1)
	c.Assert(json.Unmarshal([]byte(invalidData), &invalidSeries), IsNil)
	c.Assert(user.WriteSeries(invalidSeries), NotNil)
	self.server.WaitForServerToSync()
	content = self.server.RunQueryAsRoot("select * from test_should_not_write", "m", c)
	c.Assert(content, HasLen, 0)
	rootUser.ChangeDatabaseUser("db1", "limited_user", "pass", false, "^$", "test_.*")
	c.Assert(user.WriteSeries(invalidSeries), IsNil)
	self.server.WaitForServerToSync()
	content = self.server.RunQueryAsRoot("select * from test_should_not_write", "m", c)
	c.Assert(content, HasLen, 1)
}
開發者ID:richthegeek,項目名稱:influxdb,代碼行數:60,代碼來源:single_server_test.go

示例3: WriteData

func (self *Server) WriteData(data interface{}, c *C, precision ...influxdb.TimePrecision) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Username: "root",
		Password: "root",
		Database: "db1",
	})
	c.Assert(err, IsNil)
	var series []*influxdb.Series
	switch x := data.(type) {
	case string:
		c.Assert(json.Unmarshal([]byte(x), &series), IsNil)
	case []*influxdb.Series:
		series = x
	default:
		c.Fatalf("Unknown type: %T", x)
	}

	if len(precision) == 0 {
		err = client.WriteSeries(series)
	} else {
		err = client.WriteSeriesWithTimePrecision(series, precision[0])
	}
	c.Assert(err, IsNil)
	self.WaitForServerToSync()
}
開發者ID:9cat,項目名稱:influxdb,代碼行數:25,代碼來源:server.go

示例4: RunInvalidQuery

func (self *DataTestClient) RunInvalidQuery(query string, c *C, timePrecision ...influxdb.TimePrecision) []*influxdb.Series {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{Database: self.db})
	c.Assert(err, IsNil)
	_, err = client.Query(query, timePrecision...)
	c.Assert(err, NotNil)
	return nil
}
開發者ID:9cat,項目名稱:influxdb,代碼行數:7,代碼來源:data_test_client.go

示例5: createUser

func (self *SingleServerSuite) createUser(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.CreateDatabase("db1"), IsNil)
	c.Assert(client.CreateDatabaseUser("db1", "user", "pass"), IsNil)
	c.Assert(client.AlterDatabasePrivilege("db1", "user", true), IsNil)
}
開發者ID:richthegeek,項目名稱:influxdb,代碼行數:7,代碼來源:single_server_test.go

示例6: TestSslOnly

func (self *SingleServerSuite) TestSslOnly(c *C) {
	self.server.Stop()
	// TODO: don't hard code the path here
	c.Assert(os.RemoveAll("/tmp/influxdb/development"), IsNil)
	server := NewSslServer("src/integration/test_ssl_only.toml", c)
	server.WaitForServerToStart()

	defer func() {
		server.Stop()
		self.server = NewServer("src/integration/test_config_single.toml", c)
	}()

	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		IsSecure: true,
		HttpClient: &http.Client{
			Transport: &http.Transport{
				TLSClientConfig: &tls.Config{
					InsecureSkipVerify: true,
				},
			},
		},
	})

	c.Assert(err, IsNil)
	c.Assert(client.Ping(), IsNil)

}
開發者ID:richthegeek,項目名稱:influxdb,代碼行數:27,代碼來源:single_server_test.go

示例7: RunQueryWithNumbers

func (self *DataTestClient) RunQueryWithNumbers(query string, c *C, timePrecision ...influxdb.TimePrecision) []*influxdb.Series {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{Database: self.db})
	c.Assert(err, IsNil)
	series, err := client.QueryWithNumbers(query, timePrecision...)
	c.Assert(err, IsNil)
	return series
}
開發者ID:hanshenu,項目名稱:influxdb,代碼行數:7,代碼來源:data_test_client.go

示例8: GetClient

// optional db
func (self *Server) GetClient(db string, c *C) *influxdb.Client {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Host:     fmt.Sprintf("localhost:%d", self.apiPort),
		Database: db,
	})
	c.Assert(err, IsNil)
	return client
}
開發者ID:9cat,項目名稱:influxdb,代碼行數:9,代碼來源:server.go

示例9: WriteData

func (self *DataTestClient) WriteData(series []*influxdb.Series, c *C, timePrecision ...influxdb.TimePrecision) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{Database: self.db})
	c.Assert(err, IsNil)
	if len(timePrecision) == 0 {
		c.Assert(client.WriteSeries(series), IsNil)
	} else {
		c.Assert(client.WriteSeriesWithTimePrecision(series, timePrecision[0]), IsNil)
	}
}
開發者ID:9cat,項目名稱:influxdb,代碼行數:9,代碼來源:data_test_client.go

示例10: TestShortPasswords

func (self *SingleServerSuite) TestShortPasswords(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.CreateDatabaseUser("shahid", "shahid", "1"), Not(ErrorMatches), ".*blowfish.*")

	// should be able to recreate the user
	c.Assert(client.CreateDatabaseUser("shahid", "shahid", "shahid"), IsNil)

	c.Assert(client.AuthenticateDatabaseUser("shahid", "shahid", "shahid"), IsNil)
}
開發者ID:siqueries,項目名稱:influxdb,代碼行數:10,代碼來源:single_server_test.go

示例11: GetClientWithUser

func (self *Server) GetClientWithUser(db, username, password string, c *C) *influxdb.Client {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Host:     fmt.Sprintf("localhost:%d", self.apiPort),
		Username: username,
		Password: password,
		Database: db,
	})
	c.Assert(err, IsNil)
	return client
}
開發者ID:hyc,項目名稱:influxdb,代碼行數:10,代碼來源:server.go

示例12: NewCounterClient

func NewCounterClient(httpClient *http.Client) (*CounterClient, error) {
	client, err := influx.NewClient(&influx.ClientConfig{
		Host:       fmt.Sprintf("%s:%d", InfluxConfig.Host, InfluxConfig.Port),
		Username:   InfluxConfig.Username,
		Password:   InfluxConfig.Password,
		Database:   InfluxConfig.Database,
		IsSecure:   InfluxConfig.IsSecure,
		HttpClient: httpClient,
	})
	return &CounterClient{influxClient: client}, err
}
開發者ID:speedland,項目名稱:lib,代碼行數:11,代碼來源:counter.go

示例13: RunQueryAsUser

func (self *Server) RunQueryAsUser(query string, precision influxdb.TimePrecision, username, password string, isValid bool, c *C) []*influxdb.Series {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{
		Username: username,
		Password: password,
		Database: "db1",
	})
	c.Assert(err, IsNil)
	series, err := client.Query(query, precision)
	if isValid {
		c.Assert(err, IsNil)
	} else {
		c.Assert(err, NotNil)
	}
	return series
}
開發者ID:9cat,項目名稱:influxdb,代碼行數:15,代碼來源:server.go

示例14: TestDeletingNewDatabase

// issue #378
func (self *SingleServerSuite) TestDeletingNewDatabase(c *C) {
	client, err := influxdb.NewClient(&influxdb.ClientConfig{})
	c.Assert(err, IsNil)
	c.Assert(client.CreateDatabase("delete0"), IsNil)

	s := CreatePoints("data_resurrection", 1, 10)
	self.server.WriteData(s, c)
	self.server.WaitForServerToSync()
	fmt.Printf("wrote some data\n")

	for i := 0; i < 2; i++ {
		c.Assert(client.CreateDatabase("delete1"), IsNil)
		c.Assert(client.DeleteDatabase("delete1"), IsNil)
		c.Assert(client.Ping(), IsNil)
	}
}
開發者ID:richthegeek,項目名稱:influxdb,代碼行數:17,代碼來源:single_server_test.go

示例15: Influxdb

func Influxdb(r metrics.Registry, d time.Duration, config *Config) {
	client, err := influxClient.NewClient(&influxClient.ClientConfig{
		Host:     config.Host,
		Database: config.Database,
		Username: config.Username,
		Password: config.Password,
	})
	if err != nil {
		log.Println(err)
		return
	}

	for _ = range time.Tick(d) {
		if err := send(r, client); err != nil {
			log.Println(err)
		}
	}
}
開發者ID:johntdyer,項目名稱:golang-devops-stuff,代碼行數:18,代碼來源:influxdb.go


注:本文中的github.com/influxdb/influxdb-go.NewClient函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。