Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
37
plugins/outputs/nsq/README.md
Normal file
37
plugins/outputs/nsq/README.md
Normal file
|
@ -0,0 +1,37 @@
|
|||
# NSQ Output Plugin
|
||||
|
||||
This plugin writes metrics to the given topic of a [NSQ][nsq] instance as a
|
||||
producer in one of the supported [data formats][data_formats].
|
||||
|
||||
⭐ Telegraf v0.2.1
|
||||
🏷️ messaging
|
||||
💻 all
|
||||
|
||||
[nsq]: https://nsq.io
|
||||
[data_formats]: /docs/DATA_FORMATS_OUTPUT.md
|
||||
|
||||
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
|
||||
|
||||
In addition to the plugin-specific configuration settings, plugins support
|
||||
additional global and plugin configuration settings. These settings are used to
|
||||
modify metrics, tags, and field or create aliases and configure ordering, etc.
|
||||
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
|
||||
|
||||
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
|
||||
|
||||
## Configuration
|
||||
|
||||
```toml @sample.conf
|
||||
# Send telegraf measurements to NSQD
|
||||
[[outputs.nsq]]
|
||||
## Location of nsqd instance listening on TCP
|
||||
server = "localhost:4150"
|
||||
## NSQ topic for producer messages
|
||||
topic = "telegraf"
|
||||
|
||||
## Data format to output.
|
||||
## Each data format has its own unique set of configuration options, read
|
||||
## more about them here:
|
||||
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
|
||||
data_format = "influx"
|
||||
```
|
75
plugins/outputs/nsq/nsq.go
Normal file
75
plugins/outputs/nsq/nsq.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
//go:generate ../../../tools/readme_config_includer/generator
|
||||
package nsq
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
|
||||
"github.com/nsqio/go-nsq"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/plugins/outputs"
|
||||
)
|
||||
|
||||
//go:embed sample.conf
|
||||
var sampleConfig string
|
||||
|
||||
type NSQ struct {
|
||||
Server string
|
||||
Topic string
|
||||
Log telegraf.Logger `toml:"-"`
|
||||
|
||||
producer *nsq.Producer
|
||||
serializer telegraf.Serializer
|
||||
}
|
||||
|
||||
func (*NSQ) SampleConfig() string {
|
||||
return sampleConfig
|
||||
}
|
||||
|
||||
func (n *NSQ) SetSerializer(serializer telegraf.Serializer) {
|
||||
n.serializer = serializer
|
||||
}
|
||||
|
||||
func (n *NSQ) Connect() error {
|
||||
config := nsq.NewConfig()
|
||||
producer, err := nsq.NewProducer(n.Server, config)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n.producer = producer
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NSQ) Close() error {
|
||||
n.producer.Stop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NSQ) Write(metrics []telegraf.Metric) error {
|
||||
if len(metrics) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, metric := range metrics {
|
||||
buf, err := n.serializer.Serialize(metric)
|
||||
if err != nil {
|
||||
n.Log.Debugf("Could not serialize metric: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = n.producer.Publish(n.Topic, buf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send NSQD message: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
outputs.Add("nsq", func() telegraf.Output {
|
||||
return &NSQ{}
|
||||
})
|
||||
}
|
47
plugins/outputs/nsq/nsq_test.go
Normal file
47
plugins/outputs/nsq/nsq_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package nsq
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/testcontainers/testcontainers-go/wait"
|
||||
|
||||
"github.com/influxdata/telegraf/plugins/serializers/influx"
|
||||
"github.com/influxdata/telegraf/testutil"
|
||||
)
|
||||
|
||||
func TestConnectAndWriteIntegration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("Skipping integration test in short mode")
|
||||
}
|
||||
|
||||
servicePort := "4150"
|
||||
container := testutil.Container{
|
||||
Image: "nsqio/nsq",
|
||||
ExposedPorts: []string{servicePort},
|
||||
Entrypoint: []string{"/nsqd"},
|
||||
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
|
||||
}
|
||||
err := container.Start()
|
||||
require.NoError(t, err, "failed to start container")
|
||||
defer container.Terminate()
|
||||
|
||||
server := []string{fmt.Sprintf("%s:%s", container.Address, container.Ports[servicePort])}
|
||||
s := &influx.Serializer{}
|
||||
require.NoError(t, s.Init())
|
||||
n := &NSQ{
|
||||
Server: server[0],
|
||||
Topic: "telegraf",
|
||||
serializer: s,
|
||||
}
|
||||
|
||||
// Verify that we can connect to the NSQ daemon
|
||||
err = n.Connect()
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify that we can successfully write data to the NSQ daemon
|
||||
err = n.Write(testutil.MockMetrics())
|
||||
require.NoError(t, err)
|
||||
}
|
12
plugins/outputs/nsq/sample.conf
Normal file
12
plugins/outputs/nsq/sample.conf
Normal file
|
@ -0,0 +1,12 @@
|
|||
# Send telegraf measurements to NSQD
|
||||
[[outputs.nsq]]
|
||||
## Location of nsqd instance listening on TCP
|
||||
server = "localhost:4150"
|
||||
## NSQ topic for producer messages
|
||||
topic = "telegraf"
|
||||
|
||||
## Data format to output.
|
||||
## Each data format has its own unique set of configuration options, read
|
||||
## more about them here:
|
||||
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
|
||||
data_format = "influx"
|
Loading…
Add table
Add a link
Reference in a new issue