How can I create a GCP monitoring dashboard?
To create a monitoring dashboard in Google Cloud Platform (GCP), you need to define a few resources including a Google Cloud Monitoring Dashboard. This resource will allow you to specify various widgets and their configurations to visualize your metrics appropriately.
Below is an example of how you can achieve this:
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Define a GCP Monitoring Dashboard resource
const exampleDashboard = new gcp.monitoring.Dashboard("example_dashboard", {dashboardJson: ` {
"displayName": "Sample Dashboard",
"gridLayout": {
"columns": 3,
"widgets": [
{
"title": "CPU Usage",
"xyChart": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"compute.googleapis.com/instance/cpu/utilization\"",
"aggregation": {
"alignmentPeriod": "120s",
"perSeriesAligner": "ALIGN_MEAN"
}
}
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"label": "CPU Usage (%)",
"scale": "LINEAR"
}
}
},
{
"title": "Disk Read Ops",
"xyChart": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"compute.googleapis.com/instance/disk/read_ops_count\"",
"aggregation": {
"alignmentPeriod": "120s",
"perSeriesAligner": "ALIGN_RATE"
}
}
}
}
],
"timeshiftDuration": "0s",
"yAxis": {
"label": "Read Operations",
"scale": "LINEAR"
}
}
}
]
}
}
`});
export const dashboardName = exampleDashboard.id;
This example defines a monitoring dashboard in GCP with two widgets: one for CPU usage and one for disk read operations. Each widget is configured to display the respective metrics using specific queries and alignments.
In summary, by creating a google_monitoring_dashboard
resource and defining the JSON for the dashboard layout and widgets, you can visualize GCP metrics on a custom dashboard. The provided setup shows how to configure the dashboard with one grid layout containing two widgets. The outputs show the name of the created dashboard for verification purposes.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.