SlapbirdAPM is a free and open-source application performance monitoring (APM) platform specifically designed for Perl web applications. It provides developers with comprehensive observability tools to monitor and optimize their applications' performance.
SlapbirdAPM is easily installed on your Plack application, here is a minimal example, using a Dancer2 application:
Install with
cpan -I SlapbirdAPM::Agent::Plack
#!/usr/bin/env perl
use Dancer2;
use Plack::Builder;
get '/' => sub {
'Hello World!';
};
builder {
enable 'SlapbirdAPM';
app;
};
Now, you can create an account on SlapbirdAPM, and create your application.
Then, simply copy the API key output and, add it to your application via the SLAPBIRDAPM_API_KEY
environment variable. For example:
SLAPBIRDAPM_API_KEY=<API-KEY> plackup app.pl
or, you can pass your key in to the middleware:
builder {
enable 'SlapbirdAPM', key => <YOUR API KEY>;
...
};
Now when you navigate to /
, you will see it logged in your Slapbird dashboard!
SlapbirdAPM also supports DBI, meaning you can trace your queries, let's edit our application to include a few DBI queries:
#!/usr/bin/env perl
use Dancer2;
use DBI;
use Plack::Builder;
my $dbh = DBI->connect( 'dbi:SQLite:dbname=database.db', '', '' );
$dbh->do('create table if not exists users (id integer primary key, name varchar)');
get '/' => sub {
send_as html => 'Hello World!';
};
get '/users/:id' => sub {
my $user_id = route_parameters->get('id');
my ($user) =
$dbh->selectall_array(
'select * from users where id = ?',
{ Slice => {} }, $user_id );
send_as JSON => $user;
};
post '/users' => sub {
my $user_name = body_parameters->get('name');
my ($user) =
$dbh->selectall_array(
'insert into users(name) values ( ? ) returning id, name',
{ Slice => {} }, $user_name );
send_as JSON => $user;
};
builder {
enable 'SlapbirdAPM';
app;
};
Now we can use cURL to add data to our database:
curl -X POST -d 'name=bob' http://127.0.0.1:5000/users
Then, if we go back into Slapbird, we can view our timings for our queries:
This just breaks the surface of what is possible using SlapbirdAPM. You can also, generate reports, perform health-checks, and get notified if your application is creating too many 5XX responses.
Thanks for reading!
Top comments (0)