|
| 1 | +## 🚀 Prometheus |
| 2 | +- Prometheus is an open-source systems monitoring and alerting toolkit originally built at SoundCloud. |
| 3 | +- It is known for its robust data model, powerful query language (PromQL), and the ability to generate alerts based on the collected time-series data. |
| 4 | +- It can be configured and set up on both bare-metal servers and container environments like Kubernetes. |
| 5 | + |
| 6 | +## 🏠 Prometheus Architecture |
| 7 | +- The architecture of Prometheus is designed to be highly flexible, scalable, and modular. |
| 8 | +- It consists of several core components, each responsible for a specific aspect of the monitoring process. |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +### 🔥 Prometheus Server |
| 13 | +- Prometheus server is the core of the monitoring system. It is responsible for scraping metrics from various configured targets, storing them in its time-series database (TSDB), and serving queries through its HTTP API. |
| 14 | +- Components: |
| 15 | + - **Retrieval**: This module handles the scraping of metrics from endpoints, which are discovered either through static configurations or dynamic service discovery methods. |
| 16 | + - **TSDB (Time Series Database)**: The data scraped from targets is stored in the TSDB, which is designed to handle high volumes of time-series data efficiently. |
| 17 | + - **HTTP Server**: This provides an API for querying data using PromQL, retrieving metadata, and interacting with other components of the Prometheus ecosystem. |
| 18 | +- **Storage**: The scraped data is stored on local disk (HDD/SSD) in a format optimized for time-series data. |
| 19 | + |
| 20 | +### 🌐 Service Discovery |
| 21 | +- Service discovery automatically identifies and manages the list of scrape targets (i.e., services or applications) that Prometheus monitors. |
| 22 | +- This is crucial in dynamic environments like Kubernetes where services are constantly being created and destroyed. |
| 23 | +- Components: |
| 24 | + - **Kubernetes**: In Kubernetes environments, Prometheus can automatically discover services, pods, and nodes using Kubernetes API, ensuring it monitors the most up-to-date list of targets. |
| 25 | + - **File SD (Service Discovery)**: Prometheus can also read static target configurations from files, allowing for flexibility in environments where dynamic service discovery is not used. |
| 26 | + |
| 27 | +### 📤 Pushgateway |
| 28 | +- The Pushgateway is used to expose metrics from short-lived jobs or applications that cannot be scraped directly by Prometheus. |
| 29 | +- These jobs push their metrics to the Pushgateway, which then makes them available for Prometheus to scrape(pull). |
| 30 | +- Use Case: |
| 31 | + - It's particularly useful for batch jobs or tasks that have a limited lifespan and would otherwise not have their metrics collected. |
| 32 | + |
| 33 | +### 🚨 Alertmanager |
| 34 | +- The Alertmanager is responsible for managing alerts generated by the Prometheus server. |
| 35 | +- It takes care of deduplicating, grouping, and routing alerts to the appropriate notification channels such as PagerDuty, email, or Slack. |
| 36 | + |
| 37 | +### 🧲 Exporters |
| 38 | +- Exporters are small applications that collect metrics from various third-party systems and expose them in a format Prometheus can scrape. They are essential for monitoring systems that do not natively support Prometheus. |
| 39 | +- Types of Exporters: |
| 40 | + - Common exporters include the Node Exporter (for hardware metrics), the MySQL Exporter (for database metrics), and various other application-specific exporters. |
| 41 | + |
| 42 | +### 🖥️ Prometheus Web UI |
| 43 | +- The Prometheus Web UI allows users to explore the collected metrics data, run ad-hoc PromQL queries, and visualize the results directly within Prometheus. |
| 44 | + |
| 45 | +### 📊 Grafana |
| 46 | +- Grafana is a powerful dashboard and visualization tool that integrates with Prometheus to provide rich, customizable visualizations of the metrics data. |
| 47 | + |
| 48 | +### 🔌 API Clients |
| 49 | +- API clients interact with Prometheus through its HTTP API to fetch data, query metrics, and integrate Prometheus with other systems or custom applications. |
| 50 | + |
| 51 | +# 🛠️ Installation & Configurations |
| 52 | +## 📦 Step 1: Create EKS Cluster |
| 53 | + |
| 54 | +```bash |
| 55 | +eksctl create cluster --name=observability \ |
| 56 | + --region=us-east-1 \ |
| 57 | + --zones=us-east-1a,us-east-1b \ |
| 58 | + --without-nodegroup |
| 59 | +``` |
| 60 | +```bash |
| 61 | +eksctl utils associate-iam-oidc-provider \ |
| 62 | + --region us-east-1 \ |
| 63 | + --cluster observability \ |
| 64 | + --approve |
| 65 | +``` |
| 66 | +```bash |
| 67 | +eksctl create nodegroup --cluster=observability \ |
| 68 | + --region=us-east-1 \ |
| 69 | + --name=observability-ng-private \ |
| 70 | + --node-type=t3.medium \ |
| 71 | + --nodes-min=2 \ |
| 72 | + --nodes-max=3 \ |
| 73 | + --node-volume-size=20 \ |
| 74 | + --managed \ |
| 75 | + --asg-access \ |
| 76 | + --external-dns-access \ |
| 77 | + --full-ecr-access \ |
| 78 | + --appmesh-access \ |
| 79 | + --alb-ingress-access \ |
| 80 | + --node-private-networking |
| 81 | +``` |
| 82 | + |
| 83 | +### 🧰 Step 2: Install kube-prometheus-stack |
| 84 | +```bash |
| 85 | +helm repo add prometheus-community https://prometheus-community.github.io/helm-charts |
| 86 | +helm repo update |
| 87 | +``` |
| 88 | + |
| 89 | +### 🚀 Step 3: Deploy the chart into a new namespace "monitoring" |
| 90 | +```bash |
| 91 | +kubeclt create ns monitoring |
| 92 | +``` |
| 93 | +```bash |
| 94 | +helm install monitoring \ |
| 95 | + --namespace monitoring \ |
| 96 | + prometheus-community/kube-prometheus-stack |
| 97 | +``` |
| 98 | + |
| 99 | +### ✅ Step 4: Verify the Installation |
| 100 | +```bash |
| 101 | +kubectl get all -n monitoring |
| 102 | +``` |
| 103 | +- **Prometheus UI**: |
| 104 | +```bash |
| 105 | +kubectl port-forward service/prometheus-operated -n monitoring 9090:9090 |
| 106 | +``` |
| 107 | +- **Grafana UI**: password is `prom-operator` |
| 108 | +```bash |
| 109 | +kubectl port-forward service/monitoring-grafana -n monitoring 8080:80 |
| 110 | +``` |
| 111 | +- **Alertmanager UI**: |
| 112 | +```bash |
| 113 | +kubectl port-forward service/alertmanager-operated -n monitoring 9093:9093 |
| 114 | +``` |
| 115 | + |
| 116 | +### 🧼 Step 5: Clean UP |
| 117 | +- **Uninstall helm chart**: |
| 118 | +```bash |
| 119 | +helm uninstall monitoring --namespace monitoring |
| 120 | +``` |
| 121 | +- **Delete namespace**: |
| 122 | +```bash |
| 123 | +kubectl delete ns monitoring |
| 124 | +``` |
| 125 | +- **Delete Cluster & everything else**: |
| 126 | +```bash |
| 127 | +eksctl delete cluster --name observability |
| 128 | +``` |
0 commit comments