docs(inputs.execd): Add python example, clean up doc (#15337)

This commit is contained in:
Joshua Powers 2024-05-10 10:24:56 -06:00 committed by GitHub
parent bdf14aad72
commit f3357f369f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 76 deletions

View File

@ -13,6 +13,9 @@ new line to the process's STDIN.
STDERR from the process will be relayed to Telegraf as errors in the logs.
[Input Data Formats]: ../../../docs/DATA_FORMATS_INPUT.md
[inputs.exec]: ../exec/README.md
## Service Input <!-- @/docs/includes/service_input.md -->
This plugin is a service input. Normal plugins gather metrics determined by the
@ -74,84 +77,18 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
## Example
### Daemon written in bash using STDIN signaling
See the examples directory for basic examples in different languages expecting
various signals from Telegraf:
```bash
#!/bin/bash
counter=0
while IFS= read -r LINE; do
echo "counter_bash count=${counter}"
let counter=counter+1
done
```
```toml
[[inputs.execd]]
command = ["plugins/inputs/execd/examples/count.sh"]
signal = "STDIN"
```
### Go daemon using SIGHUP
```go
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP)
counter := 0
for {
<-c
fmt.Printf("counter_go count=%d\n", counter)
counter++
}
}
```
```toml
[[inputs.execd]]
command = ["plugins/inputs/execd/examples/count.go.exe"]
signal = "SIGHUP"
```
### Ruby daemon running standalone
```ruby
#!/usr/bin/env ruby
counter = 0
loop do
puts "counter_ruby count=#{counter}"
STDOUT.flush
counter += 1
sleep 1
end
```
```toml
[[inputs.execd]]
command = ["plugins/inputs/execd/examples/count.rb"]
signal = "none"
```
[Input Data Formats]: ../../../docs/DATA_FORMATS_INPUT.md
[inputs.exec]: ../exec/README.md
- [Go](./examples/count.go): Example expects `signal = "SIGHUP"`
- [Python](./examples/count.py): Example expects `signal = "none"`
- [Ruby](./examples/count.rb): Example expects `signal = "none"`
- [shell](./examples/count.sh): Example expects `signal = "STDIN"`
## Metrics
Varies depending on the users data.
## Example Output
Varies depending on the users data.

View File

@ -0,0 +1,12 @@
#!/usr/bin/env python3
import sys
import time
COUNTER = 0
while True:
print("counter_python count=" + str(COUNTER))
sys.stdout.flush()
COUNTER += 1
time.sleep(1)