Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/monitoring

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/monitoring

Stackdriver Monitoring API client for Node.js

  • 4.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
145K
increased by42.3%
Maintainers
1
Weekly downloads
 
Created

What is @google-cloud/monitoring?

@google-cloud/monitoring is a Node.js client library for interacting with Google Cloud Monitoring, which allows you to collect and manage metrics, create and manage alerting policies, and visualize your data in dashboards.

What are @google-cloud/monitoring's main functionalities?

Collecting Metrics

This feature allows you to list all the metric descriptors available in your Google Cloud project. Metric descriptors define the schema of the time series data.

const {MetricServiceClient} = require('@google-cloud/monitoring');
const client = new MetricServiceClient();

async function listMetrics() {
  const [descriptors] = await client.listMetricDescriptors({
    name: client.projectPath('your-project-id'),
  });
  descriptors.forEach(descriptor => console.log(descriptor.name));
}
listMetrics();

Creating Alert Policies

This feature allows you to create an alert policy that monitors a specific metric and triggers an alert when the metric exceeds a defined threshold.

const {AlertPolicyServiceClient} = require('@google-cloud/monitoring');
const client = new AlertPolicyServiceClient();

async function createAlertPolicy() {
  const projectId = 'your-project-id';
  const alertPolicy = {
    displayName: 'Test Alert Policy',
    conditions: [{
      displayName: 'Test Condition',
      conditionThreshold: {
        filter: 'metric.type="compute.googleapis.com/instance/cpu/utilization"',
        comparison: 'COMPARISON_GT',
        thresholdValue: 0.8,
        duration: {seconds: 60},
      },
    }],
    notificationChannels: [],
  };
  const [policy] = await client.createAlertPolicy({
    name: client.projectPath(projectId),
    alertPolicy,
  });
  console.log(`Created alert policy ${policy.name}`);
}
createAlertPolicy();

Creating Dashboards

This feature allows you to create a custom dashboard to visualize your metrics. The dashboard can include various widgets such as charts and tables.

const {DashboardsServiceClient} = require('@google-cloud/monitoring-dashboards');
const client = new DashboardsServiceClient();

async function createDashboard() {
  const projectId = 'your-project-id';
  const dashboard = {
    displayName: 'Test Dashboard',
    gridLayout: {
      widgets: [{
        title: 'CPU Utilization',
        xyChart: {
          dataSets: [{
            timeSeriesQuery: {
              timeSeriesFilter: {
                filter: 'metric.type="compute.googleapis.com/instance/cpu/utilization"',
              },
            },
          }],
        },
      }],
    },
  };
  const [response] = await client.createDashboard({
    parent: client.projectPath(projectId),
    dashboard,
  });
  console.log(`Created dashboard ${response.name}`);
}
createDashboard();

Other packages similar to @google-cloud/monitoring

Keywords

FAQs

Package last updated on 21 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc