This directory contains samples for calling Stackdriver Monitoring from PHP.
Stackdriver 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.
Authentication is typically done through Application Default Credentials 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:
-
When running locally, use the Google Cloud SDK
gcloud auth application-default login
-
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.
-
You can create a 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
-
Ensure the gRPC PHP Extension is installed and enabled on your machine.
-
Install dependencies via Composer. Run
php composer.phar install
(if composer is installed locally) orcomposer install
(if composer is installed globally). -
Create a service account at the Service account section in the Cloud Console
-
Download the json key file of the service account.
-
Set
GOOGLE_APPLICATION_CREDENTIALS
environment variable pointing to that file.
Execute the snippets in the src/ directory by running
php src/SNIPPET_NAME.php
. The usage will print for each if no arguments
are provided:
$ php src/list_resources.php
Usage: php src/list_resources.php PROJECT_ID
$ php src/list_resources.php 'your-project-id'
This sample uses the Cloud Monitoring Client Library for PHP. You can read the documentation for more details on API usage and use GitHub to browse the source and report issues.