https://github.com/tesibelda/lightmetric
Libraries that help creating plugins for telegraf without telegraf libraries dependencies
https://github.com/tesibelda/lightmetric
golang-library telegraf-plugin
Last synced: 2 months ago
JSON representation
Libraries that help creating plugins for telegraf without telegraf libraries dependencies
- Host: GitHub
- URL: https://github.com/tesibelda/lightmetric
- Owner: tesibelda
- License: mit
- Created: 2023-06-04T19:10:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-23T17:51:06.000Z (over 1 year ago)
- Last Synced: 2025-12-17T12:51:10.071Z (6 months ago)
- Topics: golang-library, telegraf-plugin
- Language: Go
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/tesibelda/lightmetric/raw/master/LICENSE)
[](https://goreportcard.com/report/github.com/tesibelda/lightmetric)

[](https://pkg.go.dev/github.com/tesibelda/lightmetric)
# lightmetric
lightmetric contains libraries that help creating plugins for [telegraf](https://github.com/influxdata/telegraf) monitoring agent. metric library includes Metric and metric Accumulator that you may use for exec input plugins; Shim helps creating execd input plugins like telegraf's [shim](https://github.com/influxdata/telegraf/tree/master/plugins/common/shim). Most of the code has been borrowed from telegraf's repository and most of it has not been modified, but it has been reorganized so that it provides:
* much less library dependencies
* smaller final binary size
* ability to set precision to the execd input plugin shim
* ability to use the shim's [context](https://pkg.go.dev/context) in the plugin's Gather function
Hopefully as telegraf evolves this library will not be helpful in the future.
# Examples
## Example of an exec input plugin using Metric
See the complete example at [examples/rand](https://github.com/tesibelda/lightmetric/tree/main/examples/rand) folder:
```go
ctags["sheep"] = mytag
cfields["counter"] = rand.Intn(100)
t := metric.TimeWithPrecision(time.Now(), time.Millisecond)
m := metric.New("randplugin", ctags, cfields, t)
fmt.Fprint(os.Stdout, m.String(metric.InfluxLp))
```
### Example output
```plain
randplugin,sheep=Shaun counter=66i 1686482784943000000
```
## Example of an execd input plugin using Shim
See the complete example at [examples/counter](https://github.com/tesibelda/lightmetric/tree/main/examples/counter) folder:
```go
p := NewCounter(mytag)
p.Start()
execd := shim.New("SheepCounter").WithPrecision(time.Second)
err := execd.RunInput(p.Gather)
if err != nil {
fmt.Fprintf(os.Stderr, "Error running lightmetric telegraf input shim: %w\n", err)
os.Exit(1)
}
p.Stop()
```
### Example output
```plain
counterplugin,sheep=Shaun counter=1i 1686483004000000000
counterplugin,sheep=Shaun counter=2i 1686483014000000000
counterplugin,sheep=Shaun counter=3i 1686483024000000000
```
# Telegraf configuration
## For an exec input plugin
Use influx data format.
```
[[inputs.exec]]
commands = ["plugins/inputs/execd/yourplugin"]
data_format = "influx"
```
Reference: [exec input](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/exec)
## For execd input plugin shim
Execd input shim requires telegraf to be configured with: signal = "STDIN"
```toml
[[inputs.execd]]
command = ["plugins/inputs/execd/yourplugin --config plugins/inputs/execd/yourplugin.conf"]
signal = "STDIN"
```
Reference: [execd input](https://github.com/influxdata/telegraf/tree/master/plugins/inputs/execd)
# License
[The MIT License (MIT)](https://github.com/tesibelda/vcstat/blob/master/LICENSE)