Skip to content

Pulse ​

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:

bash
dotnet add package DotBlaze.Pulse
bash
dotblaze migrate

The 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:

csharp
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 },
        },
    };
}
KeyDefaultDescription
enabledtrue, except in the Testing environmentRecord entries.
pathpulseWhere the dashboard is.
ignore_pathsdashboards and assetsRequests to these paths are not recorded. A trailing * matches any rest of the path.
trim_days7Days of data to keep. Older entries are deleted automatically.
recorders.*.threshold1000Milliseconds from which a request, query, job, or outgoing request counts as slow.
recorders.servers.interval15Seconds between readings of the server's load.
recorders.servers.directoriesthe app's driveDisks to show the usage of.
recorders.servers.server_namethe machine nameThe 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:

csharp
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:

csharp
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.

CardShows
ServersEach 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 UsageThe users with the most requests, slow requests, or dispatched jobs.
ExceptionsReported exceptions by type and location, with how often each happened and when it last did.
QueuesPer connection and queue: queued, processing, processed, released, and failed jobs, and the processed jobs over the period.
Slow RequestsRoutes (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 RequestsThe same for jobs, SQL commands, and requests sent with the Http client (grouped by URL without the query string).
CacheHits, 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:

csharp
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:

bash
dotblaze pulse:check

pulse: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:

csharp
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:

bash
dotblaze pulse:clear

Complete Example: Authorized Performance Dashboard ​

Install DotBlaze.Pulse in the Blog application, run dotblaze migrate, and create:

csharp
// 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:

csharp
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.