Skip to content

Commit ac8f4c1

Browse files
committed
add plugin documentation
1 parent 4232599 commit ac8f4c1

File tree

8 files changed

+71
-24
lines changed

8 files changed

+71
-24
lines changed

docs/INPUTS.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import (
3838
)
3939

4040
type Simple struct {
41-
Ok bool `toml:"ok"`
41+
Ok bool `toml:"ok"`
42+
Log telegraf.Logger `toml:"-"`
4243
}
4344

4445
func (s *Simple) Description() string {
@@ -52,6 +53,7 @@ func (s *Simple) SampleConfig() string {
5253
`
5354
}
5455

56+
// Init is for setup, and validating config.
5557
func (s *Simple) Init() error {
5658
return nil
5759
}

docs/OUTPUTS.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ import (
3030
)
3131

3232
type Simple struct {
33-
Ok bool `toml:"ok"`
33+
Ok bool `toml:"ok"`
34+
Log telegraf.Logger `toml:"-"`
3435
}
3536

3637
func (s *Simple) Description() string {
@@ -43,20 +44,25 @@ func (s *Simple) SampleConfig() string {
4344
`
4445
}
4546

47+
// Init is for setup, and validating config.
4648
func (s *Simple) Init() error {
4749
return nil
4850
}
4951

5052
func (s *Simple) Connect() error {
51-
// Make a connection to the URL here
53+
// Make any connection required here
5254
return nil
5355
}
5456

5557
func (s *Simple) Close() error {
56-
// Close connection to the URL here
58+
// Close any connections here.
59+
// Write will not be called once Close is called, so there is no need to synchronize.
5760
return nil
5861
}
5962

63+
// Write should write immediately to the output, and not buffer writes
64+
// (Telegraf manages the buffer for you). Returning an error will fail this
65+
// batch of writes and the entire batch will be retried automatically.
6066
func (s *Simple) Write(metrics []telegraf.Metric) error {
6167
for _, metric := range metrics {
6268
// write `metric` to the output sink here
@@ -102,9 +108,9 @@ Metrics are flushed to outputs when any of the following events happen:
102108
- The telegraf process has received a SIGUSR1 signal
103109

104110
Note that if the flush takes longer than the `agent.interval` to write the metrics
105-
to the output, you'll see a message saying the output `did not complete within its
106-
flush interval`. This may mean your output is not keeping up with the flow of metrics,
107-
and you may want to look into enabling compression, reducing the size of your metrics,
111+
to the output, you'll see a message saying the output `did not complete within its
112+
flush interval`. This may mean your output is not keeping up with the flow of metrics,
113+
and you may want to look into enabling compression, reducing the size of your metrics,
108114
or investigate other reasons why the writes might be taking longer than expected.
109115

110116
[file]: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/file

docs/PROCESSORS.md

+23
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
)
3434

3535
type Printer struct {
36+
Log telegraf.Logger `toml:"-"`
3637
}
3738

3839
var sampleConfig = `
@@ -46,6 +47,7 @@ func (p *Printer) Description() string {
4647
return "Print all metrics that pass through this filter."
4748
}
4849

50+
// Init is for setup, and validating config.
4951
func (p *Printer) Init() error {
5052
return nil
5153
}
@@ -97,6 +99,7 @@ import (
9799
)
98100

99101
type Printer struct {
102+
Log telegraf.Logger `toml:"-"`
100103
}
101104

102105
var sampleConfig = `
@@ -110,13 +113,27 @@ func (p *Printer) Description() string {
110113
return "Print all metrics that pass through this filter."
111114
}
112115

116+
// Init is for setup, and validating config.
113117
func (p *Printer) Init() error {
114118
return nil
115119
}
116120

121+
// Start is called once when the plugin starts; it is only called once per
122+
// plugin instance, and never in parallel.
123+
// Start should return once it is ready to receive metrics.
124+
// The passed in accumulator is the same as the one passed to Add(), so you
125+
// can choose to save it in the plugin, or use the one received from Add().
117126
func (p *Printer) Start(acc telegraf.Accumulator) error {
118127
}
119128

129+
// Add is called for each metric to be processed. The Add() function does not
130+
// need to wait for the metric to be processed before returning, and it may
131+
// be acceptable to let background goroutine(s) handle the processing if you
132+
// have slow processing you need to do in parallel.
133+
// Keep in mind Add() should not spawn unbounded goroutines, so you may need
134+
// to use a semaphore or pool of workers (eg: reverse_dns plugin does this).
135+
// Metrics you don't want to pass downstream should have metric.Drop() called,
136+
// rather than simply omitting the acc.AddMetric() call
120137
func (p *Printer) Add(metric telegraf.Metric, acc telegraf.Accumulator) error {
121138
// print!
122139
fmt.Println(metric.String())
@@ -127,6 +144,12 @@ func (p *Printer) Add(metric telegraf.Metric, acc telegraf.Accumulator) error {
127144
return nil
128145
}
129146

147+
// Stop gives you an opportunity to gracefully shut down the processor.
148+
// Once Stop() is called, Add() will not be called any more. If you are using
149+
// goroutines, you should wait for any in-progress metrics to be processed
150+
// before returning from Stop().
151+
// When stop returns, you should no longer be writing metrics to the
152+
// accumulator.
130153
func (p *Printer) Stop() error {
131154
}
132155

input.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type Input interface {
44
PluginDescriber
55

66
// Gather takes in an accumulator and adds the metrics that the Input
7-
// gathers. This is called every "interval"
7+
// gathers. This is called every agent.interval
88
Gather(Accumulator) error
99
}
1010

@@ -15,6 +15,9 @@ type ServiceInput interface {
1515
// Stop returns.
1616
Start(Accumulator) error
1717

18-
// Stop stops the services and closes any necessary channels and connections
18+
// Stop stops the services and closes any necessary channels and connections.
19+
// Metrics should not be written out to the accumulator once stop returns, so
20+
// Stop() should stop reading and wait for any in-flight metrics to write out
21+
// to the accumulator before returning.
1922
Stop()
2023
}

output.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package telegraf
33
type Output interface {
44
PluginDescriber
55

6-
// Connect to the Output
6+
// Connect to the Output; connect is only called once when the plugin starts
77
Connect() error
8-
// Close any connections to the Output
8+
// Close any connections to the Output. Close is called once when the output
9+
// is shutting down. Close will not be called until all writes have finished,
10+
// and Write() will not be called once Close() has been, so locking is not
11+
// necessary.
912
Close() error
1013
// Write takes in group of points to be written to the Output
1114
Write(metrics []Metric) error

plugin.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type Initializer interface {
1010
}
1111

1212
// PluginDescriber contains the functions all plugins must implement to describe
13-
// themselves to Telegraf
13+
// themselves to Telegraf. Note that all plugins may define a logger that is
14+
// not part of the interface, but will receive an injected logger if it's set.
15+
// eg: Log telegraf.Logger `toml:"-"`
1416
type PluginDescriber interface {
1517
// SampleConfig returns the default configuration of the Processor
1618
SampleConfig() string

plugins/inputs/http_response/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ This input plugin checks HTTP/HTTPS connections.
77
```toml
88
# HTTP/HTTPS request given an address a method and a timeout
99
[[inputs.http_response]]
10-
## Deprecated in 1.12, use 'urls'
11-
## Server address (default http://localhost)
12-
# address = "http://localhost"
10+
## address is Deprecated in 1.12, use 'urls'
1311

1412
## List of urls to query.
1513
# urls = ["http://localhost"]
@@ -39,8 +37,8 @@ This input plugin checks HTTP/HTTPS connections.
3937
# {'fake':'data'}
4038
# '''
4139

42-
## Optional name of the field that will contain the body of the response.
43-
## By default it is set to an empty String indicating that the body's content won't be added
40+
## Optional name of the field that will contain the body of the response.
41+
## By default it is set to an empty String indicating that the body's content won't be added
4442
# response_body_field = ''
4543

4644
## Maximum allowed HTTP response body size in bytes.

processor.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,27 @@ type Processor interface {
1414
type StreamingProcessor interface {
1515
PluginDescriber
1616

17-
// Start is the initializer for the processor
18-
// Start is only called once per plugin instance, and never in parallel.
19-
// Start should exit immediately after setup
17+
// Start is called once when the plugin starts; it is only called once per
18+
// plugin instance, and never in parallel.
19+
// Start should return once it is ready to receive metrics.
20+
// The passed in accumulator is the same as the one passed to Add(), so you
21+
// can choose to save it in the plugin, or use the one received from Add().
2022
Start(acc Accumulator) error
2123

22-
// Add is called for each metric to be processed.
24+
// Add is called for each metric to be processed. The Add() function does not
25+
// need to wait for the metric to be processed before returning, and it may
26+
// be acceptable to let background goroutine(s) handle the processing if you
27+
// have slow processing you need to do in parallel.
28+
// Keep in mind Add() should not spawn unbounded goroutines, so you may need
29+
// to use a semaphore or pool of workers (eg: reverse_dns plugin does this)
30+
// Metrics you don't want to pass downstream should have metric.Drop() called,
31+
// rather than simply omitting the acc.AddMetric() call
2332
Add(metric Metric, acc Accumulator) error
2433

25-
// Stop gives you a callback to free resources.
26-
// by the time Stop is called, the input stream will have already been closed
27-
// and Add will not be called anymore.
34+
// Stop gives you an opportunity to gracefully shut down the processor.
35+
// Once Stop() is called, Add() will not be called any more. If you are using
36+
// goroutines, you should wait for any in-progress metrics to be processed
37+
// before returning from Stop().
2838
// When stop returns, you should no longer be writing metrics to the
2939
// accumulator.
3040
Stop() error

0 commit comments

Comments
 (0)