Skip to content

Commit

Permalink
GDB-286 Added monitoring for graphdb
Browse files Browse the repository at this point in the history
* Added the necessary policy for the cloudwatch-agent
* Modified the user data script to enable the cloudwatch agent and configure it for the current tenant
* Added sample dashboard with a widget that monitors the cpu
* Added editorconfig
* Bumped GraphDB version to 10.4.0-RC8
  • Loading branch information
ivorusev authored and mihailradkov committed Oct 16, 2023
1 parent ed4548e commit d3ef5d6
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions examples/vpc-with-multiple-az/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ module "graphdb" {
ami_id = var.ami_id
graphdb_version = var.graphdb_version
}

module "monitoring" {
source = "./monitoring"

aws_region = var.aws_region
resource_name_prefix = var.resource_name_prefix
}
3 changes: 3 additions & 0 deletions examples/vpc-with-multiple-az/monitoring/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GraphDB AWS Monitoring Module

This module adds metrics scraping from GraphDB cluster to Cloudwatch.
33 changes: 33 additions & 0 deletions examples/vpc-with-multiple-az/monitoring/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
resource "aws_cloudwatch_dashboard" "main" {
dashboard_name = "${var.resource_name_prefix}-dashboard"

dashboard_body = jsonencode({
widgets = [
{
"height" : 6,
"width" : 6,
"y" : 0,
"x" : 0,
"type" : "metric",
"properties" : {
"metrics" : [
[
{
"expression" : "SELECT AVG(graphdb_cpu_load) FROM \"${var.resource_name_prefix}-graphdb\" GROUP BY host",
"id" : "q1",
"label" : "CPU",
"region" : var.aws_region,
"stat" : "Average"
}
]
],
"region" : var.aws_region,
"stacked" : false,
"view" : "timeSeries",
"period" : 300,
"stat" : "Average"
}
}
]
})
}
Empty file.
9 changes: 9 additions & 0 deletions examples/vpc-with-multiple-az/monitoring/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "resource_name_prefix" {
description = "Resource name prefix used for tagging and naming AWS resources"
type = string
}

variable "aws_region" {
description = "AWS region where GraphDB is being deployed"
type = string
}
10 changes: 10 additions & 0 deletions examples/vpc-with-multiple-az/monitoring/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.4.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.15"
}
}
}
5 changes: 5 additions & 0 deletions modules/iam/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ resource "aws_iam_instance_profile" "graphdb" {
role = var.user_supplied_iam_role_name != null ? var.user_supplied_iam_role_name : aws_iam_role.graphdb[0].name
}

resource "aws_iam_role_policy_attachment" "cloudwatch-agent-policy" {
role = aws_iam_role.graphdb[0].id
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
}

resource "aws_iam_role" "graphdb" {
count = var.user_supplied_iam_role_name != null ? 0 : 1
name_prefix = "${var.resource_name_prefix}-graphdb-"
Expand Down
1 change: 1 addition & 0 deletions modules/user_data/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ locals {
zone_id = var.zone_id

jvm_max_memory = local.jvm_max_memory
resource_name_prefix = var.resource_name_prefix
}
)
}
8 changes: 8 additions & 0 deletions modules/user_data/templates/start_graphdb.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ echo 'fs.file-max = 262144' | tee -a /etc/sysctl.conf

sysctl -p

tmp=$(mktemp)
jq '.logs.metrics_collected.prometheus.log_group_name = "${resource_name_prefix}-graphdb"' /etc/graphdb/cloudwatch-agent-config.json > "$tmp" && mv "$tmp" /etc/graphdb/cloudwatch-agent-config.json
jq '.logs.metrics_collected.prometheus.emf_processor.metric_namespace = "${resource_name_prefix}-graphdb"' /etc/graphdb/cloudwatch-agent-config.json > "$tmp" && mv "$tmp" /etc/graphdb/cloudwatch-agent-config.json
cat /etc/prometheus/prometheus.yaml | yq '.scrape_configs[].static_configs[].targets = ["localhost:7201"]' > "$tmp" && mv "$tmp" /etc/prometheus/prometheus.yaml

amazon-cloudwatch-agent-ctl -a start
amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/etc/graphdb/cloudwatch-agent-config.json

# the proxy service is set up in the AMI but not enabled there, so we enable and start it
systemctl daemon-reload
systemctl start graphdb
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ variable "ami_id" {
variable "graphdb_version" {
description = "GraphDB version"
type = string
default = "10.4.0-RC5"
default = "10.4.0-RC8"
nullable = false
}

Expand Down

0 comments on commit d3ef5d6

Please sign in to comment.