Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GDB-286 initial commit with tf new module #14

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" {
mihailradkov marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 2 additions & 1 deletion modules/user_data/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ locals {
zone_dns_name = var.zone_dns_name
zone_id = var.zone_id

jvm_max_memory = local.jvm_max_memory
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