-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More advanced use case #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,4 +106,58 @@ You can use this plugin with either a caddy.json or a Caddyfile here is an examp | |
} | ||
} | ||
} | ||
``` | ||
``` | ||
|
||
# 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The import name does not mach the snippet name |
||
} | ||
} | ||
``` | ||
|
||
## telegraf.conf | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the |
||
[[inputs.http_listener_v2]] | ||
service_address = "10.99.99.99:7777" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider using |
||
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 | ||
''' | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logging output format is missing here. Add
format json