#!/bin/bash

send_viewer_fastindex () {
metric="webmaster-viewer-fastrobot-index"
amount=$(timetail -n 300 /var/log/webmaster/webmaster-viewer.log | grep -c FAST_ROBOT_HAS_INDEXED_MORE_PAGES)
gmetric -n $metric -v $amount -x 300 -t float
}

send_viewer_requests () {
metric="webmaster-viewer-requests"
amount=$(timetail -n 300 /var/log/webmaster/webmaster-viewer.log | grep -c Processing.time.for.request)
gmetric -n $metric -v $amount -x 300 -t float
}

send_viewer_errors () {
metric="webmaster-viewer-errors"
amount=$(timetail -n 300 /var/log/webmaster/webmaster-viewer.log | grep -c "\] ERROR \[")
gmetric -n $metric -v $amount -x 300 -t float
}

send_api_requests () {
metric="webmaster-api-requests"
amount=$(timetail -n 300 /var/log/webmaster/webmaster-viewer.log | grep -c "Call query for request api")
gmetric -n $metric -v $amount -x 300 -t float
}

send_api_errors () {
metric="webmaster-api-errors"
amount=$(timetail -n 300 /var/log/webmaster/webmaster-viewer.log | grep "\] ERROR \[" | grep -c "Exception in ru.yandex.wmconsole.servantlet.api.")
gmetric -n $metric -v $amount -x 300 -t float
}

send_addurl_errors () {
metric="webmaster-addurl-errors"
amount=$(timetail -n 300 /var/log/webmaster/webmaster-viewer.log | grep -c CALLADDURL_PROBLEM)
gmetric -n $metric -v $amount -x 300 -t float
}

send_fullgc_count () {
metric="webmaster-viewer-fullgc"
amount=$(timetail -n 300 -r '^(\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d)' /var/log/webmaster/webmaster-viewer-gc.log | grep -c 'Full GC')
gmetric -n $metric -v $amount -x 300 -t float
}

test -e /usr/bin/gmetric || exit 0
$1
