AWS EC2 Auto Scaling, Target Tracking Policies and Prometheus Exporters

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • pulumi-ec2-cloudwatch-prometheus-autoscaling

    A demo Pulumi project to set up EC2 autoscaling policies based on Prometheus exporters metrics

    You may find the source code for this demo in this Github repo.

  • node_exporter

    Exporter for machine metrics

    #!/bin/bash yum update -y # Install CWA yum install amazon-cloudwatch-agent -y # Install Nginx and configure the stub status module amazon-linux-extras install nginx1.12 -y aws ssm get-parameter --name {{ nginx_stub_status_config_parameter_path }} --region {{ region }} --output text --query Parameter.Value > {{ nginx_config_file_path }} # Add a user to run the exporters useradd --no-create-home metrics_exporter # Install Node Exporter wget https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz tar xzf node_exporter-1.4.0.linux-amd64.tar.gz cp node_exporter-1.4.0.linux-amd64/node_exporter /usr/local/bin/node_exporter rm -rf node_exporter-1.4.0.linux-amd64.tar.gz node_exporter-1.4.0.linux-amd64 # Create Node Exporter systemd service cat << 'EOF' > /etc/systemd/system/node-exporter.service [Unit] Description=Prometheus Node Exporter Service After=network.target [Service] User=metrics_exporter Group=metrics_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target EOF # Install Nginx Exporter wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz tar xzf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz cp nginx-prometheus-exporter /usr/local/bin/nginx-prometheus-exporter rm -rf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz nginx-prometheus-exporter # Create Nginx Exporter systemd service cat << 'EOF' > /etc/systemd/system/nginx-prometheus-exporter.service [Unit] Description=Prometheus Nginx Exporter Service After=network.target [Service] User=metrics_exporter Group=metrics_exporter Type=simple ExecStart=/usr/local/bin/nginx-prometheus-exporter -nginx.scrape-uri http://127.0.0.1:{{ nginx_stub_status_port }}/metrics -web.listen-address=127.0.0.1:9113 [Install] WantedBy=multi-user.target EOF # Configure CWA aws ssm get-parameter --name {{ cwa_prometheus_parameter_path }} --region {{ region }} --with-decryption --output text --query Parameter.Value > /opt/aws/amazon-cloudwatch-agent/etc/prometheus.yml /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:"{{ cwa_settings_parameter_path }}" -s # Start everything up systemctl daemon-reload systemctl enable nginx systemctl start nginx systemctl enable node-exporter systemctl start node-exporter systemctl enable nginx-prometheus-exporter systemctl start nginx-prometheus-exporter

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

  • nginx-prometheus-exporter

    NGINX Prometheus Exporter for NGINX and NGINX Plus

    #!/bin/bash yum update -y # Install CWA yum install amazon-cloudwatch-agent -y # Install Nginx and configure the stub status module amazon-linux-extras install nginx1.12 -y aws ssm get-parameter --name {{ nginx_stub_status_config_parameter_path }} --region {{ region }} --output text --query Parameter.Value > {{ nginx_config_file_path }} # Add a user to run the exporters useradd --no-create-home metrics_exporter # Install Node Exporter wget https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz tar xzf node_exporter-1.4.0.linux-amd64.tar.gz cp node_exporter-1.4.0.linux-amd64/node_exporter /usr/local/bin/node_exporter rm -rf node_exporter-1.4.0.linux-amd64.tar.gz node_exporter-1.4.0.linux-amd64 # Create Node Exporter systemd service cat << 'EOF' > /etc/systemd/system/node-exporter.service [Unit] Description=Prometheus Node Exporter Service After=network.target [Service] User=metrics_exporter Group=metrics_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target EOF # Install Nginx Exporter wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz tar xzf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz cp nginx-prometheus-exporter /usr/local/bin/nginx-prometheus-exporter rm -rf nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz nginx-prometheus-exporter # Create Nginx Exporter systemd service cat << 'EOF' > /etc/systemd/system/nginx-prometheus-exporter.service [Unit] Description=Prometheus Nginx Exporter Service After=network.target [Service] User=metrics_exporter Group=metrics_exporter Type=simple ExecStart=/usr/local/bin/nginx-prometheus-exporter -nginx.scrape-uri http://127.0.0.1:{{ nginx_stub_status_port }}/metrics -web.listen-address=127.0.0.1:9113 [Install] WantedBy=multi-user.target EOF # Configure CWA aws ssm get-parameter --name {{ cwa_prometheus_parameter_path }} --region {{ region }} --with-decryption --output text --query Parameter.Value > /opt/aws/amazon-cloudwatch-agent/etc/prometheus.yml /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:"{{ cwa_settings_parameter_path }}" -s # Start everything up systemctl daemon-reload systemctl enable nginx systemctl start nginx systemctl enable node-exporter systemctl start node-exporter systemctl enable nginx-prometheus-exporter systemctl start nginx-prometheus-exporter

  • kubespy

    Tools for observing Kubernetes resources in real time, powered by Pulumi.

    Pulumi IaC will help us bring up our infrastructure on the AWS Cloud. Check out pulumi.com if you still need to become familiar with it. You can deploy this demo stack using the Pulumi button below.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts