mirror of
https://github.com/danog/MadelineProto.git
synced 2024-11-30 06:18:58 +01:00
Improve counters
This commit is contained in:
parent
75bc23ccc0
commit
be472eaadd
@ -60,7 +60,7 @@ final class CheckLoop extends Loop
|
|||||||
}
|
}
|
||||||
if ($this->shared->hasTempAuthKey()) {
|
if ($this->shared->hasTempAuthKey()) {
|
||||||
$full_message_ids = $this->connection->getPendingCalls();
|
$full_message_ids = $this->connection->getPendingCalls();
|
||||||
foreach (array_chunk($full_message_ids, 8192) as $message_ids) {
|
foreach (array_chunk($full_message_ids, WriteLoop::MAX_IDS) as $message_ids) {
|
||||||
$deferred = new DeferredFuture();
|
$deferred = new DeferredFuture();
|
||||||
$list = '';
|
$list = '';
|
||||||
// Don't edit this here pls
|
// Don't edit this here pls
|
||||||
|
@ -40,7 +40,7 @@ use function strlen;
|
|||||||
*/
|
*/
|
||||||
final class WriteLoop extends Loop
|
final class WriteLoop extends Loop
|
||||||
{
|
{
|
||||||
public const MAX_COUNT = 1020;
|
private const MAX_COUNT = 1020;
|
||||||
private const MAX_SIZE = 1 << 15;
|
private const MAX_SIZE = 1 << 15;
|
||||||
public const MAX_IDS = 8192;
|
public const MAX_IDS = 8192;
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ final class WriteLoop extends Loop
|
|||||||
|
|
||||||
$body_length = \strlen($message->getSerializedBody());
|
$body_length = \strlen($message->getSerializedBody());
|
||||||
$actual_length = $body_length + 32;
|
$actual_length = $body_length + 32;
|
||||||
if ($total_length && $total_length + $actual_length > 32760 || $count >= 1020) {
|
if ($total_length && $total_length + $actual_length > 32760 || $count >= self::MAX_COUNT) {
|
||||||
$this->API->logger('Length overflow, postponing part of payload', Logger::ULTRA_VERBOSE);
|
$this->API->logger('Length overflow, postponing part of payload', Logger::ULTRA_VERBOSE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -923,7 +923,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter
|
|||||||
*/
|
*/
|
||||||
private function cleanupProperties(): void
|
private function cleanupProperties(): void
|
||||||
{
|
{
|
||||||
$this->updateCtr = $this->getPromCounter("", "update_count", "Number of received updates since the session was created");
|
$this->updateCtr = $this->getPromCounter("MadelineProto", "update_count", "Number of received updates since the session was created");
|
||||||
// Start IPC server
|
// Start IPC server
|
||||||
if (!$this->ipcServer) {
|
if (!$this->ipcServer) {
|
||||||
$this->ipcServer = new Server($this);
|
$this->ipcServer = new Server($this);
|
||||||
|
@ -273,6 +273,14 @@ trait ResponseHandler
|
|||||||
}
|
}
|
||||||
$this->gotResponseForOutgoingMessage($request);
|
$this->gotResponseForOutgoingMessage($request);
|
||||||
|
|
||||||
|
if ($this->requestResponse !== null) {
|
||||||
|
$this->requestResponse->inc([
|
||||||
|
'method' => $request->constructor,
|
||||||
|
'error_message' => 'OK',
|
||||||
|
'error_code' => '200'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
EventLoop::queue($request->reply(...), $response);
|
EventLoop::queue($request->reply(...), $response);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -281,10 +289,12 @@ trait ResponseHandler
|
|||||||
*/
|
*/
|
||||||
private function handleRpcError(MTProtoOutgoingMessage $request, array $response): ?callable
|
private function handleRpcError(MTProtoOutgoingMessage $request, array $response): ?callable
|
||||||
{
|
{
|
||||||
if ($response['error_code'] === 420) {
|
if ($this->requestResponse !== null) {
|
||||||
$this->rpcErrors?->inc(['message' => preg_replace('/\d+/', '', $response['error_message']), 'code' => (string) $response['error_code']]);
|
$this->requestResponse->inc([
|
||||||
} else {
|
'method' => $request->constructor,
|
||||||
$this->rpcErrors?->inc(['message' => $response['error_message'], 'code' => (string) $response['error_code']]);
|
'error_message' => preg_replace('/\d+/', 'X', $response['error_message']),
|
||||||
|
'error_code' => (string) $response['error_code']
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
if ($request->isMethod
|
if ($request->isMethod
|
||||||
&& $request->constructor !== 'auth.bindTempAuthKey'
|
&& $request->constructor !== 'auth.bindTempAuthKey'
|
||||||
|
@ -23,6 +23,7 @@ namespace danog\MadelineProto\MTProtoSession;
|
|||||||
use Amp\Sync\LocalKeyedMutex;
|
use Amp\Sync\LocalKeyedMutex;
|
||||||
use danog\BetterPrometheus\BetterCounter;
|
use danog\BetterPrometheus\BetterCounter;
|
||||||
use danog\BetterPrometheus\BetterGauge;
|
use danog\BetterPrometheus\BetterGauge;
|
||||||
|
use danog\BetterPrometheus\BetterHistogram;
|
||||||
use danog\MadelineProto\Logger;
|
use danog\MadelineProto\Logger;
|
||||||
use danog\MadelineProto\MTProto\MTProtoIncomingMessage;
|
use danog\MadelineProto\MTProto\MTProtoIncomingMessage;
|
||||||
use danog\MadelineProto\MTProto\MTProtoOutgoingMessage;
|
use danog\MadelineProto\MTProto\MTProtoOutgoingMessage;
|
||||||
@ -47,7 +48,10 @@ trait Session
|
|||||||
public ?BetterCounter $outgoingCtr = null;
|
public ?BetterCounter $outgoingCtr = null;
|
||||||
public ?BetterCounter $incomingBytesCtr = null;
|
public ?BetterCounter $incomingBytesCtr = null;
|
||||||
public ?BetterCounter $outgoingBytesCtr = null;
|
public ?BetterCounter $outgoingBytesCtr = null;
|
||||||
public ?BetterCounter $rpcErrors = null;
|
|
||||||
|
public ?BetterHistogram $requestLatencies = null;
|
||||||
|
|
||||||
|
public ?BetterCounter $requestResponse = null;
|
||||||
/**
|
/**
|
||||||
* Incoming message array.
|
* Incoming message array.
|
||||||
*
|
*
|
||||||
@ -185,7 +189,8 @@ trait Session
|
|||||||
$this->outgoingCtr = $this->API->getPromCounter("MadelineProto", "outgoing_mtproto_messages", "Number of sent MTProto messages", $labels);
|
$this->outgoingCtr = $this->API->getPromCounter("MadelineProto", "outgoing_mtproto_messages", "Number of sent MTProto messages", $labels);
|
||||||
$this->incomingBytesCtr = $this->API->getPromCounter("MadelineProto", "incoming_bytes", "Number of received bytes", $labels);
|
$this->incomingBytesCtr = $this->API->getPromCounter("MadelineProto", "incoming_bytes", "Number of received bytes", $labels);
|
||||||
$this->outgoingBytesCtr = $this->API->getPromCounter("MadelineProto", "outgoing_bytes", "Number of sent bytes", $labels);
|
$this->outgoingBytesCtr = $this->API->getPromCounter("MadelineProto", "outgoing_bytes", "Number of sent bytes", $labels);
|
||||||
$this->rpcErrors = $this->API->getPromCounter("MadelineProto", "rpc_errors", "Number of received RPC errors by type", $labels);
|
$this->requestResponse = $this->API->getPromCounter("MadelineProto", "request_responses", "Received RPC error or success status of requests by method.", $labels);
|
||||||
|
$this->requestLatencies = $this->API->getPromHistogram("MadelineProto", "request_latencies", "Request latency by method", $labels);
|
||||||
if ($this->session_id === null) {
|
if ($this->session_id === null) {
|
||||||
$this->resetSession("creating initial session");
|
$this->resetSession("creating initial session");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user