@@ -48,52 +48,6 @@ const getLogEntries = async () => {
4848} ;
4949// [END functions_log_retrieve]
5050
51- // [START functions_log_get_metrics]
52- // By default, the client will authenticate using the service account file
53- // specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
54- // the project specified by the GCLOUD_PROJECT environment variable. See
55- // https://github.com/googleapis/google-cloud-node/blob/master/docs/authentication.md
56- const Monitoring = require ( '@google-cloud/monitoring' ) ;
57-
58- const getMetrics = ( callback ) => {
59- // Instantiates a client
60- const monitoring = Monitoring . v3 ( ) . metricServiceApi ( ) ;
61-
62- // Create two datestrings, a start and end range
63- const oneWeekAgo = new Date ( ) ;
64- oneWeekAgo . setHours ( oneWeekAgo . getHours ( ) - 7 * 24 ) ;
65-
66- const options = {
67- name : monitoring . projectPath ( process . env . GCLOUD_PROJECT ) ,
68- // There is also: cloudfunctions.googleapis.com/function/execution_count
69- filter :
70- 'metric.type="cloudfunctions.googleapis.com/function/execution_times"' ,
71- interval : {
72- startTime : {
73- seconds : oneWeekAgo . getTime ( ) / 1000 ,
74- } ,
75- endTime : {
76- seconds : Date . now ( ) / 1000 ,
77- } ,
78- } ,
79- view : 1 ,
80- } ;
81-
82- console . log ( 'Data:' ) ;
83-
84- let error ;
85-
86- // Iterate over all elements.
87- monitoring
88- . listTimeSeries ( options )
89- . on ( 'error' , ( err ) => {
90- error = err ;
91- } )
92- . on ( 'data' , ( element ) => console . log ( element ) )
93- . on ( 'end' , ( ) => callback ( error ) ) ;
94- // [END functions_log_get_metrics]
95- } ;
96-
9751// [START functions_log_stackdriver]
9852exports . processLogEntry = ( data ) => {
9953 const dataBuffer = Buffer . from ( data . data , 'base64' ) ;
@@ -106,4 +60,3 @@ exports.processLogEntry = (data) => {
10660// [END functions_log_stackdriver]
10761
10862exports . getLogEntries = getLogEntries ;
109- exports . getMetrics = getMetrics ;
0 commit comments