diff --git a/README.md b/README.md index 4202158..e9a4e21 100644 --- a/README.md +++ b/README.md @@ -106,4 +106,58 @@ You can use this plugin with either a caddy.json or a Caddyfile here is an examp } } } -``` \ No newline at end of file +``` + +# Filtering use case +If you need to store less data in your InfluxDB, you are able to manipulate things using Telegraf instance located in between of Caddy and database. + +This Telegraf example strips all data from the log apart of request duration, size and status which are enough to make cute realtime diagrams of your web services. Please note it is not a full telegraf configuration, it's just the part related to listening of data from caddy and doing manipulation. + +## Caddyfile +``` +(influxlog) { + output influx_log { + token whatever_as_telegraf_does_not_verify_it + org whatever_as_telegraf_does_not_verify_it + bucket whatever_as_telegraf_does_not_verify_it + measurement caddy + tags { + host server7 + domain {args.0} + } + # specially tuned telegraf to strip most of useless data + host http://telegraf_instance:7777 + } +} +127.0.0.1 { + root * example + file_server + log { + import accesslog "example.com" + } +} +``` + +## telegraf.conf +``` +[[inputs.http_listener_v2]] + service_address = "10.99.99.99:7777" + paths = ["/api/v2/write"] + data_format = "influx" + fieldpass = [ "duration", "size", "status", "ts" ] + +[[processors.starlark]] + namepass = [ "caddy" ] + source = ''' +load("logging.star", "log") +load("time.star", "time") +def apply(metric): + # we need nanoseconds, caddy gives seconds + entrytime = int(float(metric.fields["ts"])*1e9) + log.debug("{}".format(entrytime)) + metric.time = entrytime + # removal of unneeded now field + metric.fields.pop("ts") + return metric +''' +```