]> git.mxchange.org Git - friendica.git/commitdiff
Count inbound and outbound packets
authorMichael <heluecht@pirati.ca>
Tue, 23 Jul 2024 11:38:04 +0000 (11:38 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 24 Jul 2024 20:50:46 +0000 (20:50 +0000)
13 files changed:
doc/tools.md
src/Model/Item.php
src/Module/ActivityPub/Inbox.php
src/Module/DFRN/Notify.php
src/Module/Diaspora/Receive.php
src/Module/OStatus/PubSub.php
src/Module/OStatus/Salmon.php
src/Module/Stats.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/Salmon.php
src/Util/HTTPSignature.php
src/Worker/Notifier.php

index fac1f4b392b12d8d3e6defeb40601b276deec07a..ef916553adcf7b5dcc7150a7b99e6c3ea301dd6b 100644 (file)
@@ -78,3 +78,9 @@ The following will compress */var/log/friendica* (assuming this is the location
                daily
                rotate 2
        }
+
+### Zabbix
+
+To monitor the health status of your Friendica installation, you can use for example a tool like Zabbix. Please define 'stats_key' in your local.config.php in the 'system' section to be able to access the statistics page at /stats?key=your-defined-stats_key
+
+The statistics contain data about the worker performance, the last cron call, number of reports, inbound and outbound packets, posts and comments.
index 72bf396bf370fb1ed43c26c305c0d9f14be61a0a..78430f1d161270df7162bd1fb7abf7189c67bd20 100644 (file)
@@ -4265,4 +4265,22 @@ class Item
                Logger::warning('Post does not exist although it was supposed to had been fetched.', ['id' => $id, 'url' => $url, 'uid' => $uid]);
                return 0;
        }
+
+       public static function incrementInbound(string $network)
+       {
+               $packets = DI::keyValue()->get('stats_packets_inbound_' . $network) ?? 0;
+               if ($packets >= PHP_INT_MAX) {
+                       $packets = 0;
+               }
+               DI::keyValue()->set('stats_packets_inbound_' . $network, $packets + 1);
+       }
+
+       public static function incrementOutbound(string $network)
+       {
+               $packets = DI::keyValue()->get('stats_packets_outbound_' . $network) ?? 0;
+               if ($packets >= PHP_INT_MAX) {
+                       $packets = 0;
+               }
+               DI::keyValue()->set('stats_packets_outbound_' . $network, $packets + 1);
+       }
 }
index 5b096c8045414ed9a2f1728abb092ad4e0c56ed2..b39081c443b46c42884d088ae532518ff9433022 100644 (file)
 namespace Friendica\Module\ActivityPub;
 
 use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Module\BaseApi;
 use Friendica\Module\Special\HTTPException;
@@ -103,6 +105,7 @@ class Inbox extends BaseApi
                        $uid = 0;
                }
 
+               Item::incrementInbound(Protocol::ACTIVITYPUB);
                ActivityPub\Receiver::processInbox($postdata, $_SERVER, $uid);
 
                throw new \Friendica\Network\HTTPException\AcceptedException();
index 2e6b3f0f98ba09f23cf07f97ef44b9514d3e7898..76701a036f313bb9442dab8e06861f626ccaad1e 100644 (file)
 namespace Friendica\Module\DFRN;
 
 use Friendica\BaseModule;
+use Friendica\Core\Protocol;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
+use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Module\Response;
 use Friendica\Network\HTTPException;
@@ -45,6 +47,8 @@ class Notify extends BaseModule
                        throw new HTTPException\BadRequestException();
                }
 
+               Item::incrementInbound(Protocol::DFRN);
+
                $data = json_decode($postdata);
                if (is_object($data) && !empty($this->parameters['nickname'])) {
                        $user = User::getByNickname($this->parameters['nickname']);
index 57835a37b7b714c1c00fbb809b90fe96df09154c..6678695ff54e3724cf23117ad7139dfd0756368c 100644 (file)
@@ -25,6 +25,8 @@ use Friendica\App;
 use Friendica\BaseModule;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
+use Friendica\Model\Item;
 use Friendica\Model\User;
 use Friendica\Module\Response;
 use Friendica\Network\HTTPException;
@@ -57,6 +59,8 @@ class Receive extends BaseModule
                        throw new HTTPException\ForbiddenException($this->t('Access denied.'));
                }
 
+               Item::incrementInbound(Protocol::DIASPORA);
+
                if ($this->parameters['type'] === 'public') {
                        $this->receivePublic();
                } else if ($this->parameters['type'] === 'users') {
index 34e4900578fe4dc316e0dd2e1864d1e13535c41f..bddf43cd3af25ae9e9259ac33aff32408b45aa7b 100644 (file)
@@ -28,6 +28,7 @@ use Friendica\Core\System;
 use Friendica\Database\Database;
 use Friendica\Model\Contact;
 use Friendica\Model\GServer;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Module\Response;
 use Friendica\Network\HTTPException;
@@ -101,6 +102,7 @@ class PubSub extends \Friendica\BaseModule
 
                $this->logger->info('Import item from Contact.', ['nickname' => $nickname, 'contact-nickname' => $contact['nick'], 'contact-id' => $contact['id']]);
                $feedhub = '';
+               Item::incrementOutbound(Protocol::OSTATUS);
                OStatus::import($xml, $importer, $contact, $feedhub);
 
                throw new HTTPException\OKException();
index 2707fcc4c31523dc1a753595baac3f58deeb334f..745dbba55b49b366b8bf1215553f6aea2c494bdb 100644 (file)
@@ -26,6 +26,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
 use Friendica\Database\Database;
 use Friendica\Model\GServer;
+use Friendica\Model\Item;
 use Friendica\Model\Post;
 use Friendica\Module\Response;
 use Friendica\Protocol\ActivityNamespace;
@@ -210,6 +211,7 @@ class Salmon extends \Friendica\BaseModule
 
                $contact = $contact ?: [];
 
+               Item::incrementOutbound(Protocol::OSTATUS);
                OStatus::import($data, $importer, $contact, $hub);
 
                throw new HTTPException\OKException();
index b5afb9a13a0629adaed3e998c4041e6be7237098..d8bc317fc47718b666e2199c9e348b1ca618103b 100644 (file)
@@ -26,6 +26,7 @@ use Friendica\BaseModule;
 use Friendica\Core\Config\Capability\IManageConfigValues;
 use Friendica\Core\KeyValueStorage\Capability\IManageKeyValuePairs;
 use Friendica\Core\L10n;
+use Friendica\Core\Protocol;
 use Friendica\Core\Worker;
 use Friendica\Database\Database;
 use Friendica\Model\Register;
@@ -116,6 +117,20 @@ class Stats extends BaseModule
                                        'comments' => intval($this->keyValue->get('nodeinfo_local_comments')),
                                ],
                        ],
+                       'packets' => [
+                               'inbound' => [
+                                       Protocol::ACTIVITYPUB => intval($this->keyValue->get('stats_packets_inbound_' . Protocol::ACTIVITYPUB) ?? 0),
+                                       Protocol::DFRN        => intval($this->keyValue->get('stats_packets_inbound_' . Protocol::DFRN) ?? 0),
+                                       Protocol::DIASPORA    => intval($this->keyValue->get('stats_packets_inbound_' . Protocol::DIASPORA) ?? 0),
+                                       Protocol::OSTATUS     => intval($this->keyValue->get('stats_packets_inbound_' . Protocol::OSTATUS) ?? 0),
+                               ],
+                               'outbound' => [
+                                       Protocol::ACTIVITYPUB => intval($this->keyValue->get('stats_packets_outbound_' . Protocol::ACTIVITYPUB) ?? 0),
+                                       Protocol::DFRN        => intval($this->keyValue->get('stats_packets_outbound_' . Protocol::DFRN) ?? 0),
+                                       Protocol::DIASPORA    => intval($this->keyValue->get('stats_packets_outbound_' . Protocol::DIASPORA) ?? 0),
+                                       Protocol::OSTATUS     => intval($this->keyValue->get('stats_packets_outbound_' . Protocol::OSTATUS) ?? 0),
+                               ]
+                       ],
                        'reports' => [
                                'newest' => [
                                        'datetime'  => $report_datetime,
index 7e64ac9bd3d836c6526333ae4d40d2a888e90bf4..3b979bc21f2d21d462796e259ba4d29fbf6c5cc8 100644 (file)
@@ -1011,6 +1011,7 @@ class DFRN
                $content_type = ($public_batch ? 'application/magic-envelope+xml' : 'application/json');
 
                $postResult = DI::httpClient()->post($dest_url, $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DFRN);
+               Item::incrementOutbound(Protocol::DFRN);
                $xml = $postResult->getBodyString();
 
                $curl_stat = $postResult->getReturnCode();
index 526ef11a900b618eacf8cf0d1f86b06913b10ea1..27cc43ca0767d2a00bbf3ddfdb91dcb3e4f3d6c0 100644 (file)
@@ -2971,6 +2971,7 @@ class Diaspora
 
                        $postResult = DI::httpClient()->post($dest_url . '/', $envelope, ['Content-Type' => $content_type], 0, HttpClientRequest::DIASPORA);
                        $return_code = $postResult->getReturnCode();
+                       Item::incrementOutbound(Protocol::DIASPORA);
                } else {
                        Logger::notice('test_mode');
                        return 200;
index d4331570a3ff78df64fffb251ea4be64681498ee..bfb374970ff2d4be0631f3f5a32b31eb0917843e 100644 (file)
@@ -22,7 +22,9 @@
 namespace Friendica\Protocol;
 
 use Friendica\Core\Logger;
+use Friendica\Core\Protocol;
 use Friendica\DI;
+use Friendica\Model\Item;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPClient\Client\HttpClientRequest;
 use Friendica\Network\Probe;
@@ -226,6 +228,7 @@ class Salmon
                        $return_code = $postResult->getReturnCode();
                }
 
+               Item::incrementOutbound(Protocol::OSTATUS);
                Logger::info('slapper for ' . $url . ' returned ' . $return_code);
 
                if (!$return_code) {
index 2cb224ef6fa2eee8ae3416443ee6ce111212c137..85a3ed396b788f1e33849d918b47f2794232cd3b 100644 (file)
@@ -29,6 +29,7 @@ use Friendica\DI;
 use Friendica\Model\APContact;
 use Friendica\Model\Contact;
 use Friendica\Model\GServer;
+use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
 use Friendica\Model\User;
 use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
@@ -309,6 +310,8 @@ class HTTPSignature
 
                self::setInboxStatus($target, ($return_code >= 200) && ($return_code <= 299));
 
+               Item::incrementOutbound(Protocol::ACTIVITYPUB);
+
                return $postResult;
        }
 
index 2fa2984bf71f030e1001afaf71678a061b1f5646..28456b6478c7f79423dfb95695f3bdbaf930f956 100644 (file)
@@ -655,6 +655,7 @@ class Notifier
 
                                $delivery_queue_count++;
                                Salmon::slapper($owner, $url, $slap);
+                               Item::incrementOutbound(Protocol::OSTATUS);
                                Post\DeliveryData::incrementQueueDone($target_item['uri-id'], Post\DeliveryData::OSTATUS);
                        }
                }