Skip to content

Commit

Permalink
doc(influx): enhance influx1&2 doc
Browse files Browse the repository at this point in the history
Signed-off-by: Jiyong Huang <huangjy@emqx.io>
  • Loading branch information
ngjaying committed Nov 28, 2023
1 parent 4df80ad commit b205df1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 282 deletions.
90 changes: 30 additions & 60 deletions docs/en_US/guide/sinks/plugin/influx.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,39 @@

The sink will publish the result into a InfluxDB.

## Compile & deploy plugin

Please make following update before compile the plugin,

- Add Influxdb library reference in `go.mod`.
- Remove the first line `// +build plugins` of file `plugins/sinks/influx.go`.

```shell
# cd $eKuiper_src
# go build -trimpath --buildmode=plugin -o plugins/sinks/Influx.so extensions/sinks/influx/influx.go
# zip influx.zip plugins/sinks/Influx.so
# cp influx.zip /root/tomcat_path/webapps/ROOT/
# bin/kuiper create plugin sink influx -f /tmp/influxPlugin.txt
# bin/kuiper create rule influx -f /tmp/influxRule.txt
```

Restart the eKuiper server to activate the plugin.

## Properties

| Property name | Optional | Description |
|---------------|----------|---------------------------------------------------|
| addr | true | The addr of the InfluxDB |
| measurement | true | The measurement of the InfluxDb (like table name) |
| username | false | The InfluxDB login username |
| password | false | The InfluxDB login password |
| databasename | true | The database of the InfluxDB |
| tagkey | true | The tag key of the InfluxDB |
| tagvalue | true | The tag value of the InfluxDB |

Other common sink properties are supported. Please refer to the [sink common properties](../overview.md#common-properties) for more information.
Connection properties:

| Property name | Optional | Description |
|----------------------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| addr | true | The addr of the InfluxDB |
| username | false | The InfluxDB login username |
| password | false | The InfluxDB login password |
| database | true | The database of the InfluxDB |
| certificationPath | true | The certification path. It can be an absolute path, or a relative path. If it is an relative path, then the base path is where you executing the `kuiperd` command. For example, if you run `bin/kuiperd` from `/var/kuiper`, then the base path is `/var/kuiper`; If you run `./kuiperd` from `/var/kuiper/bin`, then the base path is `/var/kuiper/bin`. |
| privateKeyPath | true | The private key path. It can be either absolute path, or relative path, which is similar to use of certificationPath. |
| rootCaPath | true | The location of root ca path. It can be an absolute path, or a relative path, which is similar to use of certificationPath. |
| tlsMinVersion | true | Specifies the minimum version of the TLS protocol that will be negotiated with the client. Accept values are `tls1.0`, `tls1.1`, `tls1.2` and `tls1.3`. Default: `tls1.2`. |
| renegotiationSupport | true | Determines how and when the client handles server-initiated renegotiation requests. Support `never`, `once` or `freely` options. Default: `never`. |
| insecureSkipVerify | true | If InsecureSkipVerify is `true`, TLS accepts any certificate presented by the server and any host name in that certificate. In this mode, TLS is susceptible to man-in-the-middle attacks. The default value is `false`. The configuration item can only be used with TLS connections. |

Write options:

| Property name | Optional | Description |
|---------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| measurement | false | The measurement of the InfluxDb (like table name) |
| tags | true | The tags to write, the format is like {"tag1":"value1"}. The value can be dataTemplate format, like <span v-pre>{"tag1":"{{.temperature}}"}</span> |
| fields | true | The fields to write, the format is like ["field1", "field2"]. If fields is not set, all fields selected in the SQL will all written to InfluxDB. |
| precision | true | The precision of the timestamp. Support `ns`, `us`, `ms`, `s`. Default: `ms`. |
| tsFieldName | true | The field name of the timestamp. If set, the written timestamp will use the value of the field. For example, if the data has {"ts": 1888888888} and the tsFieldName is set to ts, then the value 1888888888 will be used when written to InfluxDB. Make sure the value is formatted according to the precision. If not set, the current timestamp will be used. |

Other common sink properties including batch settings are supported. Please refer to
the [sink common properties](../overview.md#common-properties) for more information.

## Sample usage

Below is a sample for selecting temperature great than 50 degree, and some profiles only for your reference.

### /tmp/influxRule.txt
Below is a sample for selecting temperature greater than 50 degree and write into influxDB.

```json
{
Expand All @@ -52,37 +48,11 @@ Below is a sample for selecting temperature great than 50 degree, and some profi
"username": "",
"password": "",
"measurement": "test",
"databasename": "databasename",
"tagkey": "tagkey",
"tagvalue": "tagvalue",
"database": "databasename",
"tags": "{\"tag1\":\"value1\"}",
"fields": ["humidity", "temperature", "pressure"]
}
}
]
}
```

### /tmp/influxPlugin.txt

```json
{
"file":"http://localhost:8080/influx.zip"
}
```

### plugins/go.mod

```go
module plugins

go 1.14

require (
github.com/lf-edge/ekuiper v0.0.0-20200323140757-60d00241372b
github.com/influxdata/influxdb-client-go v1.2.0
github.com/influxdata/influxdb1-client v0.0.0-20200515024757-02f0bf5dbca3 // indirect
)

replace github.com/lf-edge/ekuiper => /root/goProject/kuiper

```
86 changes: 2 additions & 84 deletions docs/en_US/guide/sinks/plugin/influx2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,6 @@

The sink will publish the result into a InfluxDB `V2.X` .

## Compile & deploy plugin

Please make following update before compile the plugin,

- Add Influxdb library reference in `go.mod`.
- Remove the first line `// +build plugins` of file `plugins/sinks/influx.go`.

### build in shell

```shell
# cd $eKuiper_src
# go build -trimpath --buildmode=plugin -o plugins/sinks/influx2.so extensions/sinks/influx/influx2.go
# zip influx2.zip plugins/sinks/influx2.so
# cp influx.zip /root/tomcat_path/webapps/ROOT/
# bin/kuiper create plugin sink influx2 -f /tmp/influxPlugin.txt
# bin/kuiper create rule influx2 -f /tmp/influxRule.txt
```

### build with image

```shell
docker build -t demo/plugins:v1 -f build/plugins/Dockerfile .
docker run demo/plugins:v1
docker cp 90eae15a7245:/workspace/_plugins/debian/sinks /tmp
```

Dockerfile like this:

```dockerfile
## plase check go version that kuiper used
ARG GO_VERSION=1.18.5
FROM ghcr.io/lf-edge/ekuiper/base:$GO_VERSION-debian AS builder
WORKDIR /workspace
ADD . /workspace/
RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN make plugins_c
CMD ["sleep","3600"]
```

add this in Makefile:

```dockerfile
PLUGINS_CUSTOM := sinks/influx2

.PHONY: plugins_c $(PLUGINS_CUSTOM)
plugins_c: $(PLUGINS_CUSTOM)

$(PLUGINS_CUSTOM): PLUGIN_TYPE = $(word 1, $(subst /, , $@))
$(PLUGINS_CUSTOM): PLUGIN_NAME = $(word 2, $(subst /, , $@))
$(PLUGINS_CUSTOM):
@$(CURDIR)/build-plugins.sh $(PLUGIN_TYPE) $(PLUGIN_NAME)
```

Restart the eKuiper server to activate the plugin.

## Properties

Connection properties:
Expand All @@ -79,7 +24,7 @@ Write options:
| Property name | Optional | Description |
|-----------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| measurement | false | The measurement of the InfluxDb (like table name) |
| tags | true | The tags to write, the format is like {"tag1":"value1"}. The value can be dataTemplate format, like {"tag1":"{{.temperature}}"} |
| tags | true | The tags to write, the format is like {"tag1":"value1"}. The value can be dataTemplate format, like <span v-pre>{"tag1":"{{.temperature}}"}</span> |
| fields | true | The fields to write, the format is like ["field1", "field2"]. If fields is not set, all fields selected in the SQL will all written to InfluxDB. |
| precision | true | The precision of the timestamp. Support `ns`, `us`, `ms`, `s`. Default: `ms`. |
| tsFieldName | true | The field name of the timestamp. If set, the written timestamp will use the value of the field. For example, if the data has {"ts": 1888888888} and the tsFieldName is set to ts, then the value 1888888888 will be used when written to InfluxDB. Make sure the value is formatted according to the precision. If not set, the current timestamp will be used. |
Expand All @@ -90,9 +35,7 @@ the [sink common properties](../overview.md#common-properties) for more informat

## Sample usage

Below is a sample for selecting temperature greater than 50 degree, and some profiles only for your reference.

### /tmp/influxRule.txt
Below is a sample for selecting temperature greater than 50 degree and write into influxDB.

```json
{
Expand All @@ -114,28 +57,3 @@ Below is a sample for selecting temperature greater than 50 degree, and some pro
]
}
```

### /tmp/influxPlugin.txt

```json
{
"file":"http://localhost:8080/influx2.zip"
}
```

### plugins/go.mod

```go
module plugins

go 1.18

require (
github.com/lf-edge/ekuiper v0.0.0-20220727015637-7d6f5c447110
github.com/influxdata/influxdb-client-go/v2 v2.10.0
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
)

replace github.com/lf-edge/ekuiper => /root/goProject/kuiper

```
Loading

0 comments on commit b205df1

Please sign in to comment.