Reference documentation and code samples for the Stackdriver Logging Client class Metric.
A metric counts the number of log entries that match a given filter. You can
use these metrics to create charts and alerting policies inStackdriver Monitoring.
Example:
use Google\Cloud\Logging\LoggingClient;
$logging = new LoggingClient();
$metric = $logging->metric('my-metric');
Namespace
Google \ Cloud \ Logging
Methods
__construct
Parameters
Name
Description
connection
Connection\ConnectionInterface
Represents a connection to Cloud
Logging. This object is created by LoggingClient,
and should not be instantiated outside of this client.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Stackdriver Logging Client - Class Metric (1.32.3)\n\nVersion latestkeyboard_arrow_down\n\n- [1.32.3 (latest)](/php/docs/reference/cloud-logging/latest/Metric)\n- [1.32.2](/php/docs/reference/cloud-logging/1.32.2/Metric)\n- [1.31.3](/php/docs/reference/cloud-logging/1.31.3/Metric)\n- [1.30.3](/php/docs/reference/cloud-logging/1.30.3/Metric)\n- [1.29.0](/php/docs/reference/cloud-logging/1.29.0/Metric)\n- [1.28.5](/php/docs/reference/cloud-logging/1.28.5/Metric)\n- [1.27.1](/php/docs/reference/cloud-logging/1.27.1/Metric)\n- [1.26.0](/php/docs/reference/cloud-logging/1.26.0/Metric)\n- [1.25.5](/php/docs/reference/cloud-logging/1.25.5/Metric)\n- [1.24.10](/php/docs/reference/cloud-logging/1.24.10/Metric) \nReference documentation and code samples for the Stackdriver Logging Client class Metric.\n\nA metric counts the number of log entries that match a given filter. You can\nuse these metrics to create charts and alerting policies in\n[Stackdriver Monitoring](https://cloud.google.com/monitoring/docs).\n\nExample: \n\n use Google\\Cloud\\Logging\\LoggingClient;\n\n $logging = new LoggingClient();\n\n $metric = $logging-\u003emetric('my-metric');\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Logging\n\nMethods\n-------\n\n### __construct\n\n### exists\n\nCheck whether or not the metric exists.\n\nExample: \n\n if ($metric-\u003eexists()) {\n echo 'Metric exists!';\n }\n\n### delete\n\nSee also:\n\n- [projects.metrics delete API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/projects.metrics/delete)\n\n### update\n\nSee also:\n\n- [projects.metrics update API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/projects.metrics/update)\n\n### info\n\nSee also:\n\n- [LogMetric resource API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/projects.metrics#resource-logmetric)\n\n### reload\n\nSee also:\n\n- [projects.metrics get API documentation.](https://cloud.google.com/logging/docs/api/reference/rest/v2/projects.metrics/get)\n\n### name\n\nReturns the metric's name.\n\nExample: \n\n echo $metric-\u003ename();"]]