santiripper / watchtower by santiripper

Watchtower is a Laravel wrapper for sending custom metrics to Amazon AWS CloudWatch in a really pleasant & powerful way.
5,342
3
1
Package Data
Maintainer Username: santiripper
Maintainer Contact: santiripper@gmail.com (Santi Corrales)
Package Create Date: 2017-05-30
Package Last Update: 2017-06-09
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:16:30
Package Statistics
Total Downloads: 5,342
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 3
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

Watchtower

Packagist Packagist

Watchtower is a Laravel wrapper for sending custom metrics to Amazon AWS CloudWatch in a really pleasant & powerful way.

Be sure to read the CloudWatch docs first.

Requirements

Installation

Via Composer by running

composer require santiripper/watchtower

Or editing composer.json

{
    "require": {
        "santiripper/watchtower" : "dev-master"
    }
}

To use the Watchtower Service Provider, you must register the provider when bootstrapping your Laravel application.

Find the providers key in your config/app.php and register the Watchtower Service Provider.

'providers' => array(
    // ...
    Santiripper\Watchtower\WatchtowerServiceProvider::class,
)

Optional, find the aliases key in your config/app.php and register the Watchtower Service Provider.

'aliases' => array(
    // ...
    'Watchtower' => Santiripper\Watchtower\Facade::class`
)

Configuration

Publish the config file by running

php artisan vendor:publish --tag=watchtower

It will create the file app/config/watchtower.php

Be sure to configure the Laravel AWS PHP SDK properly (regions & credentials)

Usage

You can usage it via helper function

cloudwatch()->on(...);

Or by facade

Cloudwatch::on(...);

Namespaces

Watchtower supports multiple Cloudwatch namespaces. To select the namespace of the metric you have to specify it using the method on, for ex if our namespace is called AwesomeApp:

$awesomeApp = cloudwatch()->on('AwesomeApp');

Facade way:

$awesomeApp = Cloudwatch::on('AwesomeApp');

Also you can use the helper shortcut by passing the metric namespace as parameter to the main function:

$awesomeApp = cloudwatch('AwesomeApp');

Adding metrics

$dimensions = [
    cloudwatch()->dimension('NameDimension1', 'ValueDimension2'),
    cloudwatch()->dimension('NameDimension1', 'ValueDimension2'),
];
$awesomeApp->newMetric('MetricName', 14, 'Count', $dimensions);

Setting default dimensions

You can configure default metric dimensions on namespaces that will be included on all related metrics.

Programatically:

$dimension = watchtower()->dimension('name', 'value');
$awesomeApp->addDefaultDimension($dimension);

Or by config on the conig/watchtower.php file:

'default_dimensions' => [
    'on' => [
        //Namespace
        'AwesomeApp' => [
            ['name' => 'test_name_1', 'value' => 'test_value_2'],
            ['name' => 'test_name_2', 'value' => 'test_value_2'],
        ],
    ],
],

Sending

By defaults, watchtower queues metrics on memory and sends it automatically when the scripts shutdown. You can configure this behavior on the watchtower config.

If you need to send the metrics at the moment you can do it by executing the sent method:

cloudwatch()->send();

ToDo

  • [ ] Add StatisticValues support
  • [ ] Add support to output to aws console
  • [ ] Write tests