<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Terraform on Rifky Ardiansyah</title>
    <link>https://rifkyards.github.io/tags/terraform/</link>
    <description>Recent content in Terraform on Rifky Ardiansyah</description>
    <image>
      <title>Rifky Ardiansyah</title>
      <url>https://rifkyards.github.io/images/papermod-cover.png</url>
      <link>https://rifkyards.github.io/images/papermod-cover.png</link>
    </image>
    <generator>Hugo -- 0.137.1</generator>
    <language>en</language>
    <lastBuildDate>Mon, 10 Mar 2025 07:13:02 +0000</lastBuildDate>
    <atom:link href="https://rifkyards.github.io/tags/terraform/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>[PART 2] Automated WebApp Provisioning and Secure Monitoring</title>
      <link>https://rifkyards.github.io/blogs/monitoring/monitoring-webapp-2/</link>
      <pubDate>Mon, 10 Mar 2025 07:13:02 +0000</pubDate>
      <guid>https://rifkyards.github.io/blogs/monitoring/monitoring-webapp-2/</guid>
      <description>&lt;p&gt;Blog ini merupakan kelanjutan dari bagian sebelumnya. Jika belum membacanya, bisa cek &lt;a href=&#34;https://rifkyards.github.io/blogs/monitoring/monitoring-webapp-1/&#34;&gt;disini&lt;/a&gt;.&lt;/p&gt;
&lt;h1 id=&#34;langkah-implementasi&#34;&gt;Langkah Implementasi&lt;/h1&gt;
&lt;h2 id=&#34;instalasi-dan-konfigurasi-tools-prometheus&#34;&gt;Instalasi dan Konfigurasi Tools Prometheus.&lt;/h2&gt;
&lt;p&gt;Note : Lakukan langkah dibawah ini di monitoring node.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download dan ekstrak file Prometheus.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;~$ sudo su -
~# cd /opt
/opt# wget
https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz
/opt# tar xvfz prometheus-2.48.1.linux-amd64.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menambahkan file konfigurasi untuk Prometheus.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt# cd prometheus-2.48.1. linux-amd64
/opt/prometheus-2.48.1. linux-amd64# vim config.yml
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;---
global:
  scrape_interval:     10s
  evaluation_interval: 15s

scrape_configs:
  - job_name: &amp;#39;node&amp;#39;
    scrape_interval:  5s
    static_configs:
    - targets: [&amp;#39;192.168.4.10:9100&amp;#39;,&amp;#39;192.168.4.20:9100&amp;#39;,&amp;#39;192.168.4.30:9100&amp;#39;]

  - job_name: &amp;#39;nginx&amp;#39;
    static_configs:
    - targets: [&amp;#39;192.168.4.20:9113&amp;#39;]

  - job_name: &amp;#39;cadvisor&amp;#39;
    static_configs:
    - targets: [&amp;#39;192.168.4.30:8080&amp;#39;]

  - job_name: &amp;#39;docker&amp;#39;
    static_configs:
    - targets: [&amp;#39;192.168.4.30:9323&amp;#39;]

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - 192.168.4.10:9093

rule_files:
  - &amp;#34;rules/container.yml&amp;#34;
  - &amp;#34;rules/node.yml&amp;#34;
  - &amp;#34;rules/web-server.yml&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Membuat SSL Key dan Certificate Signing Request.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt/prometheus-2.48.1.linux-amd64# sudo openssl genrsa -out /opt/prometheus-2.48.1.linux-amd64/prometheus.key 2048
/opt/prometheus-2.48.1.linux-amd64# sudo openssl req -new -key /opt/prometheus-2.48.1.linux-amd64/prometheus.key -out /opt/prometheus-2.48.1.linux-amd64/prometheus.csr
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter &amp;#39;.&amp;#39;, the field will be left blank.

Country Name (2 letter code) [AU]:ID
State or Province Name (full name) [Some-State]: South Kalimantan
Locality Name (eg, city) []:Banjarbaru
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:
Email Address []:

Please enter the following &amp;#39;extra&amp;#39; attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Membuat SSL Self-Signed Certificate.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt/prometheus-2.48.1.linux-amd64# openssl x509 -req -days 365 -signkey prometheus.key -in prometheus.csr -out prometheus.crt -extfile &amp;lt;(echo &amp;#34;subjectAltName=IP:192.168.4.10&amp;#34; )

Certificate request self-signature ok
subject=C = ID, ST = South Kalimantan, L = Banjarbaru, O = Internet Widgits Pty Ltd
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Instalasi paket yang dibutuhkan untuk basic authentication.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;~# sudo apt-get update &amp;amp;&amp;amp; sudo apt install apache2-utils -y
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Membuat password untuk basic authentication.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;~# htpasswd -nBC 12 &amp;#34;&amp;#34; | tr -d &amp;#39;:\n&amp;#39;
New password: &amp;lt;inputYourPassword&amp;gt;
Re-type new password: &amp;lt;inputYourPassword&amp;gt;

$2y$12$&amp;lt;saltAndHash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menambahkan konfigurasi untuk web agar SSL dan basic authentication diterapkan.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt/prometheus-2.48.1. linux-amd64# vim web.yml
basic_auth_users:
rifkyards: $2y$12$&amp;lt;saltAndHash&amp;gt;
tls_server_config:
    cert_file: /opt/prometheus-2.48.1.linux-amd64/prometheus.crt
    key_file: /opt/prometheus-2.48.1.linux-amd64/prometheus.key
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menambahkan rules untuk mengirimkan alert node yang mati ke Alert Manager.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt/prometheus-2.48.1.linux-amd64# vim rules/node.yml
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# Add this lines
groups:
  - name: NodeStatus
    rules:
      - alert: &amp;#34;NodeMonitoringDown&amp;#34;
        expr: up{instance=&amp;#34;192.168.4.10:9100&amp;#34;} == 0
        for: 5m
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: &amp;#34;NodeMonitoringDown&amp;#34;
        annotations:
          title: &amp;#34;{{ $labels.instance }} is down&amp;#34;
          description: &amp;#34;The server with IP {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;

      - alert: &amp;#34;NodeClient1Down&amp;#34;
        expr: up{instance=&amp;#34;192.168.4.10:9100&amp;#34;} == 0
        for: 5m
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: NodeClient1Down
        annotations:
          title: &amp;#34;{{ $labels.name }} is down&amp;#34;
          description: &amp;#34;The server with IP {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;

      - alert: &amp;#34;NodeClient2Down&amp;#34;
        expr: up{instance=&amp;#34;192.168.4.30:9100&amp;#34;} == 0
        for: 5m
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: NodeClient2Down
        annotations:
          title: &amp;#34;{{ $labels.instance }} is down&amp;#34;
          description: &amp;#34;The server with IP {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menambahkan rules untuk mengirimkan alert Nginx Server yang mati ke Alert Manager.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt/prometheus-2.48.1.linux-amd64# vim rules/web-server.yml
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# Add this lines
groups:
  - name: WebNginxStatus
    rules:
      - alert: NginxDown
        expr: nginx_up{instance=&amp;#34;192.168.4.20:9113&amp;#34;, job=&amp;#34;nginx&amp;#34;} == 0
        for: 5m
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: NginxDown
        annotations:
          title: &amp;#34;{{ $labels.name }} is down&amp;#34;
          description: &amp;#34;The {{ $labels.job }} server on {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menambahkan rules untuk mengirimkan alert container yang mati ke Alert Manager.&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/opt/prometheus-2.48.1.linux-amd64# vim rules/container.yml
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# Add this lines
groups:
  - name: containerMonitoring
    rules:
      - alert: &amp;#34;Container2048Down&amp;#34;
        expr: absent(container_start_time_seconds{name=&amp;#34;2048-apps&amp;#34;,instance=&amp;#34;192.168.4.30:8080&amp;#34;})
        for: 5m
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: Container2048Down
        annotations:
          title: &amp;#34;{{ $labels.name }} is down&amp;#34;
          description: &amp;#34;The {{ $labels.name }} container on {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;

      - alert: &amp;#34;ContainerTicTacToeDown&amp;#34;
        expr: absent(container_start_time_seconds{name=&amp;#34;tic-tac-toe-apps&amp;#34;,instance=&amp;#34;192.168.4.30:8080&amp;#34;})
        for: 5m
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: ContainerTicTacToeDown
        annotations:
          title: &amp;#34;{{ $labels.name }} is down&amp;#34;
          description: &amp;#34;The {{ $labels.name }} container on {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;

      - alert: &amp;#34;GeneralContainerDown&amp;#34;
        expr: time() - container_last_seen{instance=&amp;#34;192.168.4.30:8080&amp;#34;, image!=&amp;#34;&amp;#34;, name!~&amp;#34;2048-apps|tic-tac-toe-apps|cadvisor&amp;#34;} &amp;gt; 220
        for: 20s
        labels:
          severity: critical
          instance: &amp;#34;{{ $labels.instance }}&amp;#34;
          alertname: GeneralContainerDown
          resolved: &amp;#39;false&amp;#39;
        annotations:
          title: &amp;#34;{{ $labels.name }} is down&amp;#34;
          description: &amp;#34;A container {{ $labels.name }} on {{ $labels.instance }} has been down for more than 5 minutes.&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menambahkan konfigurasi untuk Prometheus berjalan di SystemD.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;~# vim /etc/systemd/system/prometheus_server.service
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;# Add this lines
[Unit]
Description=Prometheus Server

[Service]
User=root
ExecStart=/opt/prometheus-2.48.1.linux-amd64/prometheus --config.file=/opt/prometheus-2.48.1.linux-amd64/config.yml --web.config.file=/opt/prometheus-2.48.1.linux-amd64/web.yml --web.external-url=https://192.168.4.10:9090/

[Install]
WantedBy=default.target
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;Menjalankan perintah agar SystemD Prometheus berjalan.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;~# systemctl daemon-reload
~# systemctl start prometheus_server
~# systemctl enable prometheus_server
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;instalasi-dan-konfigurasi-tools-alert-manager&#34;&gt;Instalasi dan Konfigurasi Tools Alert Manager.&lt;/h2&gt;
&lt;p&gt;Note : Lakukan langkah dibawah ini di monitoring node.&lt;/p&gt;</description>
    </item>
    <item>
      <title>[PART 1] Automated WebApp Provisioning and Secure Monitoring</title>
      <link>https://rifkyards.github.io/blogs/monitoring/monitoring-webapp-1/</link>
      <pubDate>Mon, 10 Mar 2025 03:13:02 +0000</pubDate>
      <guid>https://rifkyards.github.io/blogs/monitoring/monitoring-webapp-1/</guid>
      <description>&lt;p&gt;Dalam lingkungan TI modern, banyak organisasi menghadapi tantangan dalam mengelola kombinasi aplikasi berbasis &lt;strong&gt;SystemD&lt;/strong&gt; dan &lt;strong&gt;container&lt;/strong&gt;. Kesulitan ini dapat menyebabkan kurangnya visibilitas terhadap performa sistem, meningkatkan risiko downtime yang tidak terdeteksi, dan menyulitkan tim dalam merespons masalah dengan cepat.&lt;/p&gt;
&lt;p&gt;Untuk mengatasi tantangan ini, pendekatan yang umum diterapkan adalah menetapkan satu server sebagai &lt;strong&gt;pusat monitoring dan kontrol otomatisasi&lt;/strong&gt;. Server ini berperan dalam mengintegrasikan berbagai alat seperti &lt;strong&gt;Terraform&lt;/strong&gt; untuk otomatisasi pembuatan infrastruktur berbasis container, serta &lt;strong&gt;Ansible&lt;/strong&gt; untuk mengelola konfigurasi sistem, termasuk pengumpulan metrik dan pengelolaan aplikasi berbasis SystemD.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
