diff --git a/plugins/all/all.go b/plugins/all/all.go index ffef12b33..8a0a7e796 100644 --- a/plugins/all/all.go +++ b/plugins/all/all.go @@ -21,4 +21,5 @@ import ( _ "github.com/influxdb/telegraf/plugins/redis" _ "github.com/influxdb/telegraf/plugins/rethinkdb" _ "github.com/influxdb/telegraf/plugins/system" + _ "github.com/influxdb/telegraf/plugins/webservercodes" ) diff --git a/plugins/webservercodes/webserver_codes.go b/plugins/webservercodes/webserver_codes.go new file mode 100644 index 000000000..17c47f299 --- /dev/null +++ b/plugins/webservercodes/webserver_codes.go @@ -0,0 +1,255 @@ +package webservercodes + +import ( + "net/http" + "strconv" + "sync" + "time" + "os" + "io" + "regexp" + "errors" + + "github.com/rogpeppe/rog-go/reverse" + "github.com/influxdb/telegraf/plugins" +) + +type Vhost struct { + Host string + AccessLog string + RegexParsestring string + Interval string +} + +type Webservercodes struct { + Vhosts []*Vhost +} + +type HttpStats struct { + codes map[int]int +} + +var sampleConfig = ` +# List of virtualhosts for http codes collecting (each section for one virtualhost, none for disable collecting codes) +[[webservercodes.vhosts]] +# 'host' field should match hostname in appropriate status url +host = "defaulthost" + +# telegraf user must have read permissions to this log file (shell command 'sudo adduser telegraf adm' for apache on Ubuntu) +access_log = "/var/log/apache2/access.log" + +# Regular expression for fetching codes from log file strings. You can adjust regex for your custom log format +# example for apache "common" and "combined" log formats, nginx default log format ("combined"): +# '\[(?P