(projectId)
| 15 | 'use strict'; |
| 16 | |
| 17 | async function main(projectId) { |
| 18 | // [START monitoring_quickstart] |
| 19 | // Imports the Google Cloud client library |
| 20 | const monitoring = require('@google-cloud/monitoring'); |
| 21 | |
| 22 | async function quickstart() { |
| 23 | // Creates a client |
| 24 | const client = new monitoring.MetricServiceClient(); |
| 25 | |
| 26 | // TODO(developer): Uncomment and set the following variables |
| 27 | // const projectId = "PROJECT_ID" |
| 28 | |
| 29 | // Prepares an individual data point |
| 30 | const dataPoint = { |
| 31 | interval: { |
| 32 | endTime: { |
| 33 | seconds: Date.now() / 1000, |
| 34 | }, |
| 35 | }, |
| 36 | value: { |
| 37 | // The amount of sales |
| 38 | doubleValue: 123.45, |
| 39 | }, |
| 40 | }; |
| 41 | |
| 42 | // Prepares the time series request |
| 43 | const request = { |
| 44 | name: client.projectPath(projectId), |
| 45 | timeSeries: [ |
| 46 | { |
| 47 | // Ties the data point to a custom metric |
| 48 | metric: { |
| 49 | type: 'custom.googleapis.com/stores/daily_sales', |
| 50 | labels: { |
| 51 | store_id: 'Pittsburgh', |
| 52 | }, |
| 53 | }, |
| 54 | resource: { |
| 55 | type: 'global', |
| 56 | labels: { |
| 57 | project_id: projectId, |
| 58 | }, |
| 59 | }, |
| 60 | points: [dataPoint], |
| 61 | }, |
| 62 | ], |
| 63 | }; |
| 64 | |
| 65 | // Writes time series data |
| 66 | const [result] = await client.createTimeSeries(request); |
| 67 | console.log('Done writing time series data.', result); |
| 68 | } |
| 69 | quickstart(); |
| 70 | // [END monitoring_quickstart] |
| 71 | } |
| 72 | |
| 73 | process.on('unhandledRejection', err => { |
| 74 | console.error(err.message); |
no test coverage detected