Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import name does not mach the snippet name

}
}
```

## telegraf.conf
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the toml language here to add syntax highlighting

[[inputs.http_listener_v2]]
service_address = "10.99.99.99:7777"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider using 0.0.0.0 here to make it more clear, that it is a listening port

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
'''
```