Pulse
- Introduction
- Complete Example: Authorized Performance Dashboard
- Installation
- The Dashboard
- Capturing Entries
- Performance
Introduction
DotBlaze.Pulse gives you an at-a-glance view of your application's performance and usage, like Laravel Pulse. Its dashboard at /pulse shows:
- your servers' CPU, memory, and disk usage,
- the users who make the most requests and dispatch the most jobs,
- slow requests, slow queries, slow jobs, and slow outgoing HTTP requests,
- exceptions,
- the throughput of your queues,
- cache hits and misses.
For the details of single requests while you develop, use Telescope instead.
Installation
Add the package and run its migration, which creates the pulse_entries and pulse_values tables:
dotnet add package DotBlaze.Pulsedotblaze migrateThe dashboard is at /pulse. DotBlaze finds the package by itself; there is nothing to register.
Configuration
To change Pulse's defaults, add config/Pulse.cs:
public class PulseConfig : ConfigFile
{
public override object Values() => new
{
enabled = !IsEnvironment("Testing"),
path = "pulse",
ignore_paths = new[] { "pulse*", "telescope*", "horizon*", "_dotblaze/*", "_live/*", "broadcasting*", "favicon.ico" },
trim_days = 7,
recorders = new
{
servers = new { enabled = true, interval = 15, directories = new[] { "/" } },
user_requests = new { enabled = true },
user_jobs = new { enabled = true },
slow_requests = new { enabled = true, threshold = 1000 },
slow_queries = new { enabled = true, threshold = 1000 },
slow_jobs = new { enabled = true, threshold = 1000 },
slow_outgoing_requests = new { enabled = true, threshold = 1000 },
exceptions = new { enabled = true },
queues = new { enabled = true },
cache_interactions = new { enabled = true },
},
};
}| Key | Default | Description |
|---|---|---|
enabled | true, except in the Testing environment | Record entries. |
path | pulse | Where the dashboard is. |
ignore_paths | dashboards and assets | Requests to these paths are not recorded. A trailing * matches any rest of the path. |
trim_days | 7 | Days of data to keep. Older entries are deleted automatically. |
recorders.*.threshold | 1000 | Milliseconds from which a request, query, job, or outgoing request counts as slow. |
recorders.servers.interval | 15 | Seconds between readings of the server's load. |
recorders.servers.directories | the app's drive | Disks to show the usage of. |
recorders.servers.server_name | the machine name | The name the server has on the dashboard. |
Dashboard Authorization
In the Development environment, everyone can open the dashboard. In every other environment, only users that the viewPulse gate allows can:
public override void Boot(WebApplication app)
{
Gate.Define<User>("viewPulse", user => user.IsAdmin);
}To decide in another way, use Pulse.Auth, which replaces both the environment check and the gate:
Pulse.Auth(context => context.Connection.RemoteIpAddress?.ToString() == "10.0.0.5");The Dashboard
Choose the period at the top: the last hour, 6 hours, 24 hours, or 7 days. The dashboard refreshes every ten seconds.
| Card | Shows |
|---|---|
| Servers | Each server's CPU and memory usage over the period, and its disk usage. A server that sent no reading in the last minute is shown as offline. |
| Application Usage | The users with the most requests, slow requests, or dispatched jobs. |
| Exceptions | Reported exceptions by type and location, with how often each happened and when it last did. |
| Queues | Per connection and queue: queued, processing, processed, released, and failed jobs, and the processed jobs over the period. |
| Slow Requests | Routes (by their pattern, such as /posts/{post}) with requests slower than the threshold, how often, and the slowest time. |
| Slow Jobs, Slow Queries, Slow Outgoing Requests | The same for jobs, SQL commands, and requests sent with the Http client (grouped by URL without the query string). |
| Cache | Hits, misses, and the hit rate, and the most-read keys. |
Resolving Users
The Application Usage card shows each user's Name and Email properties. To show something else, use Pulse.User:
Pulse.User(user =>
{
var u = (User)user;
return new PulseUser(u.Name, u.Company, u.AvatarUrl);
});Capturing Entries
Servers
The web application records its own server's load every 15 seconds. On a server that does not run the web application, such as one that only runs queue workers, keep pulse:check running under your process supervisor, like Laravel's:
dotblaze pulse:checkpulse:check --once takes one reading and exits. On Linux, Pulse reads the CPU and memory usage of the whole machine from /proc; on other systems, it shows the usage of the process itself.
Recorders
Pulse records from DotBlaze's framework events, in every process (the web app, queue:work, queue:manager's workers, and commands). Turn a recorder off with enabled = false in its section.
To record a value of your own, use Pulse.Record. Read it back from the pulse_entries table:
Pulse.Record("checkout", user.Id.ToString(), value: order.TotalCents);Performance
Pulse keeps recorded entries in memory and writes them in the background, about once a second, in batches. A request only adds an entry to a list. The dashboard groups the entries when it shows them, so its queries read through the period you chose. For very busy applications, raise the thresholds and turn off the recorders you do not need.
To clear everything Pulse has recorded:
dotblaze pulse:clearComplete Example: Authorized Performance Dashboard
Install DotBlaze.Pulse in the Blog application, run dotblaze migrate, and create:
// app/Providers/PulseAccessProvider.cs
using Blog.Models;
using DotBlaze;
using DotBlaze.Pulse;
using Microsoft.AspNetCore.Builder;
namespace Blog.Providers;
public class PulseAccessProvider : Provider
{
public override void Boot(WebApplication app)
{
Gate.Define<User>("viewPulse", user => user.Email == "operator@example.test");
Pulse.Auth(context => Gate.Allows("viewPulse"));
}
}Register that local operator account, sign in, and open /pulse. This callback enforces the gate in Development too. Generate ordinary page requests and run dotblaze pulse:check --once to capture a server reading. Slow-operation cards only show work above their configured thresholds; an empty card is not proof that recording failed.
For application-owned metrics, inside a request or command:
DotBlaze.Pulse.Pulse.Record("documentation", "completed", value: 1L);
await DotBlaze.Pulse.Pulse.Flush();
var entries = await DB.Table("pulse_entries").Where("type", "documentation").Get();Flush makes buffered records available for deterministic inspection. Custom records do not automatically add dashboard cards. See DashboardsTest.cs for recorder and authorization checks. In the Testing environment, enable recording explicitly in the test fixture only when testing Pulse itself.