|
| 1 | +Stackdriver Monitoring PHP Samples |
| 2 | +================================== |
| 3 | + |
| 4 | +This directory contains samples for Stackdriver Monitoring. |
| 5 | +[Stackdriver Monitoring][monitoring] collects metrics, events, and metadata from |
| 6 | +Google Cloud Platform, Amazon Web Services (AWS), hosted uptime probes, |
| 7 | +application instrumentation, and a variety of common application components |
| 8 | +including Cassandra, Nginx, Apache Web Server, Elasticsearch and many others. |
| 9 | + |
| 10 | +[monitoring]: https://cloud.google.com/monitoring/docs |
| 11 | + |
| 12 | +## Setup |
| 13 | + |
| 14 | +### Authentication |
| 15 | + |
| 16 | +Authentication is typically done through [Application Default Credentials][adc] |
| 17 | +which means you do not have to change the code to authenticate as long as |
| 18 | +your environment has credentials. You have a few options for setting up |
| 19 | +authentication: |
| 20 | + |
| 21 | +1. When running locally, use the [Google Cloud SDK][google-cloud-sdk] |
| 22 | + |
| 23 | + gcloud auth application-default login |
| 24 | + |
| 25 | +1. When running on App Engine or Compute Engine, credentials are already |
| 26 | + set-up. However, you may need to configure your Compute Engine instance |
| 27 | + with [additional scopes][additional_scopes]. |
| 28 | + |
| 29 | +1. You can create a [Service Account key file][service_account_key_file]. This file can be used to |
| 30 | + authenticate to Google Cloud Platform services from any environment. To use |
| 31 | + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to |
| 32 | + the path to the key file, for example: |
| 33 | + |
| 34 | + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json |
| 35 | + |
| 36 | +[adc]: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow |
| 37 | +[additional_scopes]: https://cloud.google.com/compute/docs/authentication#using |
| 38 | +[service_account_key_file]: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount |
| 39 | + |
| 40 | +## Install Dependencies |
| 41 | + |
| 42 | +1. Ensure the [gRPC PHP Extension][php_grpc] is installed and enabled on your machine. |
| 43 | +1. [Enable the Stackdriver Monitoring API](https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com). |
| 44 | + |
| 45 | +1. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md). |
| 46 | + Run `php composer.phar install` (if composer is installed locally) or `composer install` |
| 47 | + (if composer is installed globally). |
| 48 | + |
| 49 | +1. Create a service account at the |
| 50 | +[Service account section in the Cloud Console](https://console.cloud.google.com/iam-admin/serviceaccounts/) |
| 51 | + |
| 52 | +1. Download the json key file of the service account. |
| 53 | + |
| 54 | +1. Set `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to that file. |
| 55 | + |
| 56 | +## Samples |
| 57 | + |
| 58 | +To run the Stackdriver Monitoring Samples: |
| 59 | + |
| 60 | + $ php monitoring.php |
| 61 | + |
| 62 | + Stackdriver Monitoring |
| 63 | + |
| 64 | + Usage: |
| 65 | + command [options] [arguments] |
| 66 | + |
| 67 | + Options: |
| 68 | + -h, --help Display this help message |
| 69 | + -q, --quiet Do not output any message |
| 70 | + -V, --version Display this application version |
| 71 | + --ansi Force ANSI output |
| 72 | + --no-ansi Disable ANSI output |
| 73 | + -n, --no-interaction Do not ask any interactive question |
| 74 | + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug |
| 75 | + |
| 76 | + Available commands: |
| 77 | + create-metric Creates a logging metric. |
| 78 | + delete-metric Deletes a logging metric. |
| 79 | + get-descriptor Gets a logging descriptor. |
| 80 | + help Displays help for a command |
| 81 | + list Lists commands |
| 82 | + list-descriptors Lists logging descriptors. |
| 83 | + read-timeseries-align Aggregates metrics for each timeseries. |
| 84 | + read-timeseries-fields Reads Timeseries fields. |
| 85 | + read-timeseries-reduce Aggregates metrics across multiple timeseries. |
| 86 | + read-timeseries-simple Reads a timeseries. |
| 87 | + write-timeseries Writes a timeseries. |
| 88 | + |
| 89 | +## The client library |
| 90 | + |
| 91 | +This sample uses the [Google Cloud Client Library for PHP][google-cloud-php]. |
| 92 | +You can read the documentation for more details on API usage and use GitHub |
| 93 | +to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues]. |
| 94 | + |
| 95 | +[php_grpc]: http://cloud.google.com/php/grpc |
| 96 | +[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php |
| 97 | +[google-cloud-php-source]: https://github.com/GoogleCloudPlatform/google-cloud-php |
| 98 | +[google-cloud-php-issues]: https://github.com/GoogleCloudPlatform/google-cloud-php/issues |
| 99 | +[google-cloud-sdk]: https://cloud.google.com/sdk/ |
0 commit comments