1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,120 @@
# Mcrouter Input Plugin
This plugin gathers statistics data from [Mcrouter][mcrouter] instances, a
protocol router, developed and maintained by Facebook, for scaling
[memcached][memcached] deployments.
⭐ Telegraf v1.7.0
🏷️ applications, network
💻 all
[mcrouter]: https://github.com/facebook/mcrouter
[memcached]: http://memcached.org/
## 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
# Read metrics from one or many mcrouter servers.
[[inputs.mcrouter]]
## An array of address to gather stats about. Specify an ip or hostname
## with port. ie tcp://localhost:11211, tcp://10.0.0.1:11211, etc.
servers = ["tcp://localhost:11211", "unix:///var/run/mcrouter.sock"]
## Timeout for metric collections from all servers. Minimum timeout is "1s".
# timeout = "5s"
```
## Metrics
The fields from this plugin are gathered in the *mcrouter* measurement.
Description of gathered fields can be found in the [project wiki][wiki].
Fields:
* uptime
* num_servers
* num_servers_new
* num_servers_up
* num_servers_down
* num_servers_closed
* num_clients
* num_suspect_servers
* destination_batches_sum
* destination_requests_sum
* outstanding_route_get_reqs_queued
* outstanding_route_update_reqs_queued
* outstanding_route_get_avg_queue_size
* outstanding_route_update_avg_queue_size
* outstanding_route_get_avg_wait_time_sec
* outstanding_route_update_avg_wait_time_sec
* retrans_closed_connections
* destination_pending_reqs
* destination_inflight_reqs
* destination_batch_size
* asynclog_requests
* proxy_reqs_processing
* proxy_reqs_waiting
* client_queue_notify_period
* rusage_system
* rusage_user
* ps_num_minor_faults
* ps_num_major_faults
* ps_user_time_sec
* ps_system_time_sec
* ps_vsize
* ps_rss
* fibers_allocated
* fibers_pool_size
* fibers_stack_high_watermark
* successful_client_connections
* duration_us
* destination_max_pending_reqs
* destination_max_inflight_reqs
* retrans_per_kbyte_max
* cmd_get_count
* cmd_delete_out
* cmd_lease_get
* cmd_set
* cmd_get_out_all
* cmd_get_out
* cmd_lease_set_count
* cmd_other_out_all
* cmd_lease_get_out
* cmd_set_count
* cmd_lease_set_out
* cmd_delete_count
* cmd_other
* cmd_delete
* cmd_get
* cmd_lease_set
* cmd_set_out
* cmd_lease_get_count
* cmd_other_out
* cmd_lease_get_out_all
* cmd_set_out_all
* cmd_other_count
* cmd_delete_out_all
* cmd_lease_set_out_all
[wiki]: https://github.com/facebook/mcrouter/wiki/Stats-list
## Tags
* Mcrouter measurements have the following tags:
* server (the host name from which metrics are gathered)
## Example Output
```text
mcrouter,server=localhost:11211 uptime=166,num_servers=1,num_servers_new=1,num_servers_up=0,num_servers_down=0,num_servers_closed=0,num_clients=1,num_suspect_servers=0,destination_batches_sum=0,destination_requests_sum=0,outstanding_route_get_reqs_queued=0,outstanding_route_update_reqs_queued=0,outstanding_route_get_avg_queue_size=0,outstanding_route_update_avg_queue_size=0,outstanding_route_get_avg_wait_time_sec=0,outstanding_route_update_avg_wait_time_sec=0,retrans_closed_connections=0,destination_pending_reqs=0,destination_inflight_reqs=0,destination_batch_size=0,asynclog_requests=0,proxy_reqs_processing=1,proxy_reqs_waiting=0,client_queue_notify_period=0,rusage_system=0.040966,rusage_user=0.020483,ps_num_minor_faults=2490,ps_num_major_faults=11,ps_user_time_sec=0.02,ps_system_time_sec=0.04,ps_vsize=697741312,ps_rss=10563584,fibers_allocated=0,fibers_pool_size=0,fibers_stack_high_watermark=0,successful_client_connections=18,duration_us=0,destination_max_pending_reqs=0,destination_max_inflight_reqs=0,retrans_per_kbyte_max=0,cmd_get_count=0,cmd_delete_out=0,cmd_lease_get=0,cmd_set=0,cmd_get_out_all=0,cmd_get_out=0,cmd_lease_set_count=0,cmd_other_out_all=0,cmd_lease_get_out=0,cmd_set_count=0,cmd_lease_set_out=0,cmd_delete_count=0,cmd_other=0,cmd_delete=0,cmd_get=0,cmd_lease_set=0,cmd_set_out=0,cmd_lease_get_count=0,cmd_other_out=0,cmd_lease_get_out_all=0,cmd_set_out_all=0,cmd_other_count=0,cmd_delete_out_all=0,cmd_lease_set_out_all=0 1453831884664956455
```

View file

@ -0,0 +1,280 @@
//go:generate ../../../tools/readme_config_includer/generator
package mcrouter
import (
"bufio"
"context"
_ "embed"
"errors"
"fmt"
"net"
"net/url"
"strconv"
"strings"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/plugins/inputs"
)
//go:embed sample.conf
var sampleConfig string
// enum for statType
type statType int
const (
typeInt statType = iota
typeFloat statType = iota
)
var (
defaultTimeout = 5 * time.Second
defaultServerURL = url.URL{
Scheme: "tcp",
Host: "localhost:11211",
}
// The list of metrics that should be sent
sendMetrics = map[string]statType{
"uptime": typeInt,
"num_servers": typeInt,
"num_servers_new": typeInt,
"num_servers_up": typeInt,
"num_servers_down": typeInt,
"num_servers_closed": typeInt,
"num_clients": typeInt,
"num_suspect_servers": typeInt,
"destination_batches_sum": typeInt,
"destination_requests_sum": typeInt,
"outstanding_route_get_reqs_queued": typeInt,
"outstanding_route_update_reqs_queued": typeInt,
"outstanding_route_get_avg_queue_size": typeInt,
"outstanding_route_update_avg_queue_size": typeInt,
"outstanding_route_get_avg_wait_time_sec": typeInt,
"outstanding_route_update_avg_wait_time_sec": typeInt,
"retrans_closed_connections": typeInt,
"destination_pending_reqs": typeInt,
"destination_inflight_reqs": typeInt,
"destination_batch_size": typeInt,
"asynclog_requests": typeInt,
"proxy_reqs_processing": typeInt,
"proxy_reqs_waiting": typeInt,
"client_queue_notify_period": typeInt,
"rusage_system": typeFloat,
"rusage_user": typeFloat,
"ps_num_minor_faults": typeInt,
"ps_num_major_faults": typeInt,
"ps_user_time_sec": typeFloat,
"ps_system_time_sec": typeFloat,
"ps_vsize": typeInt,
"ps_rss": typeInt,
"fibers_allocated": typeInt,
"fibers_pool_size": typeInt,
"fibers_stack_high_watermark": typeInt,
"successful_client_connections": typeInt,
"duration_us": typeInt,
"destination_max_pending_reqs": typeInt,
"destination_max_inflight_reqs": typeInt,
"retrans_per_kbyte_max": typeInt,
"cmd_get_count": typeInt,
"cmd_delete_out": typeInt,
"cmd_lease_get": typeInt,
"cmd_set": typeInt,
"cmd_get_out_all": typeInt,
"cmd_get_out": typeInt,
"cmd_lease_set_count": typeInt,
"cmd_other_out_all": typeInt,
"cmd_lease_get_out": typeInt,
"cmd_set_count": typeInt,
"cmd_lease_set_out": typeInt,
"cmd_delete_count": typeInt,
"cmd_other": typeInt,
"cmd_delete": typeInt,
"cmd_get": typeInt,
"cmd_lease_set": typeInt,
"cmd_set_out": typeInt,
"cmd_lease_get_count": typeInt,
"cmd_other_out": typeInt,
"cmd_lease_get_out_all": typeInt,
"cmd_set_out_all": typeInt,
"cmd_other_count": typeInt,
"cmd_delete_out_all": typeInt,
"cmd_lease_set_out_all": typeInt,
}
)
type Mcrouter struct {
Servers []string `toml:"servers"`
Timeout config.Duration `toml:"timeout"`
}
func (*Mcrouter) SampleConfig() string {
return sampleConfig
}
func (m *Mcrouter) Gather(acc telegraf.Accumulator) error {
ctx := context.Background()
if m.Timeout < config.Duration(1*time.Second) {
m.Timeout = config.Duration(defaultTimeout)
}
ctx, cancel := context.WithTimeout(ctx, time.Duration(m.Timeout))
defer cancel()
if len(m.Servers) == 0 {
m.Servers = []string{defaultServerURL.String()}
}
for _, serverAddress := range m.Servers {
acc.AddError(gatherServer(ctx, serverAddress, acc))
}
return nil
}
// parseAddress parses an address string into 'host:port' and 'protocol' parts
func parseAddress(address string) (parsedAddress, protocol string, err error) {
var host string
var port string
parsedAddress = address
u, parseError := url.Parse(parsedAddress)
if parseError != nil {
return "", "", errors.New("invalid server address")
}
if u.Scheme != "tcp" && u.Scheme != "unix" {
return "", "", errors.New("invalid server protocol")
}
protocol = u.Scheme
if protocol == "unix" {
if u.Path == "" {
return "", "", errors.New("invalid unix socket path")
}
parsedAddress = u.Path
} else {
if u.Host == "" {
return "", "", errors.New("invalid host")
}
host = u.Hostname()
port = u.Port()
if host == "" {
host = defaultServerURL.Hostname()
}
if port == "" {
port = defaultServerURL.Port()
}
parsedAddress = host + ":" + port
}
return parsedAddress, protocol, nil
}
func gatherServer(ctx context.Context, address string, acc telegraf.Accumulator) error {
var conn net.Conn
var err error
var protocol string
var dialer net.Dialer
address, protocol, err = parseAddress(address)
if err != nil {
return err
}
conn, err = dialer.DialContext(ctx, protocol, address)
if err != nil {
return err
}
defer conn.Close()
// Extend connection
deadline, ok := ctx.Deadline()
if ok {
if err := conn.SetDeadline(deadline); err != nil {
return err
}
}
// Read and write buffer
reader := bufio.NewReader(conn)
scanner := bufio.NewScanner(reader)
// Send command
if _, err := fmt.Fprint(conn, "stats\r\n"); err != nil {
return err
}
values, err := parseResponse(scanner)
if err != nil {
return err
}
// Add server address as a tag
tags := map[string]string{"server": address}
// Process values
fields := make(map[string]interface{})
for key, sType := range sendMetrics {
if value, ok := values[key]; ok {
switch sType {
case typeInt:
if v, errParse := strconv.ParseInt(value, 10, 64); errParse == nil {
fields[key] = v
}
case typeFloat:
if v, errParse := strconv.ParseFloat(value, 64); errParse == nil {
fields[key] = v
}
default:
}
}
}
acc.AddFields("mcrouter", fields, tags)
return nil
}
func parseResponse(r *bufio.Scanner) (map[string]string, error) {
values := make(map[string]string)
for r.Scan() {
// Read line
line := r.Text()
// Done
if line == "END" {
break
}
// Read values
s := strings.SplitN(line, " ", 3)
if len(s) != 3 || s[0] != "STAT" {
return nil, fmt.Errorf("unexpected line in stats response: %s", line)
}
// Save values
values[s[1]] = s[2]
}
return values, nil
}
func init() {
inputs.Add("mcrouter", func() telegraf.Input {
return &Mcrouter{}
})
}

View file

@ -0,0 +1,188 @@
package mcrouter
import (
"bufio"
"fmt"
"os"
"testing"
"time"
"github.com/docker/go-connections/nat"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go/wait"
"github.com/influxdata/telegraf/testutil"
)
func TestAddressParsing(t *testing.T) {
var acceptTests = [][3]string{
{"tcp://localhost:8086", "localhost:8086", "tcp"},
{"tcp://localhost", "localhost:" + defaultServerURL.Port(), "tcp"},
{"tcp://localhost:", "localhost:" + defaultServerURL.Port(), "tcp"},
{"tcp://:8086", defaultServerURL.Hostname() + ":8086", "tcp"},
{"tcp://:", defaultServerURL.Host, "tcp"},
}
var rejectTests = []string{
"tcp://",
}
for _, args := range acceptTests {
address, protocol, err := parseAddress(args[0])
require.NoError(t, err, args[0])
require.Equal(t, args[1], address, args[0])
require.Equal(t, args[2], protocol, args[0])
}
for _, addr := range rejectTests {
address, protocol, err := parseAddress(addr)
require.Error(t, err, addr)
require.Empty(t, address, addr)
require.Empty(t, protocol, addr)
}
}
func TestMcrouterGeneratesMetricsIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
servicePort := "11211"
container := testutil.Container{
Image: "memcached",
ExposedPorts: []string{servicePort},
WaitingFor: wait.ForListeningPort(nat.Port(servicePort)),
}
err := container.Start()
require.NoError(t, err, "failed to start container")
defer container.Terminate()
m := &Mcrouter{
Servers: []string{
fmt.Sprintf("tcp://%s:%s", container.Address, container.Ports[servicePort]),
},
}
var acc testutil.Accumulator
// wait for the uptime stat to show up
require.Eventually(t, func() bool {
err = acc.GatherError(m.Gather)
require.NoError(t, err)
return acc.HasInt64Field("mcrouter", "uptime")
}, 5*time.Second, 10*time.Millisecond)
intMetrics := []string{
"uptime",
"cmd_set",
"cmd_get",
}
floatMetrics := []string{
"rusage_system",
"rusage_user",
}
for _, metric := range intMetrics {
require.True(t, acc.HasInt64Field("mcrouter", metric), metric)
}
for _, metric := range floatMetrics {
require.True(t, acc.HasFloatField("mcrouter", metric), metric)
}
}
func TestMcrouterParseMetrics(t *testing.T) {
filePath := "testdata/mcrouter_stats"
file, err := os.Open(filePath)
require.NoErrorf(t, err, "could not read from file %s", filePath)
r := bufio.NewReader(file)
scanner := bufio.NewScanner(r)
values, err := parseResponse(scanner)
require.NoError(t, err, "Error parsing mcrouter response")
tests := []struct {
key string
value string
}{
{"uptime", "166"},
{"num_servers", "1"},
{"num_servers_new", "1"},
{"num_servers_up", "0"},
{"num_servers_down", "0"},
{"num_servers_closed", "0"},
{"num_clients", "1"},
{"num_suspect_servers", "0"},
{"destination_batches_sum", "0"},
{"destination_requests_sum", "0"},
{"outstanding_route_get_reqs_queued", "0"},
{"outstanding_route_update_reqs_queued", "0"},
{"outstanding_route_get_avg_queue_size", "0"},
{"outstanding_route_update_avg_queue_size", "0"},
{"outstanding_route_get_avg_wait_time_sec", "0"},
{"outstanding_route_update_avg_wait_time_sec", "0"},
{"retrans_closed_connections", "0"},
{"destination_pending_reqs", "0"},
{"destination_inflight_reqs", "0"},
{"destination_batch_size", "0"},
{"asynclog_requests", "0"},
{"proxy_reqs_processing", "1"},
{"proxy_reqs_waiting", "0"},
{"client_queue_notify_period", "0"},
{"rusage_system", "0.040966"},
{"rusage_user", "0.020483"},
{"ps_num_minor_faults", "2490"},
{"ps_num_major_faults", "11"},
{"ps_user_time_sec", "0.02"},
{"ps_system_time_sec", "0.04"},
{"ps_vsize", "697741312"},
{"ps_rss", "10563584"},
{"fibers_allocated", "0"},
{"fibers_pool_size", "0"},
{"fibers_stack_high_watermark", "0"},
{"successful_client_connections", "18"},
{"duration_us", "0"},
{"destination_max_pending_reqs", "0"},
{"destination_max_inflight_reqs", "0"},
{"retrans_per_kbyte_max", "0"},
{"cmd_get_count", "0"},
{"cmd_delete_out", "0"},
{"cmd_lease_get", "0"},
{"cmd_set", "0"},
{"cmd_get_out_all", "0"},
{"cmd_get_out", "0"},
{"cmd_lease_set_count", "0"},
{"cmd_other_out_all", "0"},
{"cmd_lease_get_out", "0"},
{"cmd_set_count", "0"},
{"cmd_lease_set_out", "0"},
{"cmd_delete_count", "0"},
{"cmd_other", "0"},
{"cmd_delete", "0"},
{"cmd_get", "0"},
{"cmd_lease_set", "0"},
{"cmd_set_out", "0"},
{"cmd_lease_get_count", "0"},
{"cmd_other_out", "0"},
{"cmd_lease_get_out_all", "0"},
{"cmd_set_out_all", "0"},
{"cmd_other_count", "0"},
{"cmd_delete_out_all", "0"},
{"cmd_lease_set_out_all", "0"},
}
for _, test := range tests {
value, ok := values[test.key]
if !ok {
t.Errorf("Did not find key for metric %s in values", test.key)
continue
}
if value != test.value {
t.Errorf("Metric: %s, Expected: %s, actual: %s",
test.key, test.value, value)
}
}
}

View file

@ -0,0 +1,8 @@
# Read metrics from one or many mcrouter servers.
[[inputs.mcrouter]]
## An array of address to gather stats about. Specify an ip or hostname
## with port. ie tcp://localhost:11211, tcp://10.0.0.1:11211, etc.
servers = ["tcp://localhost:11211", "unix:///var/run/mcrouter.sock"]
## Timeout for metric collections from all servers. Minimum timeout is "1s".
# timeout = "5s"

View file

@ -0,0 +1,70 @@
STAT version 36.0.0 mcrouter
STAT commandargs --port 11211 --config-file /etc/mcrouter/mcrouter.json --async-dir /var/spool/mcrouter --log-path /var/log/mcrouter/mcrouter.log --stats-root /var/mcrouter/stats --server-timeout 100 --reset-inactive-connection-interval 10000 --proxy-threads auto
STAT pid 21357
STAT parent_pid 1
STAT time 1524673265
STAT uptime 166
STAT num_servers 1
STAT num_servers_new 1
STAT num_servers_up 0
STAT num_servers_down 0
STAT num_servers_closed 0
STAT num_clients 1
STAT num_suspect_servers 0
STAT destination_batches_sum 0
STAT destination_requests_sum 0
STAT outstanding_route_get_reqs_queued 0
STAT outstanding_route_update_reqs_queued 0
STAT outstanding_route_get_avg_queue_size 0
STAT outstanding_route_update_avg_queue_size 0
STAT outstanding_route_get_avg_wait_time_sec 0
STAT outstanding_route_update_avg_wait_time_sec 0
STAT retrans_closed_connections 0
STAT destination_pending_reqs 0
STAT destination_inflight_reqs 0
STAT destination_batch_size 0
STAT asynclog_requests 0
STAT proxy_reqs_processing 1
STAT proxy_reqs_waiting 0
STAT client_queue_notify_period 0
STAT rusage_system 0.040966
STAT rusage_user 0.020483
STAT ps_num_minor_faults 2490
STAT ps_num_major_faults 11
STAT ps_user_time_sec 0.02
STAT ps_system_time_sec 0.04
STAT ps_vsize 697741312
STAT ps_rss 10563584
STAT fibers_allocated 0
STAT fibers_pool_size 0
STAT fibers_stack_high_watermark 0
STAT successful_client_connections 18
STAT duration_us 0
STAT destination_max_pending_reqs 0
STAT destination_max_inflight_reqs 0
STAT retrans_per_kbyte_max 0
STAT cmd_get_count 0
STAT cmd_delete_out 0
STAT cmd_lease_get 0
STAT cmd_set 0
STAT cmd_get_out_all 0
STAT cmd_get_out 0
STAT cmd_lease_set_count 0
STAT cmd_other_out_all 0
STAT cmd_lease_get_out 0
STAT cmd_set_count 0
STAT cmd_lease_set_out 0
STAT cmd_delete_count 0
STAT cmd_other 0
STAT cmd_delete 0
STAT cmd_get 0
STAT cmd_lease_set 0
STAT cmd_set_out 0
STAT cmd_lease_get_count 0
STAT cmd_other_out 0
STAT cmd_lease_get_out_all 0
STAT cmd_set_out_all 0
STAT cmd_other_count 0
STAT cmd_delete_out_all 0
STAT cmd_lease_set_out_all 0
END