Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bbc/rmp-monitoringhandler
Handler for RMP projects to post monitoring events to cloudwatch
https://github.com/bbc/rmp-monitoringhandler
bbc-programmes
Last synced: 12 days ago
JSON representation
Handler for RMP projects to post monitoring events to cloudwatch
- Host: GitHub
- URL: https://github.com/bbc/rmp-monitoringhandler
- Owner: bbc
- License: apache-2.0
- Created: 2015-10-30T13:52:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-21T10:53:00.000Z (almost 7 years ago)
- Last Synced: 2024-11-06T00:35:44.705Z (2 months ago)
- Topics: bbc-programmes
- Language: PHP
- Size: 38.1 KB
- Stars: 1
- Watchers: 46
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudwatch Monitoring Handler
This is a small PHP component which will add metrics to your cloudwatch account.
## What powers it
- PHP 5.6
- Composer
- aws sdk## How to integrate
Add the project in composer.json:```
"repositories": [
{
"type": "vcs",
"url": "[email protected]:bbc/rmp-monitoringhandler.git"
}
],
"require": {
"bbc-rmp/cloudwatch-monitoringhandler": "dev-master",
}
```Run `composer install`
## Usage
```php
use RMP\CloudwatchMonitoringHandler\MonitoringHandler;
use Aws\CloudWatch\CloudWatchClient;
use RMP\CloudwatchMonitoring\CloudWatchClientMock; // cloudwatchMonitoring comes with a cloudWatchClient Mock$app['env'] = "int";
// This example is using Silex application DI container
$app['monitoring'] = $app->share(function ($c) use ($app) {
// You will need to grab yourself a cloudwatchClient from aws
$cloudwatchClient = new CloudWatchClient([
"region" => "eu-west-1",
"version" => "2010-08-01"
]);
/*
If we're running this from our sandbox, just mock the monitoring, as it cannot communicate
to AWS from our sandbox or localhost
*/
if ($app['env'] === "local" || $app['env'] === "unittests") {
$cloudwatchClient = new CloudWatchClientMock();
return new MonitoringHandler($cloudwatchClient, "your-project-name", $app['env']);
}
$monitor = new MonitoringHandler($cloudwatchClient, "your-project-name", $app['env']);
return $monitor;});
// Usage
$app['monitoring']->application500Error() // This will send a value of 1 to Http500Error metric, with the instance-id and the BBCEnvironment as values too
$app['monitoring']->application404Error() // This will send a value of 1 to Http404Error metric, with the instance-id and the BBCEnvironment as values too
$app['monitoring']->applicationError() // This will send a value of 1 to applicationError metric, with the instance-id and the BBCEnvironment as values too. This is used as a catchAll error for anything not a 404 or a 500
$app['monitoring']->customApplicationError('your error message') // This will send a value of 1 to applicationError metric, with the instance-id and the BBCEnvironment as values too, it will also send error: your error message as another dimension
```## Unit Test Helpers
Unit testing for monitoring is a pain in the backside as the data structure passed to CloudWatch is fairly complex.
To help, this library provides a trait you can put in your TestCases to ease this process:```php
assertMonitoringContains($monitor, 'applicationError');
// Asserts that the monitoring has seen a metric with the MetricName of 'applicationError' AND
// that that metric has a given dimension:
$this->assertMonitoringHasDimension($monitor, 'applicationError', ['Name' => 'backend', 'Value' => 'blur']);
// Asserts that the monitoring has seen a metric with the MetricName of 'applicationError' AND
// that that metric has a given value (22):
$this->assertMonitoringHasValue($monitor, 'applicationError', 22);
}
}```
## License
This repository is available under the terms of the Apache 2.0 license.
View the LICENSE file for more information.Copyright (c) 2017 BBC