fix: use docker and prometheus as docker containers

Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
This commit is contained in:
Rodney Osodo
2024-07-14 23:06:40 +03:00
parent 50c304a7c4
commit bbd88ba389
8 changed files with 1346 additions and 903 deletions
+18 -20
View File
@@ -22,33 +22,27 @@ install-prometheus-k8s:
@kubectl create namespace monitoring
@helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
@helm repo update
@helm install prometheus prometheus-community/kube-prometheus-stack -n monitoring -f values.yaml
@echo "Prometheus installed on k8s"
@helm install kube-state-metrics prometheus-community/kube-state-metrics -n monitoring
@helm install prometheus-node-exporter prometheus-community/prometheus-node-exporter -n monitoring
@echo "List of pods and services created by Prometheus on k8s"
kubectl get pods -n monitoring
kubectl get svc -n monitoring
@echo "Expose Prometheus service on k8s"
kubectl expose service prometheus-kube-prometheus-prometheus -n monitoring --type=NodePort --target-port=9090 --name=prometheus-kube-prometheus-prometheus-np
.PHONY: export-ports
export-ports:
@echo "Expose kube-state-metrics service on k8s"
kubectl expose service kube-state-metrics -n monitoring --type=NodePort --target-port=8080 --name=kube-state-metrics-np
@echo "Prometheus service exposed on k8s"
kubectl get svc prometheus-kube-prometheus-prometheus-np -n monitoring
@echo "Expose Grafana service on k8s"
kubectl expose service prometheus-grafana -n monitoring --type=NodePort --target-port=3000 --name=prometheus-grafana-np
@echo "Grafana service exposed on k8s"
kubectl get svc prometheus-grafana-np -n monitoring
kubectl get svc kube-state-metrics-np -n monitoring
@echo "Expose prometheus-node-exporter service on k8s"
kubectl expose service prometheus-node-exporter -n monitoring --type=NodePort --target-port=9100 --name=prometheus-node-exporter-np
@echo "Prometheus service exposed on k8s"
kubectl get svc prometheus-node-exporter-np -n monitoring
.PHONY: remove-prometheus-k8s
remove-prometheus-k8s:
@helm uninstall prometheus -n monitoring
@kubectl delete crd alertmanagerconfigs.monitoring.coreos.com
@kubectl delete crd alertmanagers.monitoring.coreos.com
@kubectl delete crd podmonitors.monitoring.coreos.com
@kubectl delete crd probes.monitoring.coreos.com
@kubectl delete crd prometheusagents.monitoring.coreos.com
@kubectl delete crd prometheuses.monitoring.coreos.com
@kubectl delete crd prometheusrules.monitoring.coreos.com
@kubectl delete crd scrapeconfigs.monitoring.coreos.com
@kubectl delete crd servicemonitors.monitoring.coreos.com
@kubectl delete crd thanosrulers.monitoring.coreos.com
@helm uninstall kube-state-metrics -n monitoring
@helm uninstall prometheus-node-exporter -n monitoring
@kubectl delete namespace monitoring
.PHONY: deploy-to-k8s
@@ -69,3 +63,7 @@ release: build-image push-image
@docker tag gitea.rodneyosodo.com/rodneyosodo/nameko-prometheus:latest gitea.rodneyosodo.com/rodneyosodo/nameko-prometheus:$(VERSION)
@docker push gitea.rodneyosodo.com/rodneyosodo/nameko-prometheus:$(VERSION)
@echo "Release done"
.PHONY: run-docker-monitoring
run-docker-monitoring:
docker compose -f docker-compose-monitoring.yaml up
+1242
View File
File diff suppressed because it is too large Load Diff
-871
View File
@@ -1,871 +0,0 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"description": "Demo service that runs 3 replicas",
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 28,
"links": [],
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "orange",
"value": 20
},
{
"color": "red",
"value": 50
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 6,
"x": 0,
"y": 0
},
"id": 4,
"options": {
"colorMode": "background",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "sum(rate(http_service_http_requests_total{service=\"nameko-service\"}[$__rate_interval]))",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "Traffic",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Total Requests Per Second",
"transparent": true,
"type": "stat"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Displays the availability ratio of replicas in the default namespace to monitor deployment health trends.",
"fieldConfig": {
"defaults": {
"color": {
"mode": "continuous-GrYlRd"
},
"custom": {
"fillOpacity": 72,
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineWidth": 0,
"spanNulls": false
},
"mappings": [
{
"options": {
"0": {
"color": "semi-dark-red",
"index": 2,
"text": "Down"
},
"1": {
"color": "green",
"index": 0,
"text": "Health"
}
},
"type": "value"
},
{
"options": {
"from": 0,
"result": {
"color": "orange",
"index": 1,
"text": "Degraded"
},
"to": 1
},
"type": "range"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "short"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 6,
"x": 6,
"y": 0
},
"id": 3,
"options": {
"alignValue": "center",
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": false
},
"mergeValues": false,
"rowHeight": 0.9,
"showValue": "never",
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "kube_deployment_status_replicas_available{namespace=\"$namespace\"} / kube_deployment_spec_replicas{namespace=\"$namespace\"}",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "{{deployment}}",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Deployment Health",
"type": "state-timeline"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Visualizes server request latency distribution over time to identify performance trends and spikes.",
"fieldConfig": {
"defaults": {
"custom": {
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"scaleDistribution": {
"type": "linear"
}
},
"fieldMinMax": false
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 12,
"y": 0
},
"id": 1,
"options": {
"calculate": false,
"cellGap": 1,
"color": {
"exponent": 0.5,
"fill": "dark-orange",
"mode": "scheme",
"reverse": false,
"scale": "exponential",
"scheme": "Warm",
"steps": 128
},
"exemplars": {
"color": "rgba(255,0,255,0.7)"
},
"filterValues": {
"le": 1e-9
},
"legend": {
"show": false
},
"rowsFrame": {
"layout": "auto"
},
"tooltip": {
"mode": "single",
"showColorScale": false,
"yHistogram": false
},
"yAxis": {
"axisPlacement": "left",
"reverse": false,
"unit": "s"
}
},
"pluginVersion": "11.1.0",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"exemplar": false,
"expr": "sum by(le) (increase(http_service_http_request_latency_seconds_bucket{job=\"$service\"}[$__rate_interval]))",
"format": "heatmap",
"fullMetaSearch": false,
"includeNullMetadata": false,
"instant": false,
"legendFormat": "{{le}}",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Request Latency Heatmap",
"type": "heatmap"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Tracks the 50th, 75th, 90th, 95th, and 99th percentile latencies of HTTP requests to identify performance bottlenecks.",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 0,
"gradientMode": "opacity",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "smooth",
"lineStyle": {
"fill": "solid"
},
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "area"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 0.02
}
]
},
"unit": "s"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 12,
"x": 0,
"y": 9
},
"id": 5,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "histogram_quantile(0.99, sum by(le) (rate(http_service_http_request_latency_seconds_bucket{service=\"$service\"}[$__rate_interval])))",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "P99",
"range": true,
"refId": "A",
"useBackend": false
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "histogram_quantile(0.95, sum(rate(http_service_http_request_latency_seconds_bucket{service=\"$service\"}[$__rate_interval])) by (le))",
"fullMetaSearch": false,
"includeNullMetadata": false,
"instant": false,
"legendFormat": "P95",
"range": true,
"refId": "B",
"useBackend": false
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "histogram_quantile(0.9, sum by(le) (rate(http_service_http_request_latency_seconds_bucket{service=\"$service\"}[$__rate_interval])))",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "P90",
"range": true,
"refId": "C",
"useBackend": false
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "histogram_quantile(0.75, sum by(le) (rate(http_service_http_request_latency_seconds_bucket{service=\"$service\"}[$__rate_interval])))",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "P75",
"range": true,
"refId": "D",
"useBackend": false
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "code",
"expr": "histogram_quantile(0.5, sum by(le) (rate(http_service_http_request_latency_seconds_bucket{service=\"$service\"}[$__rate_interval])))",
"fullMetaSearch": false,
"hide": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "P50",
"range": true,
"refId": "E",
"useBackend": false
}
],
"title": "Response Latency",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Displays the total volume of HTTP requests for the service job, aggregated over a specified interval.",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 18,
"gradientMode": "opacity",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "dashed"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 50
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 10,
"w": 12,
"x": 12,
"y": 9
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "sum(rate(http_service_http_requests_total{job=\"$service\"}[$__rate_interval]))",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Request Volume",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Displays the percentage of HTTP requests resulting in errors over time, filtered by component.",
"fieldConfig": {
"defaults": {
"color": {
"fixedColor": "red",
"mode": "fixed"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 30,
"gradientMode": "scheme",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "smooth",
"lineWidth": 2,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"max": 1,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "percentunit"
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 0,
"y": 19
},
"id": 7,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "sum(rate(http_service_http_requests_total{service=\"$service\", status_code!~\"(2..|0)\"}[$__rate_interval])) / sum(rate(http_service_http_requests_total{service=\"$service\"}[$__rate_interval]))",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "Error Rate",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Error Rate",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"description": "Tracks the rate of HTTP requests for different server paths, excluding application-specific endpoints.",
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "opacity",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "smooth",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
}
]
},
"unit": "reqps"
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 19
},
"id": 6,
"options": {
"legend": {
"calcs": [],
"displayMode": "table",
"placement": "right",
"showLegend": true
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"disableTextWrap": false,
"editorMode": "builder",
"expr": "sum by(exported_endpoint) (rate(http_service_http_requests_total{service=\"$service\", exported_endpoint!=\"/metrics\"}[$__rate_interval]))",
"fullMetaSearch": false,
"includeNullMetadata": true,
"instant": false,
"legendFormat": "__auto",
"range": true,
"refId": "A",
"useBackend": false
}
],
"title": "Request rate by endpoint",
"type": "timeseries"
}
],
"refresh": "5s",
"schemaVersion": 39,
"tags": [],
"templating": {
"list": [
{
"current": {
"selected": false,
"text": "nameko-service",
"value": "nameko-service"
},
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"definition": "label_values({namespace=\"$namespace\"},service)",
"hide": 0,
"includeAll": false,
"multi": false,
"name": "service",
"options": [],
"query": {
"qryType": 1,
"query": "label_values({namespace=\"$namespace\"},service)",
"refId": "PrometheusVariableQueryEditor-VariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
},
{
"current": {
"selected": false,
"text": "nameko-prometheus",
"value": "nameko-prometheus"
},
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"definition": "label_values(namespace)",
"hide": 0,
"includeAll": false,
"label": "Kubernetes namespace",
"multi": false,
"name": "namespace",
"options": [],
"query": {
"qryType": 1,
"query": "label_values(namespace)",
"refId": "PrometheusVariableQueryEditor-VariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
},
{
"current": {
"selected": false,
"text": "/goodbye",
"value": "/goodbye"
},
"datasource": {
"type": "prometheus",
"uid": "prometheus"
},
"definition": "label_values({namespace=\"$namespace\"},exported_endpoint)",
"hide": 0,
"includeAll": false,
"label": "Request Endpoint",
"multi": false,
"name": "endpoint",
"options": [],
"query": {
"qryType": 1,
"query": "label_values({namespace=\"$namespace\"},exported_endpoint)",
"refId": "PrometheusVariableQueryEditor-VariableQuery"
},
"refresh": 1,
"regex": "",
"skipUrlSync": false,
"sort": 0,
"type": "query"
}
]
},
"time": {
"from": "now-15m",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Service",
"uid": "bdrckn7zqshz4c",
"version": 18,
"weekStart": ""
}
+30
View File
@@ -0,0 +1,30 @@
volumes:
prometheus-data:
services:
prometheus:
image: prom/prometheus:v2.53.1
container_name: nameko-prometheus
restart: unless-stopped
command:
- "--config.file=/etc/prometheus/prometheus.yaml"
ports:
- 9090:9090
volumes:
- ./prometheus/prometheus.yaml:/etc/prometheus/prometheus.yaml
- prometheus-data:/prometheus
grafana:
image: grafana/grafana:11.1.0
container_name: nameko-grafana
restart: unless-stopped
depends_on:
- prometheus
ports:
- 3000:3000
environment:
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=password
volumes:
- ./grafana/datasource.yaml:/etc/grafana/provisioning/datasources/datasource.yml
- ./grafana/dashboard.yaml:/etc/grafana/provisioning/dashboards/main.yaml
+12
View File
@@ -0,0 +1,12 @@
apiVersion: 1
providers:
- name: "Dashboard provider"
orgId: 1
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: false
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: true
+9
View File
@@ -0,0 +1,9 @@
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://nameko-prometheus:9090
isDefault: true
access: proxy
editable: true
-12
View File
@@ -1,12 +0,0 @@
global:
scrape_interval: 5s
scrape_timeout: 5s
evaluation_interval: 15s
scrape_configs:
- job_name: "my_service"
honor_timestamps: true
scheme: http
metrics_path: /metrics
static_configs:
- targets:
- my_service:8000
+35
View File
@@ -0,0 +1,35 @@
global:
scrape_interval: 5s
scrape_timeout: 5s
evaluation_interval: 15s
scrape_configs:
- job_name: "kube-state-metrics"
honor_timestamps: true
follow_redirects: true
enable_http2: true
scheme: http
metrics_path: /metrics
static_configs:
- targets:
- 192.168.100.202:31285 # kube-state-metrics-np service NodePort
- job_name: "prometheus-node-exporter"
honor_timestamps: true
follow_redirects: true
enable_http2: true
scheme: http
metrics_path: /metrics
static_configs:
- targets:
- 192.168.100.202:32042 # prometheus-node-exporter-np service NodePort
- job_name: "nameko-service"
honor_timestamps: true
follow_redirects: true
enable_http2: true
scheme: http
metrics_path: /metrics
static_configs:
- targets:
- 192.168.100.202:30081 # deployed nameko-service service NodePort