feat: database + service usage
This commit is contained in:
parent
972f77c790
commit
1f25bc411f
@ -102,7 +102,7 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (browser && window.location.hostname === 'demo.coolify.io' && !application.fqdn) {
|
if (browser && window.location.hostname === 'demo.coolify.io' && !application.fqdn) {
|
||||||
application.fqdn = `http://${cuid()}.demo.coolify.io`;
|
application.fqdn = `http://${cuid()}.demo.coolify.io`;
|
||||||
await handleSubmit();
|
await post(`/applications/${id}.json`, { ...application });
|
||||||
}
|
}
|
||||||
domainEl.focus();
|
domainEl.focus();
|
||||||
await getUsage();
|
await getUsage();
|
||||||
|
@ -33,10 +33,40 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import DatabaseLinks from '$lib/components/DatabaseLinks.svelte';
|
import DatabaseLinks from '$lib/components/DatabaseLinks.svelte';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import { get } from '$lib/api';
|
||||||
|
import { onDestroy, onMount } from 'svelte';
|
||||||
export let database;
|
export let database;
|
||||||
export let settings;
|
export let settings;
|
||||||
export let privatePort;
|
export let privatePort;
|
||||||
export let isRunning;
|
export let isRunning;
|
||||||
|
|
||||||
|
const { id } = $page.params;
|
||||||
|
let usageLoading = false;
|
||||||
|
let usage = {
|
||||||
|
MemUsage: 0,
|
||||||
|
CPUPerc: 0,
|
||||||
|
NetIO: 0
|
||||||
|
};
|
||||||
|
let usageInterval;
|
||||||
|
|
||||||
|
async function getUsage() {
|
||||||
|
if (usageLoading) return;
|
||||||
|
usageLoading = true;
|
||||||
|
const data = await get(`/databases/${id}/usage.json`);
|
||||||
|
usage = data.usage;
|
||||||
|
usageLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
clearInterval(usageInterval);
|
||||||
|
});
|
||||||
|
onMount(async () => {
|
||||||
|
await getUsage();
|
||||||
|
usageInterval = setInterval(async () => {
|
||||||
|
await getUsage();
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex items-center space-x-2 p-6 text-2xl font-bold">
|
<div class="flex items-center space-x-2 p-6 text-2xl font-bold">
|
||||||
@ -49,4 +79,31 @@
|
|||||||
<DatabaseLinks {database} />
|
<DatabaseLinks {database} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mx-auto max-w-4xl px-6 py-4">
|
||||||
|
<div class="text-2xl font-bold">Database Usage</div>
|
||||||
|
<div class="mx-auto">
|
||||||
|
<dl class="relative mt-5 grid grid-cols-1 gap-5 sm:grid-cols-3">
|
||||||
|
<div class="overflow-hidden rounded px-4 py-5 text-center sm:p-6 sm:text-left">
|
||||||
|
<dt class=" text-sm font-medium text-white">Used Memory / Memory Limit</dt>
|
||||||
|
<dd class="mt-1 text-xl font-semibold text-white">
|
||||||
|
{usage?.MemUsage}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-hidden rounded px-4 py-5 text-center sm:p-6 sm:text-left">
|
||||||
|
<dt class="truncate text-sm font-medium text-white">Used CPU</dt>
|
||||||
|
<dd class="mt-1 text-xl font-semibold text-white ">
|
||||||
|
{usage?.CPUPerc}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-hidden rounded px-4 py-5 text-center sm:p-6 sm:text-left">
|
||||||
|
<dt class="truncate text-sm font-medium text-white">Network IO</dt>
|
||||||
|
<dd class="mt-1 text-xl font-semibold text-white ">
|
||||||
|
{usage?.NetIO}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Databases bind:database {privatePort} {settings} {isRunning} />
|
<Databases bind:database {privatePort} {settings} {isRunning} />
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { asyncExecShell, getUserDetails } from '$lib/common';
|
import { getUserDetails } from '$lib/common';
|
||||||
import * as db from '$lib/database';
|
import * as db from '$lib/database';
|
||||||
import { ErrorHandler } from '$lib/database';
|
import { ErrorHandler } from '$lib/database';
|
||||||
import { checkContainer, getContainerUsage, isContainerExited } from '$lib/haproxy';
|
import { getContainerUsage } from '$lib/haproxy';
|
||||||
import type { RequestHandler } from '@sveltejs/kit';
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
import { setDefaultConfiguration } from '$lib/buildPacks/common';
|
|
||||||
|
|
||||||
export const get: RequestHandler = async (event) => {
|
export const get: RequestHandler = async (event) => {
|
||||||
const { teamId, status, body } = await getUserDetails(event);
|
const { teamId, status, body } = await getUserDetails(event);
|
||||||
@ -13,9 +12,9 @@ export const get: RequestHandler = async (event) => {
|
|||||||
|
|
||||||
let usage = {};
|
let usage = {};
|
||||||
try {
|
try {
|
||||||
const application = await db.getApplication({ id, teamId });
|
const database = await db.getDatabase({ id, teamId });
|
||||||
if (application.destinationDockerId) {
|
if (database.destinationDockerId) {
|
||||||
[usage] = await Promise.all([getContainerUsage(application.destinationDocker.engine, id)]);
|
[usage] = await Promise.all([getContainerUsage(database.destinationDocker.engine, id)]);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
@ -74,7 +74,7 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if (browser && window.location.hostname === 'demo.coolify.io' && !service.fqdn) {
|
if (browser && window.location.hostname === 'demo.coolify.io' && !service.fqdn) {
|
||||||
service.fqdn = `http://${cuid()}.demo.coolify.io`;
|
service.fqdn = `http://${cuid()}.demo.coolify.io`;
|
||||||
await handleSubmit();
|
await post(`/services/${id}/${service.type}.json`, { ...service });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -32,11 +32,41 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import ServiceLinks from '$lib/components/ServiceLinks.svelte';
|
import ServiceLinks from '$lib/components/ServiceLinks.svelte';
|
||||||
import Services from './_Services/_Services.svelte';
|
import Services from './_Services/_Services.svelte';
|
||||||
|
import { get } from '$lib/api';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import { onDestroy, onMount } from 'svelte';
|
||||||
|
|
||||||
export let service;
|
export let service;
|
||||||
export let isRunning;
|
export let isRunning;
|
||||||
export let readOnly;
|
export let readOnly;
|
||||||
export let settings;
|
export let settings;
|
||||||
|
|
||||||
|
const { id } = $page.params;
|
||||||
|
let usageLoading = false;
|
||||||
|
let usage = {
|
||||||
|
MemUsage: 0,
|
||||||
|
CPUPerc: 0,
|
||||||
|
NetIO: 0
|
||||||
|
};
|
||||||
|
let usageInterval;
|
||||||
|
|
||||||
|
async function getUsage() {
|
||||||
|
if (usageLoading) return;
|
||||||
|
usageLoading = true;
|
||||||
|
const data = await get(`/services/${id}/usage.json`);
|
||||||
|
usage = data.usage;
|
||||||
|
usageLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
clearInterval(usageInterval);
|
||||||
|
});
|
||||||
|
onMount(async () => {
|
||||||
|
await getUsage();
|
||||||
|
usageInterval = setInterval(async () => {
|
||||||
|
await getUsage();
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex h-20 items-center space-x-2 p-5 px-6 font-bold">
|
<div class="flex h-20 items-center space-x-2 p-5 px-6 font-bold">
|
||||||
@ -46,6 +76,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<span class="text-xs">{service.name}</span>
|
<span class="text-xs">{service.name}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if service.fqdn}
|
{#if service.fqdn}
|
||||||
<a
|
<a
|
||||||
href={service.fqdn}
|
href={service.fqdn}
|
||||||
@ -71,5 +102,31 @@
|
|||||||
|
|
||||||
<ServiceLinks {service} />
|
<ServiceLinks {service} />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mx-auto max-w-4xl px-6 py-4">
|
||||||
|
<div class="text-2xl font-bold">Service Usage</div>
|
||||||
|
<div class="mx-auto">
|
||||||
|
<dl class="relative mt-5 grid grid-cols-1 gap-5 sm:grid-cols-3">
|
||||||
|
<div class="overflow-hidden rounded px-4 py-5 text-center sm:p-6 sm:text-left">
|
||||||
|
<dt class=" text-sm font-medium text-white">Used Memory / Memory Limit</dt>
|
||||||
|
<dd class="mt-1 text-xl font-semibold text-white">
|
||||||
|
{usage?.MemUsage}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-hidden rounded px-4 py-5 text-center sm:p-6 sm:text-left">
|
||||||
|
<dt class="truncate text-sm font-medium text-white">Used CPU</dt>
|
||||||
|
<dd class="mt-1 text-xl font-semibold text-white ">
|
||||||
|
{usage?.CPUPerc}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="overflow-hidden rounded px-4 py-5 text-center sm:p-6 sm:text-left">
|
||||||
|
<dt class="truncate text-sm font-medium text-white">Network IO</dt>
|
||||||
|
<dd class="mt-1 text-xl font-semibold text-white ">
|
||||||
|
{usage?.NetIO}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<Services bind:service {isRunning} {readOnly} {settings} />
|
<Services bind:service {isRunning} {readOnly} {settings} />
|
||||||
|
30
src/routes/services/[id]/usage.json.ts
Normal file
30
src/routes/services/[id]/usage.json.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { getUserDetails } from '$lib/common';
|
||||||
|
import * as db from '$lib/database';
|
||||||
|
import { ErrorHandler } from '$lib/database';
|
||||||
|
import { getContainerUsage } from '$lib/haproxy';
|
||||||
|
import type { RequestHandler } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const get: RequestHandler = async (event) => {
|
||||||
|
const { teamId, status, body } = await getUserDetails(event);
|
||||||
|
if (status === 401) return { status, body };
|
||||||
|
|
||||||
|
const { id } = event.params;
|
||||||
|
|
||||||
|
let usage = {};
|
||||||
|
try {
|
||||||
|
const service = await db.getService({ id, teamId });
|
||||||
|
if (service.destinationDockerId) {
|
||||||
|
[usage] = await Promise.all([getContainerUsage(service.destinationDocker.engine, id)]);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
status: 200,
|
||||||
|
body: {
|
||||||
|
usage
|
||||||
|
},
|
||||||
|
headers: {}
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
return ErrorHandler(error);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user