A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
usage on dashboard
aminnausin0f5e572e6a46
diff --git a/resources/js/components/cards/DashboardCard.vue b/resources/js/components/cards/DashboardCard.vueindex cd123c65..c97f1d9e 100644--- a/resources/js/components/cards/DashboardCard.vue+++ b/resources/js/components/cards/DashboardCard.vue@@ -28,8 +28,6 @@ const props = withDefaults(<slot name="icon"></slot></div><hgroup class="flex flex-wrap items-baseline gap-x-2 overflow-hidden">- <!-- <h2 class="text-base font-bold text-gray-600 dark:text-gray-300 truncate" @if($attributes->- has('x-bind:title')) x-bind:title="{{ $attributes->get('x-bind:title') }}" @else :title="{{ title }}" @endif> --><h2 class="text-base font-bold text-gray-600 dark:text-gray-300 truncate" :title="props.title">{{ props.name }}</h2>@@ -39,14 +37,11 @@ const props = withDefaults(</hgroup></div></div>- <!-- @if ($actions ?? false) --><div class="flex flex-grow"><div class="w-full flex items-center gap-4">- <!-- {{ $actions }} --><slot name="actions"></slot></div></div>- <!-- @endif --></header><slot name="slot"></slot></div>diff --git a/resources/js/components/dashboard/DashboardAnalytics.vue b/resources/js/components/dashboard/DashboardAnalytics.vueindex 7f657515..e3712cee 100644--- a/resources/js/components/dashboard/DashboardAnalytics.vue+++ b/resources/js/components/dashboard/DashboardAnalytics.vue@@ -10,6 +10,7 @@ import LucideChartNoAxesCombined from '~icons/lucide/chart-no-axes-combined';import PulseQueues from '../pulseCards/PulseQueues.vue';import DashboardCard from '../cards/DashboardCard.vue';import { periodForHumans } from '@/service/util';+import PulseUsage from '../pulseCards/PulseUsage.vue';const validPeriods: { key: string; value: string }[] = [{ key: '1h', value: '1_hour' },@@ -80,7 +81,8 @@ watch(</span></template></DashboardCard>- <PulseQueues :pulseData="pulseData" :isLoading="pulseLoading" :period="period" :cols="4" :rows="2" />+ <PulseUsage :pulseData="pulseData" :isLoading="pulseLoading" :period="period" :rows="4" />+ <PulseQueues :pulseData="pulseData" :isLoading="pulseLoading" :period="period" :rows="2" /></span></section></template>diff --git a/resources/js/components/pinesUI/InputSelect.vue b/resources/js/components/pinesUI/InputSelect.vueindex a893b425..48bb8a1c 100755--- a/resources/js/components/pinesUI/InputSelect.vue+++ b/resources/js/components/pinesUI/InputSelect.vue@@ -5,6 +5,10 @@ import { onMounted, ref, watch } from 'vue';import { OnClickOutside } from '@vueuse/components';const props = defineProps({+ class: {+ type: String,+ default: '',+ },placeholder: {type: String,default: 'Select Item',@@ -114,8 +118,7 @@ watch(<buttonref="selectButton"@click="select.toggleSelect()"- :class="{ 'hocus:ring-0': select.selectOpen }"- class="relative h-10 flex items-center justify-between w-full py-2 pl-3 pr-10 text-left rounded-md shadow-sm cursor-pointer text-sm border-none focus:outline-none ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 hocus:ring-[0.125rem] hover:ring-violet-400 hover:dark:ring-violet-700 focus:ring-indigo-400 dark:focus:ring-indigo-500 text-gray-900 dark:text-neutral-100 bg-white dark:bg-neutral-800"+ :class="`${select.selectOpen && 'hocus:ring-0'} relative h-10 flex items-center justify-between w-full py-2 pl-3 pr-10 text-left rounded-md shadow-sm cursor-pointer text-sm border-none focus:outline-none ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 hocus:ring-[0.125rem] hover:ring-violet-400 hover:dark:ring-violet-700 focus:ring-indigo-400 dark:focus:ring-indigo-500 text-gray-900 dark:text-neutral-100 bg-white dark:bg-neutral-800 ${props.class}`"><span class="truncate">{{ select.selectedItem ? select.selectedItem.title : placeholder }}</span><span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">diff --git a/resources/js/components/pinesUI/ToastController.vue b/resources/js/components/pinesUI/ToastController.vueindex 51ff8509..1f5ec18e 100755--- a/resources/js/components/pinesUI/ToastController.vue+++ b/resources/js/components/pinesUI/ToastController.vue@@ -1,6 +1,8 @@<script>-import ToastEventBus from '../../service/toastEventBus';-import ToastNotification from '../pinesUI/ToastNotification.vue';+// This is so bad lol pls fix++import ToastEventBus from '@/service/toastEventBus';+import ToastNotification from '@/components/pinesUI/ToastNotification.vue';var messageIdx = 0;diff --git a/resources/js/components/pulse/PulseUserCard.vue b/resources/js/components/pulse/PulseUserCard.vueindex 449dbebd..fc51bde4 100644--- a/resources/js/components/pulse/PulseUserCard.vue+++ b/resources/js/components/pulse/PulseUserCard.vue@@ -1,8 +1,8 @@<script setup lang="ts">-const props = defineProps<{ user?: any; name?: any; extra?: any; avatar?: any; stats?: any }>();+const props = defineProps<{ user: { name: string; extra?: any; avatar?: string } }>();</script><template>- <div class="flex items-center justify-between p-3 gap-3 bg-gray-50 dark:bg-gray-800/50 rounded">+ <div class="flex items-center justify-between p-4 gap-2 rounded-md dark:bg-primary-dark-800/70 bg-primary-900 ring-1 ring-gray-900/10"><div class="flex items-center gap-3 overflow-hidden"><imgv-if="props.user.avatar ?? false"@@ -13,46 +13,18 @@ const props = defineProps<{ user?: any; name?: any; extra?: any; avatar?: any; s/><div class="overflow-hidden">- <div class="text-sm text-gray-900 dark:text-gray-100 font-medium truncate" title="{{ $user->name ?? $name }}">- {{ user.name ?? name }}+ <div class="text-sm text-gray-900 dark:text-gray-100 font-medium truncate" :title="user.name">+ {{ user.name }}</div>- <div class="text-xs text-gray-500 dark:text-gray-400 truncate" title="{{ $user->name ?? $extra }}">- {{ user.extra ?? extra }}+ <div class="text-xs text-gray-500 dark:text-gray-400 truncate" :title="user.name ?? user.extra">+ {{ user.extra }}</div></div></div>- <div v-if="props.stats" class="text-xl text-gray-900 dark:text-gray-100 font-bold tabular-nums">- {{ props.stats }}+ <div class="text-xl text-gray-900 dark:text-gray-100 font-bold tabular-nums">+ <slot name="stats"> </slot></div></div></template>--<!-- @props(['user' => null, 'name' => null, 'extra' => null, 'avatar' => null, 'stats' => null])--<div {{ $attributes->merge(['class' => 'flex items-center justify-between p-3 gap-3 bg-gray-50 dark:bg-gray-800/50 rounded']) }}>- <div class="flex items-center gap-3 overflow-hidden">- @if (isset($avatar))- {{ $avatar }}- @elseif ($user->avatar ?? false)- <img src="{{ $user->avatar }}" alt="{{ $user->name }}" loading="lazy" class="rounded-full w-8 h-8 object-cover">- @endif-- <div class="overflow-hidden">- <div class="text-sm text-gray-900 dark:text-gray-100 font-medium truncate" title="{{ $user->name ?? $name }}">- {{ $user->name ?? $name }}- </div>-- <div class="text-xs text-gray-500 dark:text-gray-400 truncate" title="{{ $user->name ?? $extra }}">- {{ $user->extra ?? $extra }}- </div>- </div>- </div>-- @if (isset($stats))- <div class="text-xl text-gray-900 dark:text-gray-100 font-bold tabular-nums">- {{ $stats }}- </div>- @endif-</div> -->diff --git a/resources/js/components/pulseCards/PulseQueues.vue b/resources/js/components/pulseCards/PulseQueues.vueindex 1a9ee061..cbc5b3bb 100644--- a/resources/js/components/pulseCards/PulseQueues.vue+++ b/resources/js/components/pulseCards/PulseQueues.vue@@ -28,8 +28,6 @@ const props = withDefaults(const queues = ref<{ [key: string]: PulseQueueResponse }>();function scale(data: { [key: string]: any }) {- console.log(Object.values(data).map((value) => value * (1 / (props.pulseData?.queues?.config.sample_rate ?? 1))));-return Object.values(data).map((value) => value * (1 / (props.pulseData?.queues?.config.sample_rate ?? 1)));}@@ -183,11 +181,10 @@ watch(</script><template><DashboardCard- :cols="cols":rows="rows":class="props.class"name="Queues"- title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"+ :title="`Time: ${Intl.NumberFormat().format(pulseData?.queues?.time ?? 0)}ms; Run at: ${pulseData?.servers?.runAt ? new Date(pulseData?.servers?.runAt).toLocaleDateString() : ''};`":details="`past ${periodForHumans(period)}`"><template #icon>diff --git a/resources/js/components/pulseCards/PulseUsage.vue b/resources/js/components/pulseCards/PulseUsage.vuenew file mode 100644index 00000000..06405422--- /dev/null+++ b/resources/js/components/pulseCards/PulseUsage.vue@@ -0,0 +1,126 @@+<script setup lang="ts">+import type { PulseQueueResponse, PulseResponse, PulseServerResponse, PulseUsageResponse } from '@/types/types';++import { periodForHumans, pulseFormatDate } from '@/service/util';+import { ref, watch } from 'vue';++import IconQueueList from '../icons/IconQueueList.vue';+import DashboardCard from '../cards/DashboardCard.vue';+import PulseNoResults from '../pulse/PulseNoResults.vue';+import PulseScroll from '../pulse/PulseScroll.vue';+import PulseLineChart from '../charts/PulseLineChart.vue';+import IconCursorArrowRays from '../icons/IconCursorArrowRays.vue';+import IconArrowTrendingUp from '../icons/IconArrowTrendingUp.vue';+import IconClock from '../icons/IconClock.vue';+import IconScale from '../icons/IconScale.vue';+import InputSelect from '../pinesUI/InputSelect.vue';+import PulseUserCard from '../pulse/PulseUserCard.vue';++const requestOptions = [+ { value: 'requests', title: 'making requests' },+ { value: 'slow_requests', title: 'experiencing slow endpoints' },+ { value: 'jobs', title: 'dispatching jobs' },+];++const props = withDefaults(+ defineProps<{+ cols?: number | string;+ rows?: number;+ class?: string;+ pulseData?: PulseResponse;+ isLoading?: boolean;+ period: string;+ }>(),+ {+ cols: 2,+ rows: 4,+ },+);++const userRequestCounts = ref<PulseUsageResponse[]>();+const type = ref<'requests' | 'slow_requests' | 'jobs'>('requests');++const handleSetType = (newType: 'requests' | 'slow_requests' | 'jobs') => {+ type.value = newType;+};++const sampleRate = () => {+ switch (type.value) {+ case 'requests':+ return props.pulseData?.usage.userRequestsConfig.sample_rate ?? 1;+ case 'slow_requests':+ return props.pulseData?.usage.slowRequestsConfig.sample_rate ?? 1;+ default:+ return props.pulseData?.usage.jobsConfig.sample_rate ?? 1;+ }+};++watch(+ () => props.pulseData,+ () => {+ if (props.pulseData?.usage) {+ console.log(props?.pulseData?.usage.userRequestCounts);+ userRequestCounts.value = props.pulseData.usage.userRequestCounts;+ }+ },+);+</script>+<template>+ <DashboardCard+ :cols="cols"+ :rows="rows"+ :class="`${props.class} col-span-2 md:col-span-4`"+ :name="`${+ type === 'requests'+ ? 'Top 10 Users Making Requests'+ : type === 'slow_requests'+ ? 'Top 10 Users Experiencing Slow Endpoints'+ : type === 'jobs'+ ? 'Top 10 Users Dispatching Jobs'+ : 'Application Usage'+ }`"+ :title="`Time: ${Intl.NumberFormat().format(pulseData?.queues?.time ?? 0)}ms; Run at: ${pulseData?.servers?.runAt ? new Date(pulseData?.servers?.runAt).toLocaleDateString() : ''};`"+ :details="`past ${periodForHumans(period)}`"+ >+ <template #icon>+ <IconArrowTrendingUp v-if="type === 'requests'" />+ <IconClock v-else-if="type === 'slow_requests'" />+ <IconScale v-else-if="type === 'jobs'" />+ <IconCursorArrowRays v-else />+ </template>+ <template #actions>+ <span class="flex items-center text-sm">+ <label+ class="capitalize whitespace-nowrap h-10 flex items-center justify-between w-full py-2 p-3 text-left rounded-l-md shadow-sm text-sm ring-inset ring-1 ring-neutral-200 dark:ring-neutral-700 text-gray-900 dark:text-neutral-100 bg-primary-800 dark:bg-neutral-900"+ >Top 10 users</label+ >+ <InputSelect+ :placeholder="'None'"+ :options="requestOptions"+ class="flex-1 rounded-l-none capitalize !w-full !whitespace-nowrap"+ title="Select usage type"+ @selectItem="handleSetType"+ :defaultItem="0"+ />+ </span>+ </template>++ <template #slot>+ <PulseNoResults v-if="userRequestCounts?.length === 0" />+ <div v-else class="grid grid-cols-1 @lg:grid-cols-2 @3xl:grid-cols-3 @6xl:grid-cols-4 gap-2 overflow-visible">+ <PulseUserCard v-for="userRequestCount in userRequestCounts" :key="userRequestCount.key" :user="userRequestCount.user">+ <template #stats>+ <span+ v-if="sampleRate() < 1"+ title="Sample rate: {{ $sampleRate }}, Raw value: {{ number_format($userRequestCount->count) }}"+ >~{{ Intl.NumberFormat().format(userRequestCount.count * (1 / sampleRate())) }}</span+ >+ <template v-else>+ {{ Intl.NumberFormat().format(userRequestCount.count) }}+ </template>+ </template>+ </PulseUserCard>+ </div>+ </template>+ </DashboardCard>+</template>diff --git a/resources/js/components/pulseCards/usage.blade.php b/resources/js/components/pulseCards/usage.blade.phpdeleted file mode 100644index 11aad64a..00000000--- a/resources/js/components/pulseCards/usage.blade.php+++ /dev/null@@ -1,72 +0,0 @@-<x-pulse::card :cols="$cols" :rows="$rows" :class="$class">- <x-pulse::card-header- :name="match ($this->type) {- 'requests' => 'Top 10 Users Making Requests',- 'slow_requests' => 'Top 10 Users Experiencing Slow Endpoints',- 'jobs' => 'Top 10 Users Dispatching Jobs',- default => 'Application Usage'- }"- x-bind:title="`Time: {{ number_format($time) }}ms; Run at: ${formatDate('{{ $runAt }}')};`"- details="{{ $this->usage === 'slow_requests' ? (is_array($slowRequestsConfig['threshold']) ? '' : $slowRequestsConfig['threshold'].'ms threshold, ') : '' }}past {{ $this->periodForHumans() }}"- >- <x-slot:icon>- <x-dynamic-component :component="'pulse::icons.' . match ($this->type) {- 'requests' => 'arrow-trending-up',- 'slow_requests' => 'clock',- 'jobs' => 'scale',- default => 'cursor-arrow-rays'- }" />- </x-slot:icon>- <x-slot:actions>- @if (! $this->type)- <x-pulse::select- wire:model.live="usage"- label="Top 10 users"- :options="[- 'requests' => 'making requests',- 'slow_requests' => 'experiencing slow endpoints',- 'jobs' => 'dispatching jobs',- ]"- class="flex-1"- @change="loading = true"- />- @endif- @if ($this->usage === 'slow_requests' && is_array($slowRequestsConfig['threshold']))- @php- $message = 'You have per-route thresholds configured.';- @endphp- <button title="{{ $message }}" @click="alert(@js($message))">- <x-pulse::icons.information-circle class="w-5 h-5 stroke-gray-400 dark:stroke-gray-600" />- </button>- @endif- </x-slot:actions>- </x-pulse::card-header>-- <x-pulse::scroll :expand="$expand" wire:poll.5s="">- @if ($userRequestCounts->isEmpty())- <x-pulse::no-results />- @else- <div class="grid grid-cols-1 @lg:grid-cols-2 @3xl:grid-cols-3 @6xl:grid-cols-4 gap-2">- @php- $sampleRate = match($this->usage) {- 'requests' => $userRequestsConfig['sample_rate'],- 'slow_requests' => $slowRequestsConfig['sample_rate'],- 'jobs' => $jobsConfig['sample_rate'],- };- @endphp-- @foreach ($userRequestCounts as $userRequestCount)- <x-pulse::user-card wire:key="{{ $userRequestCount->key }}" :user="$userRequestCount->user">- <x-slot:stats>- @if ($sampleRate < 1)- <span title="Sample rate: {{ $sampleRate }}, Raw value: {{ number_format($userRequestCount->count) }}">~{{ number_format($userRequestCount->count * (1 / $sampleRate)) }}</span>- @else- {{ number_format($userRequestCount->count) }}- @endif- </x-slot:stats>- </x-pulse::user-card>- @endforeach- </div>- @endif- </x-pulse::scroll>-</x-pulse::card>diff --git a/resources/js/types/types.ts b/resources/js/types/types.tsindex a8e7ea57..82f5d4dc 100644--- a/resources/js/types/types.ts+++ b/resources/js/types/types.ts@@ -40,8 +40,26 @@ export interface PulseResponse {slow_requests?: any;usage: {userRequestCounts: PulseUsageResponse[];+ slowRequestsCounts: PulseUsageResponse[];+ jobsCounts: PulseUsageResponse[];time: number;runAt: string;+ userRequestsConfig: {+ enabled: boolean;+ sample_rate: number;+ ignore: any[];+ };+ slowRequestsConfig: {+ enabled: boolean;+ sample_rate: number;+ threshold: 1000;+ ignore: any[];+ };+ jobsConfig: {+ enabled: boolean;+ sample_rate: number;+ ignore: any[];+ };};}@@ -61,18 +79,20 @@ export interface PulseServerResponse {export interface PulseQueueResponse {[key: string]: { [key: string]: string | null };- // queued: { [key: string]: string | null };- // processing: { [key: string]: string | null };- // processed: { [key: string]: string | null };- // released: { [key: string]: string | null };- // failed: { [key: string]: string | null };}+// queued: { [key: string]: string | null };+// processing: { [key: string]: string | null };+// processed: { [key: string]: string | null };+// released: { [key: string]: string | null };+// failed: { [key: string]: string | null };+export interface PulseUsageResponse {key: number;user: {name: string;extra: string;+ avatar?: string;};count: number;}