本文整理匯總了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))
}
示例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)
}
示例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()
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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)
}
}
示例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)
}
}
}