使用带有数据库连接公式的Terraform设置数据库连接警报
我正在尝试设置Terraform中数据库连接的CloudWatch警报。
`resource "aws_cloudwatch_metric_alarm" "db_connections" {
alarm_name = "db_connections"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "DatabaseConnections"
namespace = "AWS/RDS"
period = "300"
statistic = "Average"
threshold = var.db_connection_threshold
alarm_description = "Db connections"
alarm_actions = [aws_sns_topic.topic.arn]
dimensions = {
DBInstanceIdentifier = "${var.db_instance_id}"
}
}
`
我要实现的是使用此公式最大的设置({log(dbinstanceclassmemory/805306368,2)*45},{log(log(dbinstanceclassmemory/8187281408,2)*1000})。如果大于90%,则警报会上升。 在Terraform中是否有任何可能性。我尝试给出var threshold = formula/100,但它不起作用。有什么建议吗?谢谢
I am trying to setup the Cloudwatch alarm for database connections in Terraform.
`resource "aws_cloudwatch_metric_alarm" "db_connections" {
alarm_name = "db_connections"
comparison_operator = "GreaterThanThreshold"
evaluation_periods = "1"
metric_name = "DatabaseConnections"
namespace = "AWS/RDS"
period = "300"
statistic = "Average"
threshold = var.db_connection_threshold
alarm_description = "Db connections"
alarm_actions = [aws_sns_topic.topic.arn]
dimensions = {
DBInstanceIdentifier = "${var.db_instance_id}"
}
}
`
What i am trying to achieve is to setup using this formula GREATEST({log(DBInstanceClassMemory/805306368,2)*45},{log(DBInstanceClassMemory/8187281408,2)*1000}). If it is greater than 90 percent then the Alarm rises.
Is there any possibility for that in Terraform. I tried with giving var threshold =formula/100 and it didn't work. Any suggestions? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您是否必须使用该公式来创建DB连接警报以及您使用的数据库引擎,但是,这是我设法计算数据库的最大连接并创建警报的方式。
我计算了知道实例内存的最大DB连接,并使用页面数据库连接的最大数量。例如,对于mysql:
要找到
dbinstanceclassmemory
,您必须将实例的内存从gib(gibibytes)转换为字节。可以在页面 DB实例类的硬件规格。因此,
db.t3.small
(mysql)的最大连接数为:因此该实例的最大值约为 170 Connections < / strong>。知道数字您可以轻松地使用百分比计算警报的阈值。
我的 Terraform 模块看起来像这样:
Notes!,因为我找不到有关内存的实例硬件规范的来源,我将其硬编码为local varible
数据集中
由于此信息的更改的可能性较小。Not sure whether you must use that formula to create the DB connections alarm and what database engine you use, however, here is how I managed to calculate the maximum connections for my databases and create the alarm.
I calculated the maximum DB connections knowing the instance's memory and using the formula from the page Maximum number of database connections. For instance, for MySQL:
To find the
DBInstanceClassMemory
, you must convert the instance's memory from GiB (Gibibytes) to Bytes.The instance classes' memory amount in GiB can be found on the page Hardware specifications for DB instance classes. So, the maximum number of connections for
db.t3.small
(MySQL) is:As a result, the instance can have a maximum of around 170 connections. Knowing the number you can easily calculate the threshold for your alarm using the percentage.
My Terraform module looks something like this:
NOTE! As I could not find the source of the instance's hardware specification about memory, I hardcoded it into the local variable
datasets
as this information is less likely to be changed.