package main import ( "log" //"time" "fmt" //"math/rand" "github.com/influxdata/influxdb/client/v2" ) const ( MyDB = "testInfluxdb" username = "root" password = "" ) func queryDB(clnt client.Client, cmd string) (res []client.Result, err error) { q := client.Query{ Command: cmd, Database: MyDB, } if response, err := clnt.Query(q); err == nil { if response.Error() != nil { return res, response.Error() } res = response.Results } else { return res, err } return res, nil } func main() { // Make client c, err := client.NewHTTPClient(client.HTTPConfig{ Addr: ":8086", Username: username, Password: password, }) if err != nil { log.Fatalln("Error: ", err) } q := fmt.Sprintf("select * from monitorStatus where system_name='sys_5' and site_name='s_1' and equipment_name='e_6' order by time desc limit 10000 ;") res, err2 := queryDB(c, q) if err2 != nil { log.Fatal(err) } count := len(res[0].Series[0].Values) log.Printf("Found a total of %v records\n", count) } View Code 测试结果记录
查看整体磁盘空间占用:
du -sh /var/lib/influxdb/
查看最终磁盘空间占用:
du -sh /var/lib/influxdb/data/testInfluxdb
100万条数据