write domain name only in tags

This commit is contained in:
Miki 2016-02-08 17:58:20 +01:00
parent 96c8bb3203
commit 2d38937d57
2 changed files with 11 additions and 12 deletions

View File

@ -11,9 +11,9 @@ domains. You can read Dovecot's documentation
[[inputs.dovecot]] [[inputs.dovecot]]
# Dovecot Endpoint # Dovecot Endpoint
# To use TCP, set endpoint = "ip:port" # To use TCP, set endpoint = "ip:port"
server = ["127.0.0.1:24242"] servers = ["127.0.0.1:24242"]
# Only collect metrics for these domains, collect all if empty # Only collect metrics for these domains, collect all if empty
domains_names = [] domains = []
``` ```

View File

@ -10,6 +10,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs" "github.com/influxdata/telegraf/plugins/inputs"
) )
@ -23,8 +24,7 @@ func (d *Dovecot) Description() string {
} }
var sampleConfig = ` var sampleConfig = `
# specify dovecot servers via a url matching: # specify dovecot servers via an address:port list
# address:port
# e.g. # e.g.
# localhost:24242 # localhost:24242
# #
@ -39,7 +39,7 @@ func (d *Dovecot) SampleConfig() string { return sampleConfig }
const defaultPort = "24242" const defaultPort = "24242"
// Reads stats from all configured servers. // Reads stats from all configured servers.
func (d *Dovecot) Gather(acc inputs.Accumulator) error { func (d *Dovecot) Gather(acc telegraf.Accumulator) error {
if len(d.Servers) == 0 { if len(d.Servers) == 0 {
d.Servers = append(d.Servers, "127.0.0.1:24242") d.Servers = append(d.Servers, "127.0.0.1:24242")
@ -68,7 +68,7 @@ func (d *Dovecot) Gather(acc inputs.Accumulator) error {
return outerr return outerr
} }
func (d *Dovecot) gatherServer(addr string, acc inputs.Accumulator, doms map[string]bool) error { func (d *Dovecot) gatherServer(addr string, acc telegraf.Accumulator, doms map[string]bool) error {
_, _, err := net.SplitHostPort(addr) _, _, err := net.SplitHostPort(addr)
if err != nil { if err != nil {
return fmt.Errorf("Error: %s on url %s\n", err, addr) return fmt.Errorf("Error: %s on url %s\n", err, addr)
@ -90,7 +90,7 @@ func (d *Dovecot) gatherServer(addr string, acc inputs.Accumulator, doms map[str
return gatherStats(&buf, acc, doms, host) return gatherStats(&buf, acc, doms, host)
} }
func gatherStats(buf *bytes.Buffer, acc inputs.Accumulator, doms map[string]bool, host string) error { func gatherStats(buf *bytes.Buffer, acc telegraf.Accumulator, doms map[string]bool, host string) error {
lines := strings.Split(buf.String(), "\n") lines := strings.Split(buf.String(), "\n")
head := strings.Split(lines[0], "\t") head := strings.Split(lines[0], "\t")
@ -107,10 +107,10 @@ func gatherStats(buf *bytes.Buffer, acc inputs.Accumulator, doms map[string]bool
} }
tags := map[string]string{"server": host, "domain": val[0]} tags := map[string]string{"server": host, "domain": val[0]}
for n := range val { for n := range val {
fmt.Println(n, head[n], val[n])
switch head[n] { switch head[n] {
case "domain": case "domain":
fields[head[n]] = val[n] continue
// fields[head[n]] = val[n]
case "user_cpu", "sys_cpu", "clock_time": case "user_cpu", "sys_cpu", "clock_time":
fields[head[n]] = secParser(val[n]) fields[head[n]] = secParser(val[n])
case "reset_timestamp", "last_update": case "reset_timestamp", "last_update":
@ -150,7 +150,6 @@ func splitSec(tm string) (sec int64, msec int64) {
func timeParser(tm string) time.Time { func timeParser(tm string) time.Time {
sec, msec := splitSec(tm) sec, msec := splitSec(tm)
fmt.Println("time: ", sec, msec)
return time.Unix(sec, msec) return time.Unix(sec, msec)
} }
@ -161,7 +160,7 @@ func secParser(tm string) float64 {
} }
func init() { func init() {
inputs.Add("dovecot", func() inputs.Input { inputs.Add("dovecot", func() telegraf.Input {
return &Dovecot{} return &Dovecot{}
}) })
} }