Skip to content

Instantly share code, notes, and snippets.

@cdahlqvist
Last active February 14, 2023 21:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save cdahlqvist/e713b39f0c17d85e613f56408a7facd5 to your computer and use it in GitHub Desktop.
Save cdahlqvist/e713b39f0c17d85e613f56408a7facd5 to your computer and use it in GitHub Desktop.
Ingest pipeline definition for measuring ingest delay based on @timestamp field
# Ingest pipeline that records the timestamp the event was processed (`@received`)
# by the ingest pipeline and calculates the difference in milliseconds compared to
# the event timestamp (`@timestamp`).
POST _scripts/calculate_ingest_delay
{
"script": {
"lang": "painless",
"source": "SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'\"); ctx.ingest_delay = (sdf.parse(ctx['received']).getTime() - sdf.parse(ctx['@timestamp']).getTime()) / 1000.0"
}
}
PUT _ingest/pipeline/ingest_delay
{
"description" : "Pipeline measuring ingest delay for records based on the @timestamp and @received fields",
"processors" : [
{
"set": {
"field": "received",
"value": "{{_ingest.timestamp}}"
}
},
{
"script": {
"id": "calculate_ingest_delay"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment