Files
devops-it-manual/devopsSREMonitoring.tex
T

485 lines
15 KiB
TeX

\chapter{Introduction to SRE: Monitoring and Reliability}
\ChapterLabel{SREMonitoring}
\section{Objective and Scope}
This chapter documents the design, configuration, deployment
requirements, and verification procedures for the Group 10
Site Reliability Engineering (SRE) monitoring environment.
The objective is to monitor the reliability of the existing
Gitea and Jenkins services while preserving their security,
persistent data, and continuous integration functionality.
The proposed monitoring stack consists of four Docker
containers: Prometheus, Grafana OSS, Node Exporter, and
Blackbox Exporter.
The configuration files were prepared in the Gitea repository
on the \texttt{chapter5-sre-monitoring} branch.
\begin{devopsNote}[Verification Status]
Repository configuration and documentation have been prepared.
Deployment, runtime verification, dashboard screenshots, alert
notifications, and incident testing remain pending. These
activities must be completed and documented before submission.
\end{devopsNote}
\section{Deployment and Reproducibility}
\subsection{Existing Infrastructure}
The verified deployment host is an Ubuntu 24.04 DigitalOcean
Droplet with Docker and Docker Compose installed.
The existing application containers are Gitea, Jenkins,
and Caddy.
Gitea and Jenkins use separate Compose projects. Caddy
provides HTTPS reverse-proxy access.
The monitoring services are defined in a separate Compose
project under \texttt{monitoring/compose.yaml}.
This separation is intended to prevent changes to the
existing application deployments.
\subsection{Monitoring Containers}
\begin{itemize}
\item \textbf{Prometheus:} Collects and stores monitoring metrics.
\item \textbf{Grafana OSS:} Displays dashboards and evaluates alerts.
\item \textbf{Node Exporter:} Exposes host CPU, memory, and disk metrics.
\item \textbf{Blackbox Exporter:} Performs HTTPS availability probes.
\end{itemize}
The Compose configuration requires explicitly selected image
versions rather than floating \texttt{latest} tags.
Prometheus and Grafana use named persistent Docker volumes.
No monitoring service publishes an internal port directly
to the public host interface.
\subsection{Capacity Constraint}
The initial host inspection identified approximately
458 MiB of total RAM, with approximately 209 MiB available
at the time of inspection.
This capacity is insufficient for a conventional deployment
of the four monitoring containers alongside the existing
Gitea, Jenkins, and Caddy services.
The team must approve a suitable capacity plan before
deploying the monitoring stack.
The team must not create paid resources or resize the
Droplet without authorization.
\subsection{Deployment Verification}
After obtaining approval, the deployment operator must:
\begin{enumerate}
\item Select and record the four official image versions.
\item Configure required environment variables securely.
\item Validate the Compose configuration.
\item Confirm the required Docker networks exist.
\item Deploy the monitoring services.
\item Verify all monitoring containers are healthy.
\item Confirm existing application containers remain operational.
\item Verify persistent volumes and restart policies.
\item Record deployment commands and their actual output.
\end{enumerate}
\textbf{Evidence pending:} Compose validation, selected image
versions, container status, network inspection, and persistence.
\section{Metrics and HTTPS Probes}
\subsection{Prometheus Scrape Configuration}
Prometheus is configured with a 30-second scrape interval.
The prepared scrape jobs are:
\begin{itemize}
\item Prometheus self-monitoring.
\item Node Exporter host metrics.
\item Blackbox Exporter self-monitoring.
\item HTTPS probes for Gitea and Jenkins.
\end{itemize}
The scrape configuration is stored at
\texttt{monitoring/prometheus/prometheus.yml}.
The Blackbox module configuration is stored at
\texttt{monitoring/blackbox/blackbox.yml}.
\subsection{Host Metrics}
Node Exporter provides metrics for CPU utilization,
available memory, and root filesystem capacity.
The dashboard uses the following Prometheus metric families:
\begin{itemize}
\item \texttt{node\_cpu\_seconds\_total}
\item \texttt{node\_memory\_MemAvailable\_bytes}
\item \texttt{node\_filesystem\_avail\_bytes}
\item \texttt{node\_filesystem\_size\_bytes}
\end{itemize}
The deployment operator must verify that these metrics
represent the actual host rather than an unintended
container filesystem.
\subsection{HTTPS Availability Metrics}
Blackbox Exporter provides:
\begin{itemize}
\item \texttt{probe\_success}: successful probe indicator.
\item \texttt{probe\_duration\_seconds}: probe duration.
\item HTTP response and TLS diagnostic metrics.
\end{itemize}
A successful configured probe requires HTTP 200,
valid TLS verification, and completion before timeout.
Prometheus target availability and service availability
are different measurements.
The Prometheus \texttt{up} metric indicates whether a
scrape succeeded. The \texttt{probe\_success} metric
indicates whether the probed endpoint passed its checks.
\textbf{Evidence pending:} Prometheus targets, live metric
values, and successful probes for both services.
\section{HTTPS Access and Security}
\subsection{Verified HTTPS Endpoints}
The existing Gitea HTTPS hostname is
\texttt{git.sespinal590.dev}.
The existing Jenkins HTTPS hostname is
\texttt{ci.165.227.90.215.sslip.io}.
Read-only checks confirmed a successful HTTP 200 response
and valid TLS verification for the Gitea root endpoint.
The Jenkins public root and login endpoints returned
HTTP 403 from the tested source, with valid TLS verification.
An internal request to the Jenkins login endpoint from
the Caddy container returned HTTP 200.
\subsection{Jenkins Access Restriction}
The Caddy configuration uses an IP allowlist to restrict
Jenkins access.
The public HTTP 403 response is therefore not sufficient
evidence that the Jenkins application is unavailable.
Before deployment, the team must establish narrowly scoped
monitoring access that preserves the existing restriction.
The team must verify that Blackbox Exporter can reach the
real Jenkins HTTPS login endpoint and obtain HTTP 200.
The monitoring system must not classify HTTP 403 as
a successful Jenkins availability probe.
\subsection{Grafana HTTPS Access}
Grafana must be made available through an authenticated
HTTPS route managed by Caddy.
Anonymous access must remain disabled.
Administrator credentials and notification secrets
must not be committed to the repository.
The team must confirm that Prometheus and exporter ports
are not exposed publicly.
\textbf{Evidence pending:} Grafana HTTPS login, Caddy
configuration, TLS verification, and access restrictions.
\section{Grafana Dashboard and CI Correlation}
\subsection{Dashboard Provisioning}
Grafana provisioning files are stored under
\texttt{monitoring/grafana/provisioning/}.
The prepared dashboard definition is stored at
\texttt{monitoring/grafana/dashboards/sre-overview.json}.
The dashboard is designed to display six panels:
\begin{enumerate}
\item Host CPU utilization percentage.
\item Host available RAM.
\item Root disk available percentage.
\item Gitea HTTPS availability.
\item Jenkins HTTPS availability.
\item HTTPS response time for both services.
\end{enumerate}
The dashboard refresh interval is 30 seconds.
\subsection{Continuous Integration Correlation}
The monitoring experiment must be correlated with the
existing Jenkins pipeline and Gitea Actions PDF workflow.
The team must record relevant build execution times and
compare them with the monitoring timeline.
A successful application recovery does not automatically
prove that CI pipelines remain operational.
The Jenkins pipeline and Gitea Actions workflow must
therefore be verified independently after the outage.
\textbf{Evidence pending:} Six-panel dashboard screenshot,
Jenkins pipeline execution, and successful Gitea Actions
PDF build artifact.
\section{SLI, SLO, and Error Budget}
\subsection{Availability Indicator}
The service level indicator (SLI) is the fraction of
successful observed HTTPS probes:
\begin{equation}
\mathrm{SLI} =
\frac{\text{Successful observed probes}}
{\text{Total observed probes}}.
\end{equation}
The laboratory service level objective (SLO) is
99\% availability over a 24-hour observation window.
At a 30-second sampling interval, the scheduled number
of samples is:
\begin{equation}
N = 24 \times 60 \times 2 = 2880.
\end{equation}
The permitted error budget is:
\begin{equation}
B = 2880 \times (1 - 0.99) = 28.8.
\end{equation}
Because probe failures are counted in whole samples,
the maximum permitted number of failed samples is 28.
The equivalent theoretical failure allowance is
14.4 minutes, while 28 complete failed samples
represent 14 minutes.
\subsection{Mandatory Hypothetical Example}
The following results are hypothetical and do not
represent measured deployment availability.
\begin{center}
\begin{tabular}{lrrrr}
\toprule
Service & Successful & Scheduled & Availability & Result \\
\midrule
Gitea & 2880 & 2880 & 100.00\% & PASS \\
Jenkins & 2850 & 2880 & 98.96\% & FAIL \\
\bottomrule
\end{tabular}
\end{center}
Jenkins has 30 hypothetical failed samples and
therefore exceeds the permitted error budget.
\subsection{Actual Observation Procedure}
After deployment, calculate observed availability
using \texttt{avg\_over\_time} applied to
\texttt{probe\_success}.
Use \texttt{count\_over\_time} to determine how many
samples were actually collected.
Missing samples must not automatically be counted
as successful probes.
If a complete 24-hour window is unavailable, clearly
label the shorter observation window and report its
actual sample count.
Detailed PromQL queries and calculation instructions
are maintained in \texttt{monitoring/SLI-SLO.md}.
\textbf{Evidence pending:} Actual observed sample counts,
availability values, and outage-window calculations.
\section{Grafana Alerts and Runbooks}
\subsection{HTTPS Service Unavailable}
The first Grafana-managed alert monitors
\texttt{probe\_success} for each HTTPS target.
The intended condition is a probe result below 1
for at least one continuous minute.
Each service must be distinguishable using its
Prometheus instance label.
\subsection{Host Root Disk Space Low}
The second Grafana-managed alert monitors the
percentage of available root filesystem space.
The intended condition is less than 15\%
available space for five continuous minutes.
\subsection{Notification Configuration}
The team must configure an approved Grafana
notification contact point and verify that an
actual notification is received.
The contact point must not expose passwords,
API keys, or private credentials in the repository.
\subsection{Safe Alert Demonstration}
The disk alert must be tested without deliberately
filling the Droplet filesystem.
The approved demonstration procedure temporarily
raises the alert threshold above the current
available disk percentage, waits for the pending
period, records the alert firing, and then restores
the required 15\% threshold.
The full alert configuration and operational
procedures are documented in
\texttt{monitoring/ALERTING-RUNBOOK.md}.
\textbf{Evidence pending:} Loaded Grafana alert rules,
contact point, firing notifications, and resolutions.
\section{Controlled Incident and Recovery}
\subsection{Jenkins-Only Outage}
The team must coordinate an approved controlled
Jenkins-only outage lasting approximately three minutes.
Gitea, Caddy, Prometheus, and Grafana must remain
operational during the experiment.
The operator must record the exact UTC timestamps
for the outage, first failed probe, alert firing,
notification receipt, application restart, first
successful probe, and alert resolution.
\subsection{Recovery Verification}
After restarting Jenkins, the team must verify:
\begin{enumerate}
\item The Jenkins login endpoint is available.
\item The HTTPS probe returns a successful result.
\item The Grafana alert resolves.
\item Gitea remained available during the outage.
\item The Jenkins pipeline executes successfully.
\item The Gitea Actions PDF workflow executes successfully.
\end{enumerate}
\subsection{Monitoring Persistence}
Prometheus and Grafana must be restarted separately.
Prometheus must retain historical metrics.
Grafana must retain the provisioned dashboard,
data source, alert rules, and notification configuration.
The team must not delete persistent Docker volumes
during these tests.
\subsection{Blameless Incident Review}
The final incident review must document actual
impact, detection, notification, recovery,
contributing factors, and preventive improvements.
At least two follow-up Gitea issues must be created,
with assigned owners and acceptance criteria.
\textbf{Evidence pending:} UTC incident timeline,
outage graphs, notifications, restart tests,
CI verification, and follow-up issue references.
\section{Traceability and Submission Evidence}
\subsection{Repository Artifacts}
The Chapter 5 preparation is organized under
the \texttt{monitoring/} directory.
Key artifacts include:
\begin{itemize}
\item \texttt{ARCHITECTURE.md}
\item \texttt{compose.yaml}
\item \texttt{prometheus/prometheus.yml}
\item \texttt{blackbox/blackbox.yml}
\item \texttt{grafana/provisioning/}
\item \texttt{grafana/dashboards/sre-overview.json}
\item \texttt{SLI-SLO.md}
\item \texttt{ALERTING-RUNBOOK.md}
\end{itemize}
These files provide the intended deployment
configuration and reproducibility documentation.
They do not independently prove that the
monitoring services were deployed successfully.
\subsection{Final Evidence Checklist}
Before submission, the team must provide:
\begin{enumerate}
\item Validated monitoring Compose configuration.
\item Running monitoring containers and selected image versions.
\item Prometheus targets and actual metric values.
\item Grafana authenticated HTTPS login.
\item Six-panel dashboard with real data.
\item Gitea and Jenkins HTTPS probe results.
\item Actual SLI observations and SLO calculations.
\item Two configured and tested Grafana alerts.
\item Notification delivery and resolution evidence.
\item Controlled Jenkins outage and UTC timeline.
\item Prometheus and Grafana persistence tests.
\item Jenkins pipeline and Gitea Actions verification.
\item Blameless incident review.
\item Two assigned follow-up Gitea issues.
\item Successfully generated final PDF manual artifact.
\end{enumerate}
\begin{devopsNote}[Final Submission Requirement]
The final Chapter 5 report must replace all pending evidence
statements with verified results or explicitly document
unresolved limitations. The team must not present planned
configuration as successful deployment.
\end{devopsNote}