adonisjs-pulse 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +119 -0
  3. package/build/configure.d.ts +2 -0
  4. package/build/configure.js +47 -0
  5. package/build/index.d.ts +5 -0
  6. package/build/index.js +5 -0
  7. package/build/providers/pulse_provider.d.ts +16 -0
  8. package/build/providers/pulse_provider.js +64 -0
  9. package/build/resources/views/components/card-header.edge +30 -0
  10. package/build/resources/views/components/card.edge +8 -0
  11. package/build/resources/views/components/no-results.edge +3 -0
  12. package/build/resources/views/components/pulse.edge +79 -0
  13. package/build/resources/views/components/scroll.edge +3 -0
  14. package/build/resources/views/components/table.edge +3 -0
  15. package/build/resources/views/components/td.edge +4 -0
  16. package/build/resources/views/components/th.edge +4 -0
  17. package/build/resources/views/components/thead.edge +3 -0
  18. package/build/resources/views/components/theme-switcher.edge +48 -0
  19. package/build/resources/views/dashboard.edge +7 -0
  20. package/build/resources/views/livewire/cache.edge +111 -0
  21. package/build/resources/views/livewire/exceptions.edge +48 -0
  22. package/build/resources/views/livewire/period-selector.edge +11 -0
  23. package/build/resources/views/livewire/servers.edge +86 -0
  24. package/build/resources/views/livewire/slow-queries.edge +50 -0
  25. package/build/resources/views/livewire/slow-requests.edge +62 -0
  26. package/build/resources/views/livewire/usage.edge +63 -0
  27. package/build/services/pulse.d.ts +3 -0
  28. package/build/services/pulse.js +6 -0
  29. package/build/src/entry.d.ts +24 -0
  30. package/build/src/entry.js +67 -0
  31. package/build/src/livewire/cache.d.ts +4 -0
  32. package/build/src/livewire/cache.js +33 -0
  33. package/build/src/livewire/card.d.ts +22 -0
  34. package/build/src/livewire/card.js +96 -0
  35. package/build/src/livewire/exceptions.d.ts +4 -0
  36. package/build/src/livewire/exceptions.js +29 -0
  37. package/build/src/livewire/period_selector.d.ts +5 -0
  38. package/build/src/livewire/period_selector.js +16 -0
  39. package/build/src/livewire/servers.d.ts +4 -0
  40. package/build/src/livewire/servers.js +36 -0
  41. package/build/src/livewire/slow_queries.d.ts +5 -0
  42. package/build/src/livewire/slow_queries.js +37 -0
  43. package/build/src/livewire/slow_requests.d.ts +5 -0
  44. package/build/src/livewire/slow_requests.js +37 -0
  45. package/build/src/pulse.d.ts +44 -0
  46. package/build/src/pulse.js +224 -0
  47. package/build/src/recorders/cache_interactions.d.ts +34 -0
  48. package/build/src/recorders/cache_interactions.js +80 -0
  49. package/build/src/recorders/exceptions.d.ts +8 -0
  50. package/build/src/recorders/exceptions.js +81 -0
  51. package/build/src/recorders/index.d.ts +7 -0
  52. package/build/src/recorders/index.js +6 -0
  53. package/build/src/recorders/recorder.d.ts +24 -0
  54. package/build/src/recorders/recorder.js +45 -0
  55. package/build/src/recorders/servers.d.ts +24 -0
  56. package/build/src/recorders/servers.js +133 -0
  57. package/build/src/recorders/slow_queries.d.ts +8 -0
  58. package/build/src/recorders/slow_queries.js +27 -0
  59. package/build/src/recorders/slow_requests.d.ts +11 -0
  60. package/build/src/recorders/slow_requests.js +80 -0
  61. package/build/src/storage/database_storage.d.ts +20 -0
  62. package/build/src/storage/database_storage.js +357 -0
  63. package/build/src/types.d.ts +91 -0
  64. package/build/src/types.js +3 -0
  65. package/build/src/value.d.ts +9 -0
  66. package/build/src/value.js +20 -0
  67. package/build/stubs/config.stub +58 -0
  68. package/build/stubs/main.d.ts +5 -0
  69. package/build/stubs/main.js +7 -0
  70. package/build/stubs/migration.stub +58 -0
  71. package/package.json +100 -0
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ # The MIT License
2
+
3
+ Copyright (c) 2023
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # AdonisJS package starter kit
2
+
3
+ > A boilerplate for creating AdonisJS packages
4
+
5
+ This repo provides you with a starting point for creating AdonisJS packages. Of course, you can create a package from scratch with your folder structure and workflow. However, using this starter kit can speed up the process, as you have fewer decisions to make.
6
+
7
+ ## Setup
8
+
9
+ - Clone the repo on your computer, or use `giget` to download this repo without the Git history.
10
+ ```sh
11
+ npx giget@latest gh:adonisjs/pkg-starter-kit
12
+ ```
13
+ - Install dependencies.
14
+ - Update the `package.json` file and define the `name`, `description`, `keywords`, and `author` properties.
15
+ - The repo is configured with an MIT license. Feel free to change that if you are not publishing under the MIT license.
16
+
17
+ ## Folder structure
18
+
19
+ The starter kit mimics the folder structure of the official packages. Feel free to rename files and folders as per your requirements.
20
+
21
+ ```
22
+ ├── providers
23
+ ├── src
24
+ ├── bin
25
+ ├── stubs
26
+ ├── configure.ts
27
+ ├── index.ts
28
+ ├── LICENSE.md
29
+ ├── package.json
30
+ ├── README.md
31
+ ├── tsconfig.json
32
+ ├── tsnode.esm.js
33
+ ```
34
+
35
+ - The `configure.ts` file exports the `configure` hook to configure the package using the `node ace configure` command.
36
+ - The `index.ts` file is the main entry point of the package.
37
+ - The `tsnode.esm.js` file runs TypeScript code using TS-Node + SWC. Please read the code comment in this file to learn more.
38
+ - The `bin` directory contains the entry point file to run Japa tests.
39
+ - Learn more about [the `providers` directory](./providers/README.md).
40
+ - Learn more about [the `src` directory](./src/README.md).
41
+ - Learn more about [the `stubs` directory](./stubs/README.md).
42
+
43
+ ### File system naming convention
44
+
45
+ We use `snake_case` naming conventions for the file system. The rule is enforced using ESLint. However, turn off the rule and use your preferred naming conventions.
46
+
47
+ ## Peer dependencies
48
+
49
+ The starter kit has a peer dependency on `@adonisjs/core@6`. Since you are creating a package for AdonisJS, you must make it against a specific version of the framework core.
50
+
51
+ If your package needs Lucid to be functional, you may install `@adonisjs/lucid` as a development dependency and add it to the list of `peerDependencies`.
52
+
53
+ As a rule of thumb, packages installed in the user application should be part of the `peerDependencies` of your package and not the main dependency.
54
+
55
+ For example, if you install `@adonisjs/core` as a main dependency, then essentially, you are importing a separate copy of `@adonisjs/core` and not sharing the one from the user application. Here is a great article explaining [peer dependencies](https://blog.bitsrc.io/understanding-peer-dependencies-in-javascript-dbdb4ab5a7be).
56
+
57
+ ## Published files
58
+
59
+ Instead of publishing your repo's source code to npm, you must cherry-pick files and folders to publish only the required files.
60
+
61
+ The cherry-picking uses the `files` property inside the `package.json` file. By default, we publish the following files and folders.
62
+
63
+ ```json
64
+ {
65
+ "files": ["build/src", "build/providers", "build/stubs", "build/index.d.ts", "build/index.js", "build/configure.d.ts", "build/configure.js"]
66
+ }
67
+ ```
68
+
69
+ If you create additional folders or files, mention them inside the `files` array.
70
+
71
+ ## Exports
72
+
73
+ [Node.js Subpath exports](https://nodejs.org/api/packages.html#subpath-exports) allows you to define the exports of your package regardless of the folder structure. This starter kit defines the following exports.
74
+
75
+ ```json
76
+ {
77
+ "exports": {
78
+ ".": "./build/index.js",
79
+ "./types": "./build/src/types.js"
80
+ }
81
+ }
82
+ ```
83
+
84
+ - The dot `.` export is the main export.
85
+ - The `./types` exports all the types defined inside the `./build/src/types.js` file (the compiled output).
86
+
87
+ Feel free to change the exports as per your requirements.
88
+
89
+ ## Testing
90
+
91
+ We configure the [Japa test runner](https://japa.dev/) with this starter kit. Japa is used in AdonisJS applications as well. Just run one of the following commands to execute tests.
92
+
93
+ - `npm run test`: This command will first lint the code using ESlint and then run tests and report the test coverage using [c8](https://github.com/bcoe/c8).
94
+ - `npm run quick:test`: Runs only the tests without linting or coverage reporting.
95
+
96
+ The starter kit also has a Github workflow file to run tests using Github Actions. The tests are executed against `Node.js 20.x` and `Node.js 21.x` versions on both Linux and Windows. Feel free to edit the workflow file in the `.github/workflows` directory.
97
+
98
+ ## TypeScript workflow
99
+
100
+ - The starter kit uses [tsc](https://www.typescriptlang.org/docs/handbook/compiler-options.html) for compiling the TypeScript to JavaScript when publishing the package.
101
+ - [TS-Node](https://typestrong.org/ts-node/) and [SWC](https://swc.rs/) are used to run tests without compiling the source code.
102
+ - The `tsconfig.json` file is extended from [`@adonisjs/tsconfig`](https://github.com/adonisjs/tooling-config/tree/main/packages/typescript-config) and uses the `NodeNext` module system. Meaning the packages are written using ES modules.
103
+ - You can perform type checking without compiling the source code using the `npm run type check` script.
104
+
105
+ Feel free to explore the `tsconfig.json` file for all the configured options.
106
+
107
+ ## ESLint and Prettier setup
108
+
109
+ The starter kit configures ESLint and Prettier
110
+ using our [shared config](https://github.com/adonisjs/tooling-config/tree/main/packages).
111
+ ESLint configuration is stored within the `eslint.config.js` file.
112
+ Prettier configuration is stored within the `package.json` file.
113
+ Feel free to change the configuration, use custom plugins, or remove both tools altogether.
114
+
115
+ ## Using Stale bot
116
+
117
+ The [Stale bot](https://github.com/apps/stale) is a Github application that automatically marks issues and PRs as stale and closes after a specific duration of inactivity.
118
+
119
+ Feel free to delete the `.github/stale.yml` and `.github/lock.yml` files if you decide not to use the Stale bot.
@@ -0,0 +1,2 @@
1
+ import ConfigureCommand from '@adonisjs/core/commands/configure';
2
+ export declare function configure(command: ConfigureCommand): Promise<void>;
@@ -0,0 +1,47 @@
1
+ /*
2
+ |--------------------------------------------------------------------------
3
+ | Configure hook
4
+ |--------------------------------------------------------------------------
5
+ |
6
+ | The configure hook is called when someone runs "node ace configure <package>"
7
+ | command. You are free to perform any operations inside this function to
8
+ | configure the package.
9
+ |
10
+ | To make things easier, you have access to the underlying "ConfigureCommand"
11
+ | instance and you can use codemods to modify the source files.
12
+ |
13
+ */
14
+ import { stubsRoot } from './stubs/main.js';
15
+ export async function configure(command) {
16
+ const codemods = await command.createCodemods();
17
+ await codemods.makeUsingStub(stubsRoot, 'migration.stub', { time: Date.now() });
18
+ await codemods.makeUsingStub(stubsRoot, 'config.stub', {});
19
+ await codemods.defineEnvVariables({
20
+ PULSE_DB_CONNECTION: '',
21
+ });
22
+ await codemods.defineEnvValidations({
23
+ leadingComment: 'Variables for configuring the pulse package',
24
+ variables: {
25
+ PULSE_ENABLED: `Env.schema.boolean.optional()`,
26
+ PULSE_DB_CONNECTION: `Env.schema.string.optional()`,
27
+ PULSE_SLOW_REQUESTS_ENABLED: `Env.schema.boolean.optional()`,
28
+ PULSE_SLOW_REQUESTS_SAMPLE_RATE: `Env.schema.number.optional()`,
29
+ PULSE_SLOW_REQUESTS_THRESHOLD: `Env.schema.number.optional()`,
30
+ PULSE_SLOW_QUERIES_ENABLED: `Env.schema.boolean.optional()`,
31
+ PULSE_SLOW_QUERIES_SAMPLE_RATE: `Env.schema.number.optional()`,
32
+ PULSE_SLOW_QUERIES_THRESHOLD: `Env.schema.number.optional()`,
33
+ PULSE_EXCEPTIONS_ENABLED: `Env.schema.boolean.optional()`,
34
+ PULSE_EXCEPTIONS_SAMPLE_RATE: `Env.schema.number.optional()`,
35
+ PULSE_SERVERS_ENABLED: `Env.schema.boolean.optional()`,
36
+ PULSE_CACHE_INTERACTIONS_ENABLED: `Env.schema.boolean.optional()`,
37
+ PULSE_CACHE_INTERACTIONS_SAMPLE_RATE: `Env.schema.number.optional()`,
38
+ },
39
+ });
40
+ await codemods.updateRcFile((rcFile) => {
41
+ rcFile.addProvider('adonisjs-pulse/pulse_provider');
42
+ });
43
+ await codemods.installPackages([
44
+ { name: 'edge.js', isDevDependency: false },
45
+ { name: 'adonisjs-livewire', isDevDependency: false },
46
+ ]);
47
+ }
@@ -0,0 +1,5 @@
1
+ export { configure } from './configure.js';
2
+ export { Pulse } from './src/pulse.js';
3
+ export { Entry } from './src/entry.js';
4
+ export { Value } from './src/value.js';
5
+ export * from './src/types.js';
package/build/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { configure } from './configure.js';
2
+ export { Pulse } from './src/pulse.js';
3
+ export { Entry } from './src/entry.js';
4
+ export { Value } from './src/value.js';
5
+ export * from './src/types.js';
@@ -0,0 +1,16 @@
1
+ import type { ApplicationService } from '@adonisjs/core/types';
2
+ import { Pulse } from '../src/pulse.js';
3
+ declare module '@adonisjs/core/types' {
4
+ interface ContainerBindings {
5
+ pulse: Pulse;
6
+ }
7
+ }
8
+ export default class PulseProvider {
9
+ protected app: ApplicationService;
10
+ protected pulse: Pulse | null;
11
+ constructor(app: ApplicationService);
12
+ register(): void;
13
+ start(): Promise<void>;
14
+ ready(): Promise<void>;
15
+ shutdown(): Promise<void>;
16
+ }
@@ -0,0 +1,64 @@
1
+ import { Pulse } from '../src/pulse.js';
2
+ import edge from 'edge.js';
3
+ import { SlowQueries } from '../src/livewire/slow_queries.js';
4
+ import { SlowRequests } from '../src/livewire/slow_requests.js';
5
+ import { Servers } from '../src/livewire/servers.js';
6
+ import { Exceptions } from '../src/livewire/exceptions.js';
7
+ import { PeriodSelector } from '../src/livewire/period_selector.js';
8
+ import { Cache } from '../src/livewire/cache.js';
9
+ export default class PulseProvider {
10
+ app;
11
+ pulse = null;
12
+ constructor(app) {
13
+ this.app = app;
14
+ }
15
+ register() {
16
+ this.app.container.singleton('pulse', async () => {
17
+ const db = await this.app.container.make('lucid.db');
18
+ const config = this.app.config.get('pulse', {});
19
+ return new Pulse(db, config);
20
+ });
21
+ }
22
+ async start() {
23
+ const database = this.app.config.get('database', {});
24
+ for (const connectionName in database.connections) {
25
+ const connectionConfig = database.connections[connectionName];
26
+ connectionConfig.debug = true;
27
+ }
28
+ if (this.app.usingEdgeJS) {
29
+ edge.mount('pulse', new URL('../resources/views', import.meta.url));
30
+ const router = await this.app.container.make('router');
31
+ router.get('/pulse', async (ctx) => {
32
+ return ctx.view.render('pulse::dashboard');
33
+ });
34
+ }
35
+ const Livewire = await this.app.container.make('livewire');
36
+ Livewire.component('pulse::slow-queries', SlowQueries);
37
+ Livewire.component('pulse::slow-requests', SlowRequests);
38
+ Livewire.component('pulse::servers', Servers);
39
+ Livewire.component('pulse::exceptions', Exceptions);
40
+ Livewire.component('pulse::period-selector', PeriodSelector);
41
+ Livewire.component('pulse::cache', Cache);
42
+ }
43
+ async ready() {
44
+ const pulse = await this.app.container.make('pulse');
45
+ this.pulse = pulse;
46
+ const config = pulse.getConfig();
47
+ if (!config.enabled) {
48
+ return;
49
+ }
50
+ await pulse.registerRecorders(this.app);
51
+ pulse.startIngesting();
52
+ }
53
+ async shutdown() {
54
+ if (this.pulse) {
55
+ for (const recorder of this.pulse.getRecorders()) {
56
+ if ('stop' in recorder && typeof recorder.stop === 'function') {
57
+ recorder.stop();
58
+ }
59
+ }
60
+ this.pulse.stopIngesting();
61
+ await this.pulse.flush();
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,30 @@
1
+ <header class="flex flex-wrap justify-between items-center gap-4 mb-3 @md:mb-6">
2
+ <div class="flex-1 basis-0 flex-grow-[10000] max-w-full">
3
+ <div class="flex overflow-hidden gap-2 items-start">
4
+ @if($slots.icon)
5
+ <div class="[&>svg]:flex-shrink-0 [&>svg]:w-6 [&>svg]:h-6 [&>svg]:stroke-gray-400 [&>svg]:dark:stroke-gray-600">
6
+ {{{ await $slots.icon() }}}
7
+ </div>
8
+ @end
9
+ <hgroup class="flex flex-wrap items-baseline gap-x-2 overflow-hidden">
10
+ <h2 class="text-base font-bold text-gray-600 dark:text-gray-300 truncate" title="{{ title ?? '' }}">
11
+ @if($slots.title)
12
+ {{{ await $slots.title() }}}
13
+ @else
14
+ {{ title ?? '' }}
15
+ @end
16
+ </h2>
17
+ @if(details)
18
+ <p class="text-gray-400 dark:text-gray-600 font-medium truncate"><small class="text-xs">{{ details }}</small></p>
19
+ @end
20
+ </hgroup>
21
+ </div>
22
+ </div>
23
+ @if($slots.actions)
24
+ <div class="flex flex-grow">
25
+ <div class="w-full flex items-center gap-4">
26
+ {{{ await $slots.actions() }}}
27
+ </div>
28
+ </div>
29
+ @end
30
+ </header>
@@ -0,0 +1,8 @@
1
+ @let(colsValue = cols ?? 6)
2
+ @let(rowsValue = rows ?? 1)
3
+
4
+ <div
5
+ class="@container flex flex-col p-3 sm:p-6 bg-white dark:bg-gray-900 text-gray-900 dark:text-gray-100 rounded-xl shadow-sm ring-1 ring-gray-900/5 col-span-full lg:col-span-{{ colsValue }} row-span-{{ rowsValue }}"
6
+ >
7
+ {{{ await $slots.main() }}}
8
+ </div>
@@ -0,0 +1,3 @@
1
+ <div class="flex items-center justify-center py-8 text-sm text-gray-500 dark:text-gray-400">
2
+ {{ message ?? 'No results' }}
3
+ </div>
@@ -0,0 +1,79 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" class="dark">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Pulse - Application Performance</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script>
9
+ tailwind.config = {
10
+ darkMode: 'class',
11
+ theme: {
12
+ extend: {
13
+ colors: {
14
+ pulse: {
15
+ bg: 'rgb(17, 24, 39)',
16
+ card: 'rgb(31, 41, 55)',
17
+ border: 'rgb(55, 65, 81)',
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ </script>
24
+ <style type="text/tailwindcss">
25
+ @layer components {
26
+ .pulse-card {
27
+ @apply bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700;
28
+ }
29
+ .pulse-scroll {
30
+ @apply overflow-y-auto;
31
+ scrollbar-width: thin;
32
+ scrollbar-color: rgb(75 85 99) transparent;
33
+ }
34
+ .pulse-scroll::-webkit-scrollbar {
35
+ width: 6px;
36
+ }
37
+ .pulse-scroll::-webkit-scrollbar-track {
38
+ background: transparent;
39
+ }
40
+ .pulse-scroll::-webkit-scrollbar-thumb {
41
+ background-color: rgb(75 85 99);
42
+ border-radius: 3px;
43
+ }
44
+ }
45
+ </style>
46
+ @livewireStyles()
47
+ </head>
48
+ <body class="bg-gray-100 dark:bg-gray-950 min-h-screen antialiased">
49
+ <div class="mx-auto max-w-screen-2xl p-4 lg:p-6">
50
+ <header class="mb-6 flex items-center justify-between">
51
+ <div class="flex items-center gap-4">
52
+ <h1 class="text-2xl font-semibold text-gray-900 dark:text-gray-100">
53
+ Pulse
54
+ </h1>
55
+ @livewire('pulse::period-selector')
56
+ </div>
57
+ <div class="flex items-center gap-2">
58
+ @!component('pulse::components/theme-switcher')
59
+ </div>
60
+ </header>
61
+
62
+ <main class="grid grid-cols-12 gap-4 lg:gap-6">
63
+ {{{ await $slots.main() }}}
64
+ </main>
65
+ </div>
66
+
67
+ @livewireScripts()
68
+ <script>
69
+ document.addEventListener('alpine:init', () => {
70
+ Alpine.data('pulseChart', () => ({
71
+ init() {
72
+ this.$watch('data', () => this.render())
73
+ },
74
+ render() {}
75
+ }))
76
+ })
77
+ </script>
78
+ </body>
79
+ </html>
@@ -0,0 +1,3 @@
1
+ <div class="pulse-scroll flex-1 overflow-y-auto {{ $props.class ?? '' }}">
2
+ {{{ await $slots.main() }}}
3
+ </div>
@@ -0,0 +1,3 @@
1
+ <table class="min-w-full">
2
+ {{{ await $slots.main() }}}
3
+ </table>
@@ -0,0 +1,4 @@
1
+ @let(classValue = state.class ?? '')
2
+ <td class="first:rounded-l-md last:rounded-r-md text-sm bg-gray-50 dark:bg-gray-800/50 first:pl-3 last:pr-3 px-1 @sm:px-3 py-3 {{ classValue }}">
3
+ {{{ await $slots.main() }}}
4
+ </td>
@@ -0,0 +1,4 @@
1
+ @let(classValue = state.class ?? '')
2
+ <th class="text-xs text-gray-500 uppercase py-2 first:pl-3 last:pr-3 px-1 @sm:px-3 text-left {{ classValue }}">
3
+ {{{ await $slots.main() }}}
4
+ </th>
@@ -0,0 +1,3 @@
1
+ <thead class="sticky z-10 top-0 bg-white dark:bg-gray-900">
2
+ {{{ await $slots.main() }}}
3
+ </thead>
@@ -0,0 +1,48 @@
1
+ <div x-data="themeSwitcher()" class="relative">
2
+ <button
3
+ type="button"
4
+ @click="toggle()"
5
+ class="flex items-center justify-center w-8 h-8 rounded-lg text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
6
+ :title="theme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'"
7
+ >
8
+ <template x-if="theme === 'dark'">
9
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
10
+ <path fill-rule="evenodd" d="M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414zm2.12-10.607a1 1 0 010 1.414l-.706.707a1 1 0 11-1.414-1.414l.707-.707a1 1 0 011.414 0zM17 11a1 1 0 100-2h-1a1 1 0 100 2h1zm-7 4a1 1 0 011 1v1a1 1 0 11-2 0v-1a1 1 0 011-1zM5.05 6.464A1 1 0 106.465 5.05l-.708-.707a1 1 0 00-1.414 1.414l.707.707zm1.414 8.486l-.707.707a1 1 0 01-1.414-1.414l.707-.707a1 1 0 011.414 1.414zM4 11a1 1 0 100-2H3a1 1 0 000 2h1z" clip-rule="evenodd" />
11
+ </svg>
12
+ </template>
13
+ <template x-if="theme === 'light'">
14
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
15
+ <path d="M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z" />
16
+ </svg>
17
+ </template>
18
+ </button>
19
+ </div>
20
+
21
+ <script>
22
+ function themeSwitcher() {
23
+ return {
24
+ theme: localStorage.getItem('pulse-theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'),
25
+ init() {
26
+ this.applyTheme()
27
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
28
+ if (!localStorage.getItem('pulse-theme')) {
29
+ this.theme = e.matches ? 'dark' : 'light'
30
+ this.applyTheme()
31
+ }
32
+ })
33
+ },
34
+ toggle() {
35
+ this.theme = this.theme === 'dark' ? 'light' : 'dark'
36
+ localStorage.setItem('pulse-theme', this.theme)
37
+ this.applyTheme()
38
+ },
39
+ applyTheme() {
40
+ if (this.theme === 'dark') {
41
+ document.documentElement.classList.add('dark')
42
+ } else {
43
+ document.documentElement.classList.remove('dark')
44
+ }
45
+ }
46
+ }
47
+ }
48
+ </script>
@@ -0,0 +1,7 @@
1
+ <x-pulse::pulse>
2
+ <livewire:pulse::servers cols="full" />
3
+ <livewire:pulse::slow-queries cols="6" />
4
+ <livewire:pulse::cache cols="6" />
5
+ <livewire:pulse::slow-requests cols="6" />
6
+ <livewire:pulse::exceptions cols="6" />
7
+ </x-pulse::pulse>
@@ -0,0 +1,111 @@
1
+ <x-pulse::card :cols="cols ?? 4" :rows="rows ?? 2">
2
+ <x-pulse::card-header title="Cache" :details="'past ' + period">
3
+ <x-slot name="icon">
4
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5">
5
+ <path stroke-linecap="round" stroke-linejoin="round" d="M15.59 14.37a6 6 0 0 1-5.84 7.38v-4.8m5.84-2.58a14.98 14.98 0 0 0 6.16-12.12A14.98 14.98 0 0 0 9.631 8.41m5.96 5.96a14.926 14.926 0 0 1-5.841 2.58m-.119-8.54a6 6 0 0 0-7.381 5.84h4.8m2.581-5.84a14.927 14.927 0 0 0-2.58 5.84m2.699 2.7c-.103.021-.207.041-.311.06a15.09 15.09 0 0 1-2.448-2.448 14.9 14.9 0 0 1 .06-.312m-2.24 2.39a4.493 4.493 0 0 0-1.757 4.306 4.493 4.493 0 0 0 4.306-1.758M16.5 9a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z" />
6
+ </svg>
7
+ </x-slot>
8
+ </x-pulse::card-header>
9
+
10
+ <x-pulse::scroll>
11
+ @if(allCacheInteractions.hits === 0 && allCacheInteractions.misses === 0)
12
+ <x-pulse::no-results message="No cache interactions" />
13
+ @else
14
+ <div class="flex flex-col gap-6">
15
+ <div class="grid grid-cols-3 gap-3 text-center">
16
+ <div class="flex flex-col justify-center @sm:block">
17
+ <span class="text-xl uppercase font-bold text-gray-700 dark:text-gray-300 tabular-nums">
18
+ @if(config.sampleRate < 1)
19
+ <span title="Sample rate: {{ config.sampleRate }}, Raw value: {{ formatNumber(allCacheInteractions.hits) }}">~{{ formatNumber(Math.round(allCacheInteractions.hits * (1 / config.sampleRate))) }}</span>
20
+ @else
21
+ {{ formatNumber(allCacheInteractions.hits) }}
22
+ @end
23
+ </span>
24
+ <span class="text-xs uppercase font-bold text-gray-500 dark:text-gray-400">
25
+ Hits
26
+ </span>
27
+ </div>
28
+ <div class="flex flex-col justify-center @sm:block">
29
+ <span class="text-xl uppercase font-bold text-gray-700 dark:text-gray-300 tabular-nums">
30
+ @if(config.sampleRate < 1)
31
+ <span title="Sample rate: {{ config.sampleRate }}, Raw value: {{ formatNumber(allCacheInteractions.misses) }}">~{{ formatNumber(Math.round(allCacheInteractions.misses * (1 / config.sampleRate))) }}</span>
32
+ @else
33
+ {{ formatNumber(allCacheInteractions.misses) }}
34
+ @end
35
+ </span>
36
+ <span class="text-xs uppercase font-bold text-gray-500 dark:text-gray-400">
37
+ Misses
38
+ </span>
39
+ </div>
40
+ <div class="flex flex-col justify-center @sm:block">
41
+ <span class="text-xl uppercase font-bold text-gray-700 dark:text-gray-300 tabular-nums">
42
+ @if(allCacheInteractions.hits + allCacheInteractions.misses > 0)
43
+ {{ (Math.floor(allCacheInteractions.hits / (allCacheInteractions.hits + allCacheInteractions.misses) * 10000) / 100).toFixed(1) }}%
44
+ @else
45
+ 0%
46
+ @end
47
+ </span>
48
+ <span class="text-xs uppercase font-bold text-gray-500 dark:text-gray-400">
49
+ Hit Rate
50
+ </span>
51
+ </div>
52
+ </div>
53
+ <div>
54
+ <x-pulse::table>
55
+ <colgroup>
56
+ <col width="100%" />
57
+ <col width="0%" />
58
+ <col width="0%" />
59
+ <col width="0%" />
60
+ </colgroup>
61
+ <x-pulse::thead>
62
+ <tr>
63
+ <x-pulse::th>Key</x-pulse::th>
64
+ <x-pulse::th class="text-right">Hits</x-pulse::th>
65
+ <x-pulse::th class="text-right">Misses</x-pulse::th>
66
+ <x-pulse::th class="text-right whitespace-nowrap">Hit Rate</x-pulse::th>
67
+ </tr>
68
+ </x-pulse::thead>
69
+ <tbody>
70
+ @each(interaction in cacheKeyInteractions.slice(0, 100))
71
+ <tr class="h-2 first:h-0"></tr>
72
+ <tr>
73
+ <x-pulse::td class="max-w-[1px]">
74
+ <code class="block text-xs text-gray-900 dark:text-gray-100 truncate" title="{{ interaction.key }}">
75
+ {{ interaction.key }}
76
+ </code>
77
+ </x-pulse::td>
78
+ <x-pulse::td class="text-right tabular-nums text-gray-700 dark:text-gray-300 font-bold whitespace-nowrap">
79
+ @if(config.sampleRate < 1)
80
+ <span title="Sample rate: {{ config.sampleRate }}, Raw value: {{ formatNumber(interaction.hits) }}">~{{ formatNumber(Math.round(interaction.hits * (1 / config.sampleRate))) }}</span>
81
+ @else
82
+ {{ formatNumber(interaction.hits) }}
83
+ @end
84
+ </x-pulse::td>
85
+ <x-pulse::td class="text-right tabular-nums text-gray-700 dark:text-gray-300 font-bold whitespace-nowrap">
86
+ @if(config.sampleRate < 1)
87
+ <span title="Sample rate: {{ config.sampleRate }}, Raw value: {{ formatNumber(interaction.misses) }}">~{{ formatNumber(Math.round(interaction.misses * (1 / config.sampleRate))) }}</span>
88
+ @else
89
+ {{ formatNumber(interaction.misses) }}
90
+ @end
91
+ </x-pulse::td>
92
+ <x-pulse::td class="text-right tabular-nums text-gray-700 dark:text-gray-300 font-bold whitespace-nowrap">
93
+ @if(interaction.hits + interaction.misses > 0)
94
+ {{ (Math.floor(interaction.hits / (interaction.hits + interaction.misses) * 10000) / 100).toFixed(1) }}%
95
+ @else
96
+ 0%
97
+ @end
98
+ </x-pulse::td>
99
+ </tr>
100
+ @end
101
+ </tbody>
102
+ </x-pulse::table>
103
+
104
+ @if(cacheKeyInteractions.length > 100)
105
+ <div class="mt-2 text-xs text-gray-400 text-center">Limited to 100 entries</div>
106
+ @end
107
+ </div>
108
+ </div>
109
+ @end
110
+ </x-pulse::scroll>
111
+ </x-pulse::card>
@@ -0,0 +1,48 @@
1
+ <x-pulse::card :cols="cols ?? 6" :rows="rows ?? 1">
2
+ <x-pulse::card-header title="Exceptions" :details="'past ' + period">
3
+ <x-slot name="icon">
4
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5">
5
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 12.75c1.148 0 2.278.08 3.383.237 1.037.146 1.866.966 1.866 2.013 0 3.728-2.35 6.75-5.25 6.75S6.75 18.728 6.75 15c0-1.046.83-1.867 1.866-2.013A24.204 24.204 0 0 1 12 12.75Zm0 0c2.883 0 5.647.508 8.207 1.44a23.91 23.91 0 0 1-1.152 6.06M12 12.75c-2.883 0-5.647.508-8.208 1.44.125 2.104.52 4.136 1.153 6.06M12 12.75a2.25 2.25 0 0 0 2.248-2.354M12 12.75a2.25 2.25 0 0 1-2.248-2.354M12 8.25c.995 0 1.971-.08 2.922-.236.403-.066.74-.358.795-.762a3.778 3.778 0 0 0-.399-2.25M12 8.25c-.995 0-1.97-.08-2.922-.236-.402-.066-.74-.358-.795-.762a3.734 3.734 0 0 1 .4-2.253M12 8.25a2.25 2.25 0 0 0-2.248 2.146M12 8.25a2.25 2.25 0 0 1 2.248 2.146M8.683 5a6.032 6.032 0 0 1-1.155-1.002c.07-.63.27-1.222.574-1.747m.581 2.749A3.75 3.75 0 0 1 15.318 5m0 0c.427-.283.815-.62 1.155-.999a4.471 4.471 0 0 0-.575-1.752M4.921 6a24.048 24.048 0 0 0-.392 3.314c1.668.546 3.416.914 5.223 1.082M19.08 6c.205 1.08.337 2.187.392 3.314a23.882 23.882 0 0 1-5.223 1.082" />
6
+ </svg>
7
+ </x-slot>
8
+ </x-pulse::card-header>
9
+
10
+ <x-pulse::scroll>
11
+ @if(exceptions && exceptions.length > 0)
12
+ <x-pulse::table>
13
+ <colgroup>
14
+ <col width="100%" />
15
+ <col width="0%" />
16
+ </colgroup>
17
+ <x-pulse::thead>
18
+ <tr>
19
+ <x-pulse::th>Type</x-pulse::th>
20
+ <x-pulse::th class="text-right">Count</x-pulse::th>
21
+ </tr>
22
+ </x-pulse::thead>
23
+ <tbody>
24
+ @each(exception in exceptions)
25
+ <tr class="h-2 first:h-0"></tr>
26
+ <tr>
27
+ <x-pulse::td class="max-w-[1px]">
28
+ <div class="truncate font-medium text-red-600 dark:text-red-400" title="{{ exception.class }}">
29
+ {{ exception.class }}
30
+ </div>
31
+ @if(exception.location)
32
+ <div class="mt-0.5 truncate text-xs text-gray-500 dark:text-gray-400" title="{{ exception.location }}">
33
+ {{ exception.location }}
34
+ </div>
35
+ @end
36
+ </x-pulse::td>
37
+ <x-pulse::td class="text-right tabular-nums text-gray-700 dark:text-gray-300 font-bold whitespace-nowrap">
38
+ {{ formatNumber(exception.count) }}
39
+ </x-pulse::td>
40
+ </tr>
41
+ @end
42
+ </tbody>
43
+ </x-pulse::table>
44
+ @else
45
+ <x-pulse::no-results message="No exceptions" />
46
+ @end
47
+ </x-pulse::scroll>
48
+ </x-pulse::card>