Created
July 31, 2020 18:22
-
-
Save deanproctor/8d1f9b6344d6c91f398bdc5c540e7acb to your computer and use it in GitHub Desktop.
Groovy script to set the roll attribute once per hour per table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.time.TimeCategory | |
if (!state.containsKey('lastRoll')) { | |
state << [lastRoll: [:]] | |
} | |
def setRollFlag(String tableName) { | |
if (!state.lastRoll.containsKey(tableName)) { | |
state.lastRoll[tableName] = new Date() | |
} | |
use (TimeCategory) { | |
if (state.lastRoll[tableName] < 1.hour.ago) { | |
state.lastRoll[tableName] = new Date() | |
return true | |
log.info("script sets roll flag for measurement") | |
} | |
return false | |
} | |
} | |
for (record in records) { | |
try { | |
if(setRollFlag(record.attributes['jdbc.tables'])) { | |
record.attributes['roll'] = 'yes' | |
} | |
output.write(record) | |
} catch (e) { | |
// Write a record to the error pipeline | |
log.error(e.toString(), e) | |
error.write(record, e.toString()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment