Skip to content

Commit 9fe90d7

Browse files
Ayrdriedanielnelson
authored andcommitted
Add plugin development framework (influxdata#4324)
1 parent 2ee374c commit 9fe90d7

File tree

9 files changed

+174
-1
lines changed

9 files changed

+174
-1
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ func init() {
100100
}
101101
```
102102

103+
### Input Plugin Development
104+
105+
* Run `make static` followed by `make plugin-[pluginName]` to spin up a docker dev environment
106+
using docker-compose.
107+
* ***[Optional]*** When developing a plugin, add a `dev` directory with a `docker-compose.yml` and `telegraf.conf`
108+
as well as any other supporting files, where sensible.
109+
103110
## Adding Typed Metrics
104111

105112
In addition the the `AddFields` function, the accumulator also supports an

Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,15 @@ docker-image:
9292
plugins/parsers/influx/machine.go: plugins/parsers/influx/machine.go.rl
9393
ragel -Z -G2 $^ -o $@
9494

95-
.PHONY: deps telegraf install test test-windows lint vet test-all package clean docker-image fmtcheck uint64
95+
static:
96+
@echo "Building static linux binary..."
97+
@CGO_ENABLED=0 \
98+
GOOS=linux \
99+
GOARCH=amd64 \
100+
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
101+
102+
plugin-%:
103+
@echo "Starting dev environment for $${$(@)} input plugin..."
104+
@docker-compose -f plugins/inputs/$${$(@)}/dev/docker-compose.yml up
105+
106+
.PHONY: deps telegraf install test test-windows lint vet test-all package clean docker-image fmtcheck uint64 static
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3'
2+
3+
services:
4+
telegraf:
5+
image: glinton/scratch
6+
volumes:
7+
- ./telegraf.conf:/telegraf.conf
8+
- ../../../../telegraf:/telegraf
9+
- ./test.log:/var/log/test.log
10+
entrypoint:
11+
- /telegraf
12+
- --config
13+
- /telegraf.conf
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[agent]
2+
interval="1s"
3+
flush_interval="1s"
4+
5+
[[inputs.logparser]]
6+
files = ["/var/log/test.log"]
7+
from_beginning = true
8+
[inputs.logparser.grok]
9+
patterns = [ "%{COMBINED_LOG_FORMAT}", "%{CLIENT:client_ip} %{NOTSPACE:ident} %{NOTSPACE:auth} \\[%{TIMESTAMP_ISO8601:timestamp}\\] \"(?:%{WORD:verb:tag} %{NOTSPACE:request}(?: HTTP/%{NUMBER:http_version:float})?|%{DATA})\" %{NUMBER:resp_code:tag} (?:%{NUMBER:resp_bytes:int}|-) %{QS:referrer} %{QS:agent}"]
10+
11+
[[outputs.file]]
12+
files = ["stdout"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
127.0.0.1 ident auth [10/Oct/2000:13:55:36 -0700] "GET /anything HTTP/1.0" 200 2326 "http://localhost:8083/" "Chrome/51.0.2704.84"
2+
127.0.0.1 ident auth [2018-02-21 13:10:34,555] "GET /peter HTTP/1.0" 200 2326 "http://localhost:8083/" "Chrome/51.0.2704.84"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3'
2+
services:
3+
mongodb:
4+
image: mongo
5+
6+
telegraf:
7+
image: glinton/scratch
8+
volumes:
9+
- ./telegraf.conf:/telegraf.conf
10+
- ../../../../telegraf:/telegraf
11+
depends_on:
12+
- mongodb
13+
entrypoint:
14+
- /telegraf
15+
- --config
16+
- /telegraf.conf
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[agent]
2+
interval="1s"
3+
flush_interval="3s"
4+
5+
[[inputs.mongodb]]
6+
servers = ["mongodb://mongodb:27017"]
7+
8+
[[outputs.file]]
9+
files = ["stdout"]
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '3'
2+
3+
services:
4+
mysql:
5+
image: mysql:5.7
6+
restart: always
7+
environment:
8+
MYSQL_ROOT_PASSWORD: telegraf
9+
MYSQL_DATABASE: telegraf
10+
MYSQL_USER: telegraf
11+
MYSQL_PASSWORD: telegraf
12+
maria:
13+
image: mariadb
14+
restart: always
15+
environment:
16+
MYSQL_ROOT_PASSWORD: telegraf
17+
MYSQL_DATABASE: telegraf
18+
MYSQL_USER: telegraf
19+
MYSQL_PASSWORD: telegraf
20+
command: mysqld --userstat=1
21+
percona:
22+
image: percona
23+
restart: always
24+
environment:
25+
MYSQL_ROOT_PASSWORD: telegraf
26+
MYSQL_DATABASE: telegraf
27+
MYSQL_USER: telegraf
28+
MYSQL_PASSWORD: telegraf
29+
30+
telegraf:
31+
image: glinton/scratch
32+
depends_on:
33+
- mysql
34+
- maria
35+
- percona
36+
volumes:
37+
- ./telegraf.conf:/telegraf.conf
38+
- ../../../../telegraf:/telegraf
39+
entrypoint:
40+
- /telegraf
41+
- --config
42+
- /telegraf.conf
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Uncomment each input as needed to test plugin
2+
3+
## mysql
4+
#[[inputs.mysql]]
5+
# servers = ["root:telegraf@tcp(mysql:3306)/"]
6+
# gather_table_schema = true
7+
# gather_process_list = true
8+
# gather_user_statistics = true
9+
# gather_info_schema_auto_inc = true
10+
# gather_innodb_metrics = true
11+
# gather_slave_status = true
12+
# gather_binary_logs = false
13+
# gather_table_io_waits = true
14+
# gather_table_lock_waits = true
15+
# gather_index_io_waits = true
16+
# gather_event_waits = true
17+
# gather_file_events_stats = true
18+
# gather_perf_events_statements = true
19+
# interval_slow = "30m"
20+
# table_schema_databases = []
21+
#
22+
## mariadb
23+
#[[inputs.mysql]]
24+
# servers = ["root:telegraf@tcp(maria:3306)/"]
25+
# gather_table_schema = true
26+
# gather_process_list = true
27+
# gather_user_statistics = true
28+
# gather_info_schema_auto_inc = true
29+
# gather_innodb_metrics = true
30+
# gather_slave_status = true
31+
# gather_binary_logs = false
32+
# gather_table_io_waits = true
33+
# gather_table_lock_waits = true
34+
# gather_index_io_waits = true
35+
# gather_event_waits = true
36+
# gather_file_events_stats = true
37+
# gather_perf_events_statements = true
38+
# interval_slow = "30m"
39+
# table_schema_databases = []
40+
41+
# percona
42+
[[inputs.mysql]]
43+
servers = ["root:telegraf@tcp(percona:3306)/"]
44+
gather_table_schema = true
45+
gather_process_list = true
46+
gather_user_statistics = true
47+
gather_info_schema_auto_inc = true
48+
gather_innodb_metrics = true
49+
gather_slave_status = true
50+
gather_binary_logs = false
51+
gather_table_io_waits = true
52+
gather_table_lock_waits = true
53+
gather_index_io_waits = true
54+
gather_event_waits = true
55+
gather_file_events_stats = true
56+
gather_perf_events_statements = true
57+
interval_slow = "30m"
58+
table_schema_databases = []
59+
60+
[[outputs.file]]
61+
files = ["stdout"]

0 commit comments

Comments
 (0)