Skip to content

Commit

Permalink
Status Page: Add account busy/idle to instances. (#2479)
Browse files Browse the repository at this point in the history
* Added idle/busy to instances and total header.
  • Loading branch information
Levonestral authored and sebastienvercammen committed Mar 4, 2018
1 parent cd6f55c commit e03a1d5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
26 changes: 20 additions & 6 deletions pogom/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def search_overseer_thread(args, new_location_queue, control_flags, heartb,
'accounts_captcha': 0,
'accounts_failed': 0,
'active_accounts': 0,
'busy_accounts': 0,
'skip_total': 0,
'captcha_total': 0,
'success_total': 0,
Expand Down Expand Up @@ -655,27 +656,39 @@ def get_stats_message(threadStatus, search_items_queue_array, db_updates_queue,
len(account_failures), len(account_captchas))

message += (
'Total active: {} | Success: {} ({:.1f}/hr) | ' +
'Fails: {} ({:.1f}/hr) | Empties: {} ({:.1f}/hr) | ' +
'Skips {} ({:.1f}/hr) | Captchas: {} ({:.1f}/hr) (${:.1f}/hr, ' +
'${:.1f}/mo) | Elapsed: {:.1f}h'
).format(overseer['active_accounts'], overseer['success_total'], sph,
'Total active: {}, busy: {}, idle: {} | ' +
'Success: {} ({:.1f}/hr) | ' +
'Fails: {} ({:.1f}/hr) | ' +
'Empties: {} ({:.1f}/hr) | ' +
'Skips {} ({:.1f}/hr) | ' +
'Captchas: {} ({:.2f}/hr)|${:.2f}/hr|${:.2f}/mo | ' +
'Elapsed: {:.1f}h'
).format(overseer['active_accounts'], overseer['busy_accounts'],
(overseer['active_accounts'] - overseer['busy_accounts']),
overseer['success_total'], sph,
overseer['fail_total'], fph, overseer['empty_total'], eph,
overseer['skip_total'], skph, overseer['captcha_total'], cph,
ccost, cmonth, elapsed / 3600.0)

return message


def update_total_stats(threadStatus, last_account_status):
overseer = threadStatus['Overseer']
# Calculate totals.
active_count = 0
busy_count = 0
current_accounts = Set()
for tstatus in threadStatus.itervalues():
if tstatus.get('type', '') == 'Worker':
if tstatus.get('active', False):

is_active = tstatus.get('active', False)
if is_active:
active_count += 1

if is_active and tstatus.get('message', '') != 'Nothing to scan.':
busy_count += 1

username = tstatus.get('username', '')
current_accounts.add(username)
last_status = last_account_status.get(username, {})
Expand All @@ -696,6 +709,7 @@ def update_total_stats(threadStatus, last_account_status):
}

overseer['active_accounts'] = active_count
overseer['busy_accounts'] = busy_count

# Remove last status for accounts that workers
# are not using anymore
Expand Down
57 changes: 32 additions & 25 deletions static/js/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ var showInstances = true
var showWorkers = true
var hashkeys = {}
var statshash = 'summarystats' /* unique statistics worker name */
var active
var success
var failed
var empty
var skipped
var captcha
var scansSuccess
var scansFailed
var scansEmpty
var scansSkipped
var captchasCount
var mainWorkers
var elapsedTotal
var elapsedSecs
Expand Down Expand Up @@ -357,11 +356,11 @@ function addStatsWorker(hash) {
}

function getStats(i, worker) {
success += worker['success']
failed += worker['fail']
empty += worker['empty']
skipped += worker['skip']
captcha += worker['captcha']
scansSuccess += worker['success']
scansFailed += worker['fail']
scansEmpty += worker['empty']
scansSkipped += worker['skip']
captchasCount += worker['captcha']
mainWorkers += 1

elapsedTotal += worker['elapsed']
Expand All @@ -371,13 +370,11 @@ function getStats(i, worker) {

function addTotalStats(result) {
var statmsg, title

active = 0
success = 0
failed = 0
empty = 0
skipped = 0
captcha = 0
scansSuccess = 0
scansFailed = 0
scansEmpty = 0
scansSkipped = 0
captchasCount = 0
mainWorkers = 0
elapsedTotal = 0
elapsedSecs = 0
Expand All @@ -393,24 +390,34 @@ function addTotalStats(result) {
$.each(result.main_workers, getStats)

if ((mainWorkers > 1) || !(showWorkers && showInstances)) {
active += result.workers.length
const accountsActive = result.workers.length

// Calculate the number of idle workers and then busy from that.
const accountsIdle = result.workers.reduce((accumulator, account) => {
if (account['message'] === 'Nothing to scan.') {
accumulator += 1
}
return accumulator
}, 0)

const accountsBusy = result.workers.length - accountsIdle

// Avoid division by zero.
elapsedSecs = Math.max(elapsedSecs, 1)

successPerHour = (success * 3600 / elapsedSecs) || 0
failsPerHour = (failed * 3600 / elapsedSecs) || 0
emptyPerHour = (empty * 3600 / elapsedSecs) || 0
skippedPerHour = (skipped * 3600 / elapsedSecs) || 0
captchasPerHour = (captcha * 3600 / elapsedSecs) || 0
successPerHour = (scansSuccess * 3600 / elapsedSecs) || 0
failsPerHour = (scansFailed * 3600 / elapsedSecs) || 0
emptyPerHour = (scansEmpty * 3600 / elapsedSecs) || 0
skippedPerHour = (scansSkipped * 3600 / elapsedSecs) || 0
captchasPerHour = (captchasCount * 3600 / elapsedSecs) || 0
captchasCost = captchasPerHour * 0.00299
captchasCostMonthly = captchasCost * 730

if ($('#worker_' + statshash).length === 0) {
addStatsWorker(statshash)
}

statmsg = 'Total active: ' + active + ' | Success: ' + success.toFixed() + ' (' + successPerHour.toFixed(1) + '/hr) | Fails: ' + failed.toFixed() + ' (' + failsPerHour.toFixed(1) + '/hr) | Empties: ' + empty.toFixed() + ' (' + emptyPerHour.toFixed(1) + '/hr) | Skips: ' + skipped.toFixed() + ' (' + skippedPerHour.toFixed(1) + '/hr) | Captchas: ' + captcha.toFixed() + ' (' + captchasPerHour.toFixed(1) + '/hr) ($' + captchasCost.toFixed(1) + '/hr, $' + captchasCostMonthly.toFixed(1) + '/mo) | Elapsed: ' + elapsedHours.toFixed(1) + 'h<hr />'
statmsg = 'Total active: ' + accountsActive + ', busy: ' + accountsBusy + ', idle: ' + accountsIdle + ' | Success: ' + scansSuccess.toFixed() + ' (' + successPerHour.toFixed(1) + '/hr) | Fails: ' + scansFailed.toFixed() + ' (' + failsPerHour.toFixed(1) + '/hr) | Empties: ' + scansEmpty.toFixed() + ' (' + emptyPerHour.toFixed(1) + '/hr) | Skips: ' + scansSkipped.toFixed() + ' (' + skippedPerHour.toFixed(1) + '/hr) | Captchas: ' + captchasCount.toFixed() + ' (' + captchasPerHour.toFixed(1) + '/hr) ($' + captchasCost.toFixed(2) + '/hr, $' + captchasCostMonthly.toFixed(2) + '/mo) | Elapsed: ' + elapsedHours.toFixed(1) + 'h<hr />'
if (mainWorkers > 1) {
title = '(Total Statistics across ' + mainWorkers + ' instances)'
} else {
Expand Down

0 comments on commit e03a1d5

Please sign in to comment.