0%

安装

kubectl apply -f https://raw.githubusercontent.com/influxdata/docs-v2/master/static/downloads/influxdb-k8-minikube.yaml
kubectl get pods -n influxdb
kubectl describe service -n influxdb influxdb
kubectl port-forward -n influxdb service/influxdb 9999:9999

yaml

---
apiVersion: v1
kind: Namespace
metadata:
    name: influxdb
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
    labels:
        app: influxdb
    name: influxdb
    namespace: influxdb
spec:
    replicas: 1
    selector:
        matchLabels:
            app: influxdb
    serviceName: influxdb
    template:
        metadata:
            labels:
                app: influxdb
        spec:
            containers:
              - image: quay.io/influxdb/influxdb:2.0.0-beta
                name: influxdb
                ports:
                  - containerPort: 9999
                    name: influxdb
                volumeMounts:
                  - mountPath: /root/.influxdbv2
                    name: data
    volumeClaimTemplates:
      - metadata:
            name: data
            namespace: influxdb
        spec:
            accessModes:
              - ReadWriteOnce
            resources:
                requests:
                    storage: 10G
---
apiVersion: v1
kind: Service
metadata:
    name: influxdb
    namespace: influxdb
spec:
    ports:
      - name: influxdb
        port: 9999
        targetPort: 9999
    selector:
        app: influxdb
    type: ClusterIP

docker run --name influxdb -p 9999:9999 quay.io/influxdb/influxdb:2.0.0-beta
docker run -p 9999:9999 quay.io/influxdb/influxdb:2.0.0-beta --reporting-disabled
docker exec -it influxdb /bin/bash

tag的使用

  • 把你经常查询的字段作为tag
  • 如果你要对其使用GROUP BY(),也要放在tag中
  • 如果你要对其使用InfluxQL函数,则将其放到field中
  • 如果你需要存储的值不是字符串,则需要放到field中,因为tag value只能是字符串
  • tags不要包含高度可变的信息,如UUID,哈希值和随机字符串,这将导致数据库中的大量series cardinality。

    series cardinality高是许多数据库高内存使用的主要原因

  • 用tag区分数据比使用详细的measurement名字更好
  • 不要把多条信息放到一个tag里面

influx-stress

Flags:
  -b, --batch-size uint      number of points in a batch (default 10000)
  -c, --consistency string   Write consistency (only applicable to clusters) (default "one")
      --create string        Use a custom create database command
      --db string            Database that will be written to (default "stress")
      --dump string          Dump to given file instead of writing over HTTP
  -f, --fast                 Run as fast as possible
      --gzip int             If non-zero, gzip write bodies with given compression level. 1=best speed, 9=best compression, -1=gzip default.
      --host string          Address of InfluxDB instance (default "http://localhost:8086")
      --pass string          Password for user
  -n, --points uint          number of points that will be written (default 18446744073709551615)
      --pps uint             Points Per Second (default 200000)
  -p, --precision string     Resolution of data being written (default "n")
  -q, --quiet                Only print the write throughput
      --rp string            Retention Policy that will be written to
  -r, --runtime duration     Total time that the test will run (default 2562047h47m16.854775807s)
  -s, --series int           number of series that will be written (default 100000)
      --strict               Strict mode will exit as soon as an error or unexpected status is encountered
      --user string          User to write data as

Example Usage

Runs forever

$ influx-stress insert
Runs forever writing as fast as possible

$ influx-stress insert -f
Runs for 1 minute writing as fast as possible

$ influx-stress insert -r 1m -f
Writing an example series key

$ influx-stress insert cpu,host=server,location=us-west,id=myid
Writing an example series key with 20,000 series

$ influx-stress insert -s 20000 cpu,host=server,location=us-west,id=myid
Writing an example point

$ influx-stress insert cpu,host=server,location=us-west,id=myid busy=100,idle=10,random=5i

测试命令

influx_stress.exe insert -r 1m -f

Total Requests: 2000
        Success: 2000
        Fail: 0
Average Response Time: 93.270662ms
Points Per Second: 484339

Total Queries: 250
Average Query Response Time: 3.372889ms

加法

#加一个常数
SELECT "A" + 5 FROM "add"
SELECT * FROM "add" WHERE "A" + 5 > 10
#两个字段相加。
SELECT "A" + "B" FROM "add"
SELECT * FROM "add" WHERE "A" + "B" >= 10

减法

#减法里带常数。
SELECT 1 - "A" FROM "sub"
SELECT * FROM "sub" WHERE 1 - "A" <= 3
#两个字段做减法。
SELECT "A" - "B" FROM "sub"
SELECT * FROM "sub" WHERE "A" - "B" <= 1

乘法

#乘以一个常数。
SELECT 10 * "A" FROM "mult"
SELECT * FROM "mult" WHERE "A" * 10 >= 20
#两个字段相乘。
SELECT "A" * "B" * "C" FROM "mult"
SELECT * FROM "mult" WHERE "A" * "B" <= 80
#乘法和其他运算符混用。
SELECT 10 * ("A" + "B" + "C") FROM "mult"
SELECT 10 * ("A" - "B" - "C") FROM "mult"
SELECT 10 * ("A" + "B" - "C") FROM "mult"

除法

#除法里带常数。
SELECT 10 / "A" FROM "div"
SELECT * FROM "div" WHERE "A" / 10 <= 2
#两个字段相除。
SELECT "A" / "B" FROM "div"
SELECT * FROM "div" WHERE "A" / "B" >= 10
#除法和其他运算符混用。
SELECT 10 / ("A" + "B" + "C") FROM "mult"

求模

#模一个常数。
SELECT "B" % 2 FROM "modulo"
SELECT "B" FROM "modulo" WHERE "B" % 2 = 0
#两个字段求模。
SELECT "A" % "B" FROM "modulo"
SELECT "A" FROM "modulo" WHERE "A" % "B" = 0

按位与

你可以在任何整数和布尔值中使用这个操作符,无论是字段或常数。该操作符不支持浮点数或字符串数据类型。并且不能混合使用整数和布尔值。

SELECT "A" & 255 FROM "bitfields"
SELECT "A" & "B" FROM "bitfields"
SELECT * FROM "data" WHERE "bitfield" & 15 > 0
SELECT "A" & "B" FROM "booleans"
SELECT ("A" ^ true) & "B" FROM "booleans"

按位或

你可以在任何整数和布尔值中使用这个操作符,无论是字段或常数。该操作符不支持浮点数或字符串数据类型。并且不能混合使用整数和布尔值。

SELECT "A" | 5 FROM "bitfields"
SELECT "A" | "B" FROM "bitfields"
SELECT * FROM "data" WHERE "bitfield" | 12 = 12

按位异或

你可以在任何整数和布尔值中使用这个操作符,无论是字段或常数。该操作符不支持浮点数或字符串数据类型。并且不能混合使用整数和布尔值。

SELECT "A" ^ 255 FROM "bitfields"
SELECT "A" ^ "B" FROM "bitfields"
SELECT * FROM "data" WHERE "bitfield" ^ 6 > 0

原文链接与常见问题