GET / — получение идентификатора пода;GET /metrics — получение метрик в формате Prometheus.http_requests_total возвращает количество запросов для метода получения идентификатора пода.8080.BASH
minikube service <имя сервиса> --url BASH
minikube addons enable metrics-server locustfile.py в удобной для вас директории. Скопируйте туда код:BASH
from locust import HttpUser, between, task
class WebsiteUser(HttpUser):
wait_time = between(1, 5)
@task
def index(self):
self.client.get("/") "/") с интервалом между запросами от 1 до 5 секунд.locustfile.py. Выполните команду:BASH
locust BASH
minikube dashboard YAML
helm repo add prometheus-community <https://prometheus-community.github.io/helm-charts>
helm repo update
helm install prometheus-operator prometheus-community/kube-prometheus-stack YAML
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: scaletestapp-app-sm
namespace: default
labels:
serviceMonitorSelector: prometheus
spec:
endpoints:
- interval: 10s
targetPort: 8080
path: /metrics
namespaceSelector:
matchNames:
- default
selector:
matchLabels:
prometheus-monitored: "true" app или кастомного лейбла (например, prometheus-monitored), который вы можете отразить в манифесте Service.additionalServiceMonitors при настройке Prometheus Operator через Helm. \n Вот пример конфигурации Prometheus Operator:YAML
defaultRules:
create: false
alertmanager:
enabled: false
grafana:
enabled: false
kubeApiServer:
enabled: false
kubelet:
enabled: false
kubeControllerManager:
enabled: false
coreDns:
enabled: false
kubeEtcd:
enabled: false
kubeScheduler:
enabled: false
kubeStateMetrics:
enabled: false
nodeExporter:
enabled: false
prometheus:
enabled: true
additionalServiceMonitors:
- name: app-sm
namespace: default
labels:
serviceMonitorSelector: prometheus
endpoints:
- interval: 10s
targetPort: 8080
path: /metrics
namespaceSelector:
matchNames:
- default
selector:
matchLabels:
prometheus-monitored: "true" BASH
minikube service <имя сервиса> --url values.yaml и включите туда определение для prometheus-adapter:YAML
prometheus:
url: "http://<адрес_prometheus>"
rules:
default: false
custom:
- seriesQuery: 'http_requests_total{namespace!="",pod!=""}'
resources:
overrides:
namespace: {resource: "namespace"}
pod: {resource: "pod"}
name:
matches: "^http_requests_total"
as: "http_requests_per_second"
metricsQuery: 'sum(rate(http_requests_total{<<.LabelMatchers>>}[30s])) by (<<.GroupBy>>)'
BASH
helm intall prometheus-adapter prometheus-community/prometheus-adapter -f values.yaml
http_requests_per_second стала доступной, воспользуйтесь командой:BASH
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
http_requests_per_second. Вот пример манифеста:YAML
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: scaletestapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: scaletestapp
minReplicas: 1
maxReplicas: 10
metrics:
- type: Pods
pods:
metric:
name: http_requests_per_second
target:
type: AverageValue
averageValue: 50 YAML
swagger: '2.0'
info:
description: API сервиса управления клиентскими данными
version: 1.0.0
title: Клиентский Сервис
host: api.client-service.com
basePath: /v1
schemes:
- https
paths:
/clients/{id}:
get:
tags:
- Клиент
summary: Получить информацию о клиенте по ID
description: Возвращает информацию о клиенте.
produces:
- application/json
parameters:
- name: id
in: path
description: ID клиента
required: true
type: string
responses:
'200':
description: Успешный ответ
schema:
$ref: '#/definitions/Client'
/clients/{id}/documents:
get:
tags:
- Документы
summary: Список документов клиента
description: Возвращает список документов клиента по ID.
produces:
- application/json
parameters:
- name: id
in: path
description: ID клиента для поиска его документов
required: true
type: string
responses:
'200':
description: Успешный ответ
schema:
type: array
items:
$ref: '#/definitions/Document'
/clients/{id}/relatives:
get:
tags:
- Родственники
summary: Информация о родственниках клиента
description: Возвращает информацию о родственниках клиента по ID.
produces:
- application/json
parameters:
- name: id
in: path
description: ID клиента
required: true
type: string
responses:
'200':
description: Успешный ответ
schema:
type: array
items:
$ref: '#/definitions/Relative'
definitions:
Client:
type: object
properties:
id:
type: string
name:
type: string
age:
type: integer
Document:
type: object
properties:
id:
type: string
type:
type: string
number:
type: string
issueDate:
type: string
expiryDate:
type: string
Relative:
type: object
properties:
id:
type: string
relationType:
type: string
name:
type: string
age:
type: integer
queries), которые покроют все операции REST API.JSX
http {
# Настройка upstream для балансировки нагрузки
upstream backend_servers {
server backend1.example.com;
server backend2.example.com;
server backend3.example.com;
}
server {
listen 80;
location / {
proxy_pass http://backend_servers;
}
}
}
429.