Cloudfunctions использует Stackdriver для захвата и отображения этих метрик.(Я предполагаю, что вы ищете те же метрики, которые отображаются для каждой функции в консоли.) StackDriver имеет API и клиентскую библиотеку, где вы можете получить метрики.Больше информации об этом на https://cloud.google.com/monitoring/docs/reference/libraries#client-libraries-install-nodejs.
Вот небольшой пример их извлечения в файле node.js
const util = require("util");
// Imports the Google Cloud client library
const monitoring = require("@google-cloud/monitoring");
// Your Google Cloud Platform project ID
const projectId = "<YOUR PROJECT ID>";
// Creates a client
const client = new monitoring.MetricServiceClient({
keyFilename: "<YOUR CREDENTIALS>"
});
// list of metrics also avaliable at https://cloud.google.com/monitoring/api/metrics_gcp#gcp-cloudfunctions
// list all metrics avaliable
client
.listMetricDescriptors({
// name: `projects/${projectId}/monitoredResourceDescriptors/cloud_function`,
name: `projects/${projectId}`,
filter: 'metric.type = starts_with("cloudfunctions.googleapis.com")'
})
.then(results => {
console.log(results);
})
.catch(err => {
console.error("ERROR:", err);
});
const currentTime = new Date();
endTime = currentTime.toISOString();
startTime = new Date(currentTime - 1 * 60 * 60 * 1000).toISOString();
interval = {
startTime: {
// Limit results to the last 20 minutes
seconds: Date.now() / 1000 - 60 * 60
},
endTime: {
seconds: Date.now() / 1000
}
};
// get the executions accross time
client
.listTimeSeries({
name: `projects/${projectId}`,
filter:
'metric.type = "cloudfunctions.googleapis.com/function/execution_count" AND resource.label.function_name = "<YOUR FUNCTION NAME>"',
view: "FULL",
interval
})
.then(results => {
// console.log(results);
console.log(util.inspect(results, { showHidden: true, depth: 5 }));
})
.catch(err => {
console.error("ERROR:", err);
});