diff --git a/public/language/en-GB/admin/settings/activitypub.json b/public/language/en-GB/admin/settings/activitypub.json index 901ea81c8b..cb47982f7d 100644 --- a/public/language/en-GB/admin/settings/activitypub.json +++ b/public/language/en-GB/admin/settings/activitypub.json @@ -66,5 +66,7 @@ "content.world-default-cid": "Default category ID for "World" page composer", "analytics.intro": "From this page you can view the state of your instance's federation with other servers", - "analytics.activities": "Received Activities" + "analytics.by-hostname": "Filter by Hostname", + "analytics.activities": "Received Activities", + "analytics.sent": "Sent Activites" } \ No newline at end of file diff --git a/public/src/admin/federation/analytics.js b/public/src/admin/federation/analytics.js index dc6c4ca0b3..86a7f8047e 100644 --- a/public/src/admin/federation/analytics.js +++ b/public/src/admin/federation/analytics.js @@ -27,17 +27,20 @@ export function init() { const hostFilterEl = document.getElementById('hostFilter'); if (hostFilterEl) { hostFilterEl.addEventListener('change', async function () { - const { activities } = await get(`/api${ajaxify.data.url}?host=${this.value}`); - const chart = charts.get('activities'); - chart.data.datasets[0].data = activities; - chart.update(); + const data = await get(`/api${ajaxify.data.url}?host=${this.value}`); + + ['activities', 'sent'].forEach((name) => { + const chart = charts.get(name); + chart.data.datasets[0].data = data[name]; + chart.update(); + }); }); } } function initializeCharts() { const activitiesCanvas = document.getElementById('activities'); - // const dailyCanvas = document.getElementById('pageviews:daily'); + const sentCanvas = document.getElementById('sent'); // const topicsCanvas = document.getElementById('topics:daily'); // const postsCanvas = document.getElementById('posts:daily'); const hourlyLabels = utils.getHoursArray().map(function (text, idx) { @@ -73,19 +76,19 @@ function initializeCharts() { }, ], }, - // 'pageviews:daily': { - // labels: dailyLabels, - // datasets: [ - // { - // ...commonDataSetOpts, - // backgroundColor: 'rgba(151,187,205,0.2)', - // borderColor: 'rgba(151,187,205,1)', - // pointBackgroundColor: 'rgba(151,187,205,1)', - // pointHoverBorderColor: 'rgba(151,187,205,1)', - // data: ajaxify.data.analytics['pageviews:daily'], - // }, - // ], - // }, + 'sent': { + labels: hourlyLabels, + datasets: [ + { + ...commonDataSetOpts, + backgroundColor: 'rgba(151,187,205,0.2)', + borderColor: 'rgba(151,187,205,1)', + pointBackgroundColor: 'rgba(151,187,205,1)', + pointHoverBorderColor: 'rgba(151,187,205,1)', + data: ajaxify.data.sent, + }, + ], + }, // 'topics:daily': { // labels: dailyLabels.slice(-7), // datasets: [ @@ -115,7 +118,7 @@ function initializeCharts() { }; activitiesCanvas.width = $(activitiesCanvas).parent().width(); - // dailyCanvas.width = $(dailyCanvas).parent().width(); + sentCanvas.width = $(sentCanvas).parent().width(); // topicsCanvas.width = $(topicsCanvas).parent().width(); // postsCanvas.width = $(postsCanvas).parent().width(); @@ -135,14 +138,13 @@ function initializeCharts() { data: data.activities, options: chartOpts, })], + ['sent', new Chart(sentCanvas.getContext('2d'), { + type: 'line', + data: data.sent, + options: chartOpts, + })], ]); - // new Chart(dailyCanvas.getContext('2d'), { - // type: 'line', - // data: data['pageviews:daily'], - // options: chartOpts, - // }); - // new Chart(topicsCanvas.getContext('2d'), { // type: 'line', // data: data['topics:daily'], diff --git a/src/activitypub/index.js b/src/activitypub/index.js index 43e06b8664..e66becbea9 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -381,6 +381,7 @@ ActivityPub._sendMessage = async function (uri, id, type, payload) { }); if (String(response.statusCode).startsWith('2')) { + ActivityPub.record.send(payload.type, uri); ActivityPub.helpers.log(`[activitypub/send] Successfully sent ${payload.type} to ${uri}`); return true; } @@ -455,7 +456,9 @@ ActivityPub.send = async (type, id, targets, payload) => { }).catch(err => winston.error(err.stack)); }; -ActivityPub.record = async ({ id, type, actor }) => { +ActivityPub.record = {}; + +ActivityPub.record.receipt = async ({ id, type, actor }) => { const now = Date.now(); const { hostname } = new URL(actor); @@ -466,6 +469,15 @@ ActivityPub.record = async ({ id, type, actor }) => { ]); }; +ActivityPub.record.send = async ({ type, target }) => { + const { hostname } = new URL(target); + + await Promise.all([ + ActivityPub.instances.log(hostname), + analytics.increment(['ap.out', `ap.out:byType:${type}`, `ap.out:byHost:${hostname}`]), + ]); +}; + ActivityPub.buildRecipients = async function (object, options) { /** * - Builds a list of targets for activitypub.send to consume diff --git a/src/controllers/activitypub/index.js b/src/controllers/activitypub/index.js index b7eaa334c8..6291a451b0 100644 --- a/src/controllers/activitypub/index.js +++ b/src/controllers/activitypub/index.js @@ -269,7 +269,7 @@ Controller.postInbox = async (req, res) => { try { await activitypub.inbox[method](req); - await activitypub.record(req.body); + await activitypub.record.receipt(req.body); await helpers.formatApiResponse(202, res); } catch (e) { helpers.formatApiResponse(500, res, e).catch(err => winston.error(err.stack)); diff --git a/src/controllers/admin/federation.js b/src/controllers/admin/federation.js index d18ef06176..c2fe092a9d 100644 --- a/src/controllers/admin/federation.js +++ b/src/controllers/admin/federation.js @@ -61,11 +61,14 @@ federationController.analytics = async function (req, res) { host = undefined; } const set = host ? `activities:byHost:${host}` : 'activities'; + const sentSet = host ? `ap.out:byHost:${host}` : 'ap:out'; const activities = await analytics.getHourlyStatsForSet(set, Date.now(), 24); + const sent = await analytics.getHourlyStatsForSet(sentSet, Date.now(), 24); res.render('admin/federation/analytics', { title: '[[admin/menu:federation/analytics]]', instances, activities, + sent, }); }; diff --git a/src/views/admin/federation/analytics.tpl b/src/views/admin/federation/analytics.tpl index 5271e48b5a..82373f46db 100644 --- a/src/views/admin/federation/analytics.tpl +++ b/src/views/admin/federation/analytics.tpl @@ -3,12 +3,10 @@
-
-

[[admin/settings/activitypub:analytics.intro]]

-
-
- +

[[admin/settings/activitypub:analytics.intro]]

+ +
+
+
+ +
+
[[admin/settings/activitypub:analytics.activities]]
@@ -26,6 +29,17 @@
+ +
+
+
[[admin/settings/activitypub:analytics.sent]]
+
+
+ +
+
+
+