homework 10.3: complete 1 task, add partially complete 2 task

This commit is contained in:
2022-10-05 10:48:00 +07:00
parent 6b5f084474
commit cf7e8c27f2
9 changed files with 2312 additions and 0 deletions

View File

@@ -49,3 +49,4 @@
* [09.6. Gitlab](/src/homework/09-ci/9.6) * [09.6. Gitlab](/src/homework/09-ci/9.6)
* [10.1. Зачем и что нужно мониторить](/src/homework/10-monitoring/10.1) * [10.1. Зачем и что нужно мониторить](/src/homework/10-monitoring/10.1)
* [10.2. Системы мониторинга](/src/homework/10-monitoring/10.2) * [10.2. Системы мониторинга](/src/homework/10-monitoring/10.2)
* [10.3. Системы Grafana](/src/homework/10-monitoring/10.3)

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

@@ -0,0 +1,62 @@
Выполнение [домашнего задания](https://github.com/netology-code/mnt-homeworks/blob/MNT-13/10-monitoring-03-grafana/README.md)
по теме "10.3. Системы Grafana"
## Q/A
### Задание 1
> Cамостоятельно разверните grafana, где в роли источника данных будет выступать prometheus, а сборщиком данных node-exporter:
>
> * `grafana`
> * `prometheus-server`
> * `prometheus node-exporter`
>
> Запустите связку prometheus-grafana.
> Зайдите в веб-интерфейс Grafana, используя авторизационные данные, указанные в манифесте docker-compose.
> Подключите поднятый вами prometheus как источник данных.
> Решение домашнего задания - скриншот веб-интерфейса grafana со списком подключенных Datasource.
> В решении к домашнему заданию приведите также все конфигурации/скрипты/манифесты, которые вы использовали в процессе решения задания.
`docker-compose` и остальная конфигурация расположена в директории [stack](./stack).
При поднятии контейнеров в `grafana` автоматически создаётся `data-source` к `prometheus`,
а так же dashboard по мониторингу контейнера `prometheus`.
![grafana_datasource](./img/grafana_datasource.png)
### Задание 2
> Изучите самостоятельно ресурсы:
> - [promql-for-humans](https://timber.io/blog/promql-for-humans/#cpu-usage-by-instance)
> - [understanding prometheus cpu metrics](https://www.robustperception.io/understanding-machine-cpu-usage)
>
> Создайте Dashboard и в ней создайте следующие Panels:
> - Утилизация CPU для nodeexporter (в процентах, 100-idle)
> - CPULA 1/5/15
> - Количество свободной оперативной памяти
> - Количество места на файловой системе
>
> Для решения данного ДЗ приведите promql запросы для выдачи этих метрик, а также скриншот получившейся Dashboard.
Метрики и текст запросов для них
- Утилизация CPU для nodeexporter (в процентах, 100-idle)
```text
100 * (1 - avg by(instance)(irate(node_cpu_seconds_total{mode="idle"}[1m])))
```
- CPULA 1/5/15
```text
avg(node_load1{})
avg(node_load5{})
avg(node_load15{})
```
- Количество свободной оперативной памяти
// todo
- Количество места на файловой системе
// todo

View File

@@ -0,0 +1,44 @@
---
version: "3.9"
services:
node-exporter:
image: prom/node-exporter:v1.4.0
container_name: node-exporter
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
command:
- "--path.procfs=/host/proc"
- "--path.rootfs=/rootfs"
- "--path.sysfs=/host/sys"
- "--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)"
expose:
- 9100
prometheus:
image: prom/prometheus:v2.37.1
container_name: prometheus
volumes:
- ./prometheus/:/etc/prometheus/
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/etc/prometheus/console_libraries"
- "--web.console.templates=/etc/prometheus/consoles"
- "--web.enable-lifecycle"
expose:
- 9090
depends_on:
node-exporter:
condition: service_completed_successfully
grafana:
image: grafana/grafana:9.1.7
expose:
- 3000
ports:
- "3000:3000"
volumes:
- ./grafana/provisioning/:/etc/grafana/provisioning/

View File

@@ -0,0 +1,298 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 2,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "semi-dark-yellow",
"value": 1
},
{
"color": "semi-dark-orange",
"value": 4
},
{
"color": "semi-dark-red",
"value": 11
}
]
},
"unit": "percentunit"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "avg(node_load1{})"
},
"properties": [
{
"id": "displayName",
"value": "loadavg1"
}
]
},
{
"matcher": {
"id": "byName",
"options": "avg(node_load5{})"
},
"properties": [
{
"id": "displayName",
"value": "loadavg5"
}
]
},
{
"matcher": {
"id": "byName",
"options": "avg(node_load15{})"
},
"properties": [
{
"id": "displayName",
"value": "loadavg15"
}
]
}
]
},
"gridPos": {
"h": 6,
"w": 13,
"x": 0,
"y": 0
},
"id": 4,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"showThresholdLabels": true,
"showThresholdMarkers": true
},
"pluginVersion": "9.1.7",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"editorMode": "code",
"expr": "avg(node_load1{})",
"legendFormat": "__auto",
"range": true,
"refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"editorMode": "code",
"expr": "avg(node_load5{})",
"hide": false,
"legendFormat": "__auto",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"editorMode": "code",
"expr": "avg(node_load15{})",
"hide": false,
"legendFormat": "__auto",
"range": true,
"refId": "C"
}
],
"title": "CPU Load Average",
"type": "gauge"
},
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 71,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "smooth",
"lineStyle": {
"fill": "solid"
},
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "dashed"
}
},
"displayName": "средняя нагрузка",
"mappings": [],
"max": 1,
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 0.8
}
]
},
"unit": "percentunit"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "средняя нагрузка"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "red",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 13,
"x": 0,
"y": 6
},
"id": 2,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": false
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"editorMode": "code",
"expr": "100 * (1 - avg by(instance)(irate(node_cpu_seconds_total{mode=\"idle\"}[1m])))",
"legendFormat": "__auto",
"range": true,
"refId": "A"
}
],
"title": "Нагрузка на node",
"type": "timeseries"
}
],
"refresh": false,
"schemaVersion": 37,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-30m",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "node-exporter",
"uid": "NwsNrL44z",
"version": 1,
"weekStart": ""
}

View File

@@ -0,0 +1,12 @@
---
apiVersion: 1
providers:
- name: 'Prometheus'
orgId: 1
folder: ''
type: file
disableDeletion: false
editable: true
options:
path: /etc/grafana/provisioning/dashboards

View File

@@ -0,0 +1,51 @@
---
# config file version
apiVersion: 1
# list of datasources that should be deleted from the database
deleteDatasources:
- name: Prometheus
orgId: 1
# list of datasources to insert/update depending
# whats available in the database
datasources:
# <string, required> name of the datasource. Required
- name: Prometheus
# <string, required> datasource type. Required
type: prometheus
# <string, required> access mode. direct or proxy. Required
access: proxy
# <int> org id. will default to orgId 1 if not specified
orgId: 1
# <string> url
url: http://prometheus:9090
# <string> database password, if used
password:
# <string> database user, if used
user:
# <string> database name, if used
database:
# <bool> enable/disable basic auth
basicAuth: false
# <string> basic auth username, if used
basicAuthUser:
# <string> basic auth password, if used
basicAuthPassword:
# <bool> enable/disable with credentials headers
withCredentials:
# <bool> mark as default datasource. Max one per org
isDefault: true
# <map> fields that will be converted to json and stored in json_data
jsonData:
graphiteVersion: "1.1"
tlsAuth: false
tlsAuthWithCACert: false
# <string> json object of data that will be encrypted.
secureJsonData:
tlsCACert: "..."
tlsClientCert: "..."
tlsClientKey: "..."
version: 1
# <bool> allow users to edit datasources from the UI.
editable: true

View File

@@ -0,0 +1,13 @@
---
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
scrape_interval: 30s
static_configs:
- targets: ["localhost:9090"]
- job_name: "node"
static_configs:
- targets: ["node-exporter:9100"]