better response time

This commit is contained in:
tree 2023-07-02 12:30:50 +00:00
rodič c702712c42
revize cf4dd39788
6 změnil soubory, kde provedl 61 přidání a 40 odebrání

Zobrazit soubor

@ -2,6 +2,7 @@ import { ATScan } from "./lib/atscan.js";
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
import { oakCors } from "https://deno.land/x/cors/mod.ts";
import { minidenticon } from "npm:minidenticons@4.2.0";
import _ from "npm:lodash";
const ats = new ATScan();
await ats.init();
@ -41,6 +42,26 @@ function findDIDFed(item) {
return ff ? ff.id : null;
}
function prepareObject(type, item) {
switch (type) {
case "pds":
item.host = item.url.replace(/^https?:\/\//, "");
item.fed = findPDSFed(item);
item.status = !item.inspect
? "unknown"
: (item.inspect?.current.err ? "offline" : "online");
const respTimes = Object.keys(item.inspect).filter((k) =>
!["current", "lastOnline"].includes(k)
).map((k) => item.inspect[k].ms || null).filter((k) => k);
item.responseTime = !item.inspect || item.status !== "online"
? null
: (respTimes.length > 0 ? _.mean(respTimes) : null);
break;
}
return item;
}
router
.get("/", (ctx) => {
ctx.response.body = "ATScan API";
@ -53,8 +74,7 @@ router
console.error("PDS without url? ", item);
continue;
}
item.host = item.url.replace(/^https?:\/\//, "");
item.fed = findPDSFed(item);
Object.assign(item, prepareObject("pds", item));
//item.didsCount = await ats.db.did.countDocuments({ 'pds': { $in: [ item.url ] }})
out.push(item);
}
@ -72,8 +92,7 @@ router
if (!item) {
return ctx.response.code = 404;
}
item.host = item.url.replace(/^https?:\/\//, "");
item.fed = findPDSFed(item);
Object.assign(item, prepareObject("pds", item));
const query = `
from(bucket: "ats-stats")

Zobrazit soubor

@ -1,6 +1,6 @@
{
"name": "atscan-fe",
"version": "0.6.0-alpha",
"version": "0.6.1-alpha",
"private": true,
"scripts": {
"dev": "vite dev",

Zobrazit soubor

@ -44,16 +44,8 @@
if (key === 'host') {
val = `<a href="/pds/${val}" class=""><span class="font-semibold text-lg">${val}</span></a>`;
}
if (key === 'ms') {
val = row.inspect?.current.err
? `<a href="${row.url}/xrpc/com.atproto.server.describeServer" target="_blank" title="${row.inspect.current.err}" class="anchor">error</a>`
: row.inspect?.current.ms
? `<a href="${
row.url
}/xrpc/com.atproto.server.describeServer" target="_blank" class="anchor">${
row.inspect.current.ms + 'ms'
}</a>`
: '-';
if (key === 'responseTime') {
val = row.responseTime ? '~' + row.responseTime + 'ms' : '-';
}
if (key === 'location') {
val =
@ -80,7 +72,11 @@
}
if (key === 'lastOnline' && row.inspect) {
val = `<span class="text-xs">${
row.inspect?.lastOnline ? dateDistance(row.inspect?.lastOnline) + ' ago' : '-'
row.inspect.lastOnline && !row.inspect?.current?.err
? 'now'
: row.inspect.lastOnline
? dateDistance(row.inspect.lastOnline) + ' ago'
: '-'
}</span>`;
}
if (key === 'host_raw') {
@ -106,12 +102,12 @@
['DIDs', 'didsCount'],
['Location', 'country'],
['PLCs (User Domains)', 'plcs'],
['Resp. time', 'ms'],
['Resp. time', 'responseTime'],
['Last Online', 'lastOnline']
],
body: customTableMapper(
sourceData,
['fed', 'status', 'host', 'didsCount', 'location', 'plcs', 'ms', 'lastOnline'],
['fed', 'status', 'host', 'didsCount', 'location', 'plcs', 'responseTime', 'lastOnline'],
tableMap
),
meta: customTableMapper(sourceData, ['host_raw', 'url'], tableMap)

Zobrazit soubor

@ -60,11 +60,12 @@ export function isDarkMode(document) {
}
export function getPDSStatus(row) {
const [color, ico, text] = !row.inspect
? ['text-gray-500', null, 'Status unknown']
: row.inspect?.current.err
? ['text-red-500', null, 'Offline']
: ['text-green-500', null, 'Online'];
const [color, ico, text] =
row.status === 'unknown'
? ['text-gray-500', null, 'Status unknown']
: row.status === 'offline'
? ['text-red-500', null, 'Offline']
: ['text-green-500', null, 'Online'];
return { color, ico, text };
}

Zobrazit soubor

@ -44,7 +44,7 @@
let base = JSON.parse(JSON.stringify(bd)); //.filter(d => d.inspect?.lastOnline)
base = base.map((i) => {
i.country = i.ip?.country;
i.ms = !i.inspect?.current.err ? i.inspect?.current?.ms : null;
//i.ms = !i.inspect?.current.err ? i.inspect?.current?.ms : null;
i.lastOnline = i.inspect?.lastOnline;
return i;
});

Zobrazit soubor

@ -1,12 +1,7 @@
<script>
import Breadcrumb from '$lib/components/Breadcrumb.svelte';
import DIDTable from '$lib/components/DIDTable.svelte';
import {
formatNumber,
dateDistance,
getFlagEmoji,
getPDSStatus
} from '$lib/utils.js';
import { formatNumber, dateDistance, getFlagEmoji, getPDSStatus } from '$lib/utils.js';
import SourceSection from '$lib/components/SourceSection.svelte';
import BasicPage from '$lib/components/BasicPage.svelte';
import Chart from '$lib/components/Chart.svelte';
@ -32,6 +27,12 @@
title: 'User domains',
value: item.inspect?.current?.data?.availableUserDomains?.join(', ') || 'n/a'
},
{
title: 'Invite code required?',
value: item.inspect?.current?.data?.inviteCodeRequired
? 'Yes'
: 'No - open registrations' || 'n/a'
},
{
title: 'DID count',
value: `${formatNumber(item.didsCount)} (<a href="/dids?q=pds:${
@ -44,20 +45,20 @@
value: item.inspect?.current?.ms
? item.inspect?.current?.ms + 'ms (from Central Europe)'
: `Error`
}*/ /*{
}*/ {
title: 'Last online',
value:
(item.inspect?.lastOnline
? `${dateDistance(item.inspect?.lastOnline)} ago (${item.inspect?.lastOnline})`
: 'never') +
` (<a href="${item.url}/xrpc/com.atproto.server.describeServer" class="anchor">inspect</a>)`
},
} /*
item.inspect?.current?.err
? {
title: 'Error',
value: item.inspect?.current?.err ? `${item.inspect.current.err}` : '-'
}
: null,*/
: null,*/,
{
title: 'Last scan',
value: item.inspect?.current?.time
@ -98,21 +99,18 @@
const crawlers = {
local: {
location: 'Prague, CZ',
icon: '🇨🇿',
country: 'cz',
region: 'Central Europe'
},
texas: {
location: 'Texas, US',
icon: '🇺🇸',
country: 'us',
region: 'North America'
}
};
$: chartResponseTimes = {
animationDuration: 500,
title: {
text: `${item.host} response times in last 24 hours`
},
animationDuration: 250,
tooltip: {
trigger: 'axis'
//formatter: '{b}: {c} ms'
@ -206,7 +204,14 @@
{#each Object.keys(crawlers).map((c) => [c, crawlers[c]]) as [crawlerId, crawler]}
<tr>
<td>{crawler.region}</td>
<td>{crawler.location} {crawler.icon}</td>
<td
><img
src="/cc/{crawler.country.toLowerCase()}.png"
alt={crawler.country}
title={crawler.country}
class="inline-block mr-2"
/>{crawler.location}</td
>
<td
>{#if item.inspect[crawlerId]?.err}
<i class="fa-solid fa-circle text-red-500 text-xs mr-1" /> Error: