Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
Stackdriver Monitoring PHP Samples
==================================

This directory contains samples for Stackdriver Monitoring.
[Stackdriver Monitoring][monitoring] collects metrics, events, and metadata from
Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes,
application instrumentation, and a variety of common application components
including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others.

[monitoring]: https://cloud.google.com/monitoring/docs

## Setup

### Authentication

Authentication is typically done through [Application Default Credentials][adc]
which means you do not have to change the code to authenticate as long as
your environment has credentials. You have a few options for setting up
authentication:

1. When running locally, use the [Google Cloud SDK][google-cloud-sdk]

gcloud auth application-default login

1. When running on App Engine or Compute Engine, credentials are already
set-up. However, you may need to configure your Compute Engine instance
with [additional scopes][additional_scopes].

1. You can create a [Service Account key file][service_account_key_file]. This file can be used to
authenticate to Google Cloud Platform services from any environment. To use
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
the path to the key file, for example:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json

[adc]: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
[additional_scopes]: https://cloud.google.com/compute/docs/authentication#using
[service_account_key_file]: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount

## Install Dependencies

1. Ensure the [gRPC PHP Extension][php_grpc] is installed and enabled on your machine.
1. [Enable the Stackdriver Monitoring API](https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com).

1. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
Run `php composer.phar install` (if composer is installed locally) or `composer install`
(if composer is installed globally).

1. Create a service account at the
[Service account section in the Cloud Console](https://console.cloud.google.com/iam-admin/serviceaccounts/)

1. Download the json key file of the service account.

1. Set `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to that file.

## Samples

To run the Stackdriver Monitoring Samples:

$ php monitoring.php

Stackdriver Monitoring

Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
create-metric Creates a logging metric.
delete-metric Deletes a logging metric.
get-descriptor Gets a logging descriptor.
help Displays help for a command
list Lists commands
list-descriptors Lists logging descriptors.
read-timeseries-align Aggregates metrics for each timeseries.
read-timeseries-fields Reads Timeseries fields.
read-timeseries-reduce Aggregates metrics across multiple timeseries.
read-timeseries-simple Reads a timeseries.
write-timeseries Writes a timeseries.

## The client library

This sample uses the [Google Cloud Client Library for PHP][google-cloud-php].
You can read the documentation for more details on API usage and use GitHub
to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues].

[php_grpc]: http://cloud.google.com/php/grpc
[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php
[google-cloud-php-source]: https://github.com/GoogleCloudPlatform/google-cloud-php
[google-cloud-php-issues]: https://github.com/GoogleCloudPlatform/google-cloud-php/issues
[google-cloud-sdk]: https://cloud.google.com/sdk/
20 changes: 17 additions & 3 deletions monitoring/composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
{
"require": {
"google/cloud-monitoring": "^0.4"
"google/cloud-monitoring": "^0.4",
"symfony/console": "^3.3"
},
"autoload": {
"files": [
"src/create_metric.php",
"src/delete_metric.php",
"src/get_descriptor.php",
"src/list_descriptors.php",
"src/read_timeseries_align.php",
"src/read_timeseries_fields.php",
"src/read_timeseries_reduce.php",
"src/read_timeseries_simple.php",
"src/write_timeseries.php"
]
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"squizlabs/php_codesniffer": "2.*"
"phpunit/phpunit": "^4",
"google/cloud-tools": "^0.6"
}
}
Loading