use of org.graylog2.plugin.ThrottleState in project graylog2-server by Graylog2.
the class ThrottleStateUpdaterThread method doRun.
@Override
public void doRun() {
throttleState = new ThrottleState(throttleState);
final long committedOffset = journal.getCommittedOffset();
// TODO there's a lot of duplication around this class. Probably should be refactored a bit.
// also update metrics for each of the values, so clients can get to it cheaply
long prevTs = currentTs;
currentTs = System.nanoTime();
long previousLogEndOffset = logEndOffset;
long previousReadOffset = currentReadOffset;
long logStartOffset = journal.getLogStartOffset();
// -1 because getLogEndOffset is the next offset that gets assigned
logEndOffset = journal.getLogEndOffset() - 1;
// just to make it clear which field we read
currentReadOffset = journal.getNextReadOffset() - 1;
// for the first run, don't send an update, there's no previous data available to calc rates
if (firstRun) {
firstRun = false;
return;
}
throttleState.appendEventsPerSec = (long) Math.floor((logEndOffset - previousLogEndOffset) / ((currentTs - prevTs) / 1.0E09));
throttleState.readEventsPerSec = (long) Math.floor((currentReadOffset - previousReadOffset) / ((currentTs - prevTs) / 1.0E09));
throttleState.journalSize = journal.size();
throttleState.journalSizeLimit = retentionSize.toBytes();
throttleState.processBufferCapacity = processBuffer.getRemainingCapacity();
if (committedOffset == LocalKafkaJournal.DEFAULT_COMMITTED_OFFSET) {
// nothing committed at all, the entire log is uncommitted, or completely empty.
throttleState.uncommittedJournalEntries = journal.size() == 0 ? 0 : logEndOffset - logStartOffset;
} else {
throttleState.uncommittedJournalEntries = logEndOffset - committedOffset;
}
log.debug("ThrottleState: {}", throttleState);
// the journal needs this to provide information to rest clients
journal.setThrottleState(throttleState);
// publish to interested parties
eventBus.post(throttleState);
// Abusing the current thread to send notifications from KafkaJournal in the graylog2-shared module
final double journalUtilizationPercentage = throttleState.journalSizeLimit > 0 ? (throttleState.journalSize * 100) / throttleState.journalSizeLimit : 0.0;
if (journalUtilizationPercentage > LocalKafkaJournal.NOTIFY_ON_UTILIZATION_PERCENTAGE) {
Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.JOURNAL_UTILIZATION_TOO_HIGH).addSeverity(Notification.Severity.URGENT).addDetail("journal_utilization_percentage", journalUtilizationPercentage);
notificationService.publishIfFirst(notification);
}
if (journal.getPurgedSegmentsInLastRetention() > 0) {
Notification notification = notificationService.buildNow().addNode(serverStatus.getNodeId().toString()).addType(Notification.Type.JOURNAL_UNCOMMITTED_MESSAGES_DELETED).addSeverity(Notification.Severity.URGENT);
notificationService.publishIfFirst(notification);
}
}
use of org.graylog2.plugin.ThrottleState in project graylog2-server by Graylog2.
the class JournalResource method show.
@GET
@Timed
@ApiOperation(value = "Get current state of the journal on this node.")
@RequiresPermissions(RestPermissions.JOURNAL_READ)
public JournalSummaryResponse show() {
if (!journalEnabled) {
return JournalSummaryResponse.createDisabled();
}
if (journal instanceof LocalKafkaJournal) {
final LocalKafkaJournal kafkaJournal = (LocalKafkaJournal) journal;
final ThrottleState throttleState = kafkaJournal.getThrottleState();
long oldestSegment = Long.MAX_VALUE;
for (final LogSegment segment : kafkaJournal.getSegments()) {
oldestSegment = Math.min(oldestSegment, segment.created());
}
return JournalSummaryResponse.createEnabled(throttleState.appendEventsPerSec, throttleState.readEventsPerSec, throttleState.uncommittedJournalEntries, Size.bytes(throttleState.journalSize), Size.bytes(throttleState.journalSizeLimit), kafkaJournal.numberOfSegments(), new DateTime(oldestSegment, DateTimeZone.UTC), KafkaJournalConfigurationSummary.of(kafkaJournalConfiguration));
}
log.warn("Unknown Journal implementation {} in use, cannot get information about it. Pretending journal is disabled.", journal.getClass());
return JournalSummaryResponse.createDisabled();
}
Aggregations