Cloud Monitoring can be used to monitor system status and send alert notifications. I mainly use to monitor hard disk capacity and some custom statuses. I installed Ops Agent on all machines to monitor hard disk status. But I later realized the bill was expensive, so I did some research on its fees and how to keep costs down.

Pricing

First of all, let’s understand the pricing of Cloud Monitoring. Mostly, only the first feature is used. The first 150 MiB of this part is a free quota. If we can keep below this, it can be used for free. This article is also for the description of this part.

Billing

Click Billing to find an item called Metric Volume, which is the cost of Cloud Monitoring data.
Billing

We can see that there is no such item in the first few days of the month. It only appears on the 5th because of the free quota 150 MiB for the first few days. After that, You can see that it costs about $4.3 per day. This is the case for 8 servers.

You can also see how much traffic is charged.
Cost

Usage

From the monitoring [Settings] tab, under GCP Projects, expand the project name, you can see the overall usage.
Usage

Click [View in Metrics Exploer] on the right side of Agent Metrics to check the usage report by time.
Metrics Exploer

However, the cost cannot be calculated here. The calculation method is quite complicated. Some of which are free mertics, and some are discounted mertics. It can be seen that the usage displayed here is inconsistent with the billing. But it can be used to quickly check the usage changes after setting.

For the part of the billing mertics, I deduce it from the bill, 8 servers are $4.3 per day, one is $0.5375 per day, and $0.2580 per MiB. So by default, the billing usage generated by each server per day is 2.08 MiB.

Solutions

With the goal of reducing usage, apply the following strategies:

  • Disable Ops Agent on unimportant servers.
  • Report only necessary metrics.
  • Reduce frequency.

We can modify the Ops Agent configuration file to achieve the purpose.

1
sudo vi /etc/google-cloud-ops-agent/config.yaml

Add the following settings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
metrics:
receivers:
hostmetrics:
type: hostmetrics
# Modify the frequency, the default is 60 seconds. For example, change it to 120 seconds
collection_interval: 120s
processors:
metrics_filter:
type: exclude_metrics
metrics_pattern:
# The following are the metrics to be excluded. Comment out the required metrics. For example, only report the metrics of disk.
- agent.googleapis.com/cpu/*
#- agent.googleapis.com/disk/*
- agent.googleapis.com/interface/*
- agent.googleapis.com/memory/*
- agent.googleapis.com/network/*
- agent.googleapis.com/swap/*
- agent.googleapis.com/processes/*
- agent.googleapis.com/pagefile/*
- agent.googleapis.com/iis/*
- agent.googleapis.com/mssql/*
service:
pipelines:
default_pipeline:
receivers: [hostmetrics]
processors: [metrics_filter]

Restart to apply

1
sudo service google-cloud-ops-agent restart

Older versions of Ops Agent may not support the above settings. For example, some of my old servers cannot install the latest Ops Agent, and there is no way to exclude metrics.