Skip to content

Commit

Permalink
beanstalk plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fatpat authored and Vladimir Dombrovski committed Feb 7, 2020
1 parent 6158996 commit 3a3d88f
Show file tree
Hide file tree
Showing 9 changed files with 543 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Current collectors are:
- s3roundtrip (S3 roundtrip check using AWS SDK)
- redis (redis metrics)
- memcached (memcached metrics)
- beanstalk (beanstalk metrics)

Install
---
Expand Down Expand Up @@ -45,6 +46,7 @@ $ go build ./cmd/oiofs.plugin/oiofs.plugin.go
$ go build ./cmd/s3roundtrip.plugin/s3roundtrip.plugin.go
$ go build ./cmd/redis.plugin/redis.plugin.go
$ go build ./cmd/memcached.plugin/memcached.plugin.go
$ go build ./cmd/beanstalk.plugin/beanstalk.plugin.go
```

Type in `./[name].plugin -h` to get all available options for each plugin
Expand All @@ -61,6 +63,7 @@ $ cp oiofs.plugin /usr/libexec/netdata/plugins.d/
$ cp s3roundtrip.plugin /usr/libexec/netdata/plugins.d/
$ cp redis.plugin /usr/libexec/netdata/plugins.d/
$ cp memcached.plugin /usr/libexec/netdata/plugins.d/
$ cp beanstalk.plugin /usr/libexec/netdata/plugins.d/
```

Ubuntu Xenial
Expand All @@ -73,6 +76,7 @@ $ cp oiofs.plugin /usr/libexec/netdata/plugins.d/
$ cp s3roundtrip.plugin /usr/libexec/netdata/plugins.d/
$ cp redis.plugin /usr/libexec/netdata/plugins.d/
$ cp memcached.plugin /usr/libexec/netdata/plugins.d/
$ cp beanstalk.plugin /usr/libexec/netdata/plugins.d/
```

Add the following /etc/netdata/netdata.conf:
Expand Down Expand Up @@ -105,7 +109,11 @@ Add the following /etc/netdata/netdata.conf:

[plugin:memcached]
update every = 10
command options = --targets 172.30.2.106:6011:memcached
command options = --targets 172.30.2.106:6011

[plugin:beanstalk]
update every = 10
command options = --targets 172.30.2.106:6014:tube1:tube2:tube3
```

Create and configure plugin config files
Expand Down
84 changes: 84 additions & 0 deletions beanstalk/beanstalk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// OpenIO netdata collectors
// Copyright (C) 2020 OpenIO SAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 3.0 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public
// License along with this program. If not, see <http://www.gnu.org/licenses/>.

package beanstalk

import (
"bufio"
"net"
"strings"
)

type collector struct {
addr string
tubes []string
}

func NewCollector(addr string, tubes []string) *collector {
return &collector{
addr: addr,
tubes: tubes,
}
}

func SendCommand(conn net.Conn, cmd string, prefix string, data map[string]string) error {
if _, err := conn.Write([]byte(cmd + "\r\n")); err != nil {
return err
}

scanner := bufio.NewScanner(conn)
for scanner.Scan() {
line := scanner.Text()
if line == "" {
break
}
if line == "NOT_FOUND" {
break
}
kv := strings.Split(line, ": ")
if len(kv) != 2 {
continue
}
data[prefix+kv[0]] = kv[1]
}

if err := scanner.Err(); err != nil {
return err
}

return nil
}

func (c *collector) Collect() (map[string]string, error) {
conn, err := net.Dial("tcp", c.addr)
if err != nil {
return nil, err
}
defer conn.Close()

data := map[string]string{}

if err = SendCommand(conn, "stats", "", data); err != nil {
return nil, err
}
for _, tube := range c.tubes {
if err = SendCommand(conn, "stats-tube "+tube, "_"+tube+"_", data); err != nil {
return nil, err
}
}

return data, nil
}
17 changes: 17 additions & 0 deletions beanstalk/beanstalk.spec.stats-tube_default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OK 267
---
name: default
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
total-jobs: 0
current-using: 3
current-watching: 31
current-waiting: 12
cmd-delete: 0
cmd-pause-tube: 0
pause: 0
pause-time-left: 0

17 changes: 17 additions & 0 deletions beanstalk/beanstalk.spec.stats-tube_oio-delete.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OK 276
---
name: oio-delete
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
total-jobs: 90110
current-using: 2
current-watching: 1
current-waiting: 1
cmd-delete: 90110
cmd-pause-tube: 0
pause: 0
pause-time-left: 0

17 changes: 17 additions & 0 deletions beanstalk/beanstalk.spec.stats-tube_oio-rebuild.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OK 269
---
name: oio-rebuild
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
total-jobs: 0
current-using: 2
current-watching: 2
current-waiting: 1
cmd-delete: 0
cmd-pause-tube: 0
pause: 0
pause-time-left: 0

17 changes: 17 additions & 0 deletions beanstalk/beanstalk.spec.stats-tube_oio.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OK 274
---
name: oio
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
total-jobs: 640670
current-using: 24
current-watching: 10
current-waiting: 10
cmd-delete: 640670
cmd-pause-tube: 0
pause: 0
pause-time-left: 0

51 changes: 51 additions & 0 deletions beanstalk/beanstalk.spec.stats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
OK 971
---
current-jobs-urgent: 0
current-jobs-ready: 0
current-jobs-reserved: 0
current-jobs-delayed: 0
current-jobs-buried: 0
cmd-put: 728737
cmd-peek: 0
cmd-peek-ready: 0
cmd-peek-delayed: 0
cmd-peek-buried: 0
cmd-reserve: 728752
cmd-reserve-with-timeout: 173970
cmd-delete: 728737
cmd-release: 4
cmd-use: 28
cmd-watch: 13
cmd-ignore: 0
cmd-bury: 0
cmd-kick: 0
cmd-touch: 0
cmd-stats: 128258
cmd-stats-job: 0
cmd-stats-tube: 129094
cmd-list-tubes: 32282
cmd-list-tube-used: 0
cmd-list-tubes-watched: 0
cmd-pause-tube: 0
job-timeouts: 0
total-jobs: 728737
max-job-size: 65535
current-tubes: 4
current-connections: 31
current-producers: 10
current-workers: 12
current-waiting: 12
total-connections: 122597
pid: 2892
version: 1.10
rusage-utime: 35.948646
rusage-stime: 82.499803
uptime: 348107
binlog-oldest-index: 149
binlog-current-index: 149
binlog-records-migrated: 0
binlog-records-written: 1457478
binlog-max-size: 10240000
id: fe6081983c4b33dd
hostname: node-1.novalocal

Loading

0 comments on commit 3a3d88f

Please sign in to comment.