push base
This commit is contained in:
commit
750e38b7fd
24
README.md
Normal file
24
README.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# LOKI PROMTAIL GRAFANA
|
||||||
|
|
||||||
|
Simple stack pour monitorer les logs des conteneurs ou applications d'un serveur via LOKI / PROMTAIL
|
||||||
|
|
||||||
|
## CONFIGURATION
|
||||||
|
|
||||||
|
Pour que LOKI récupère les logs des conteneurs il faut ajouter les labels au docker-compose.yml:
|
||||||
|
```yml
|
||||||
|
labels:
|
||||||
|
logging: "promtail"
|
||||||
|
logging_jobname: "containerlogs"
|
||||||
|
```
|
||||||
|
|
||||||
|
## UTILISATION
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
## DASHBOARD
|
||||||
|
|
||||||
|
> Faire la dashboard standard
|
||||||
|
|
||||||
|
- [ ] TLS config (https)
|
||||||
44
docker-compose.yml
Normal file
44
docker-compose.yml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# APP EXEMPLE
|
||||||
|
nginx-app:
|
||||||
|
container_name: nginx-app
|
||||||
|
image: nginx
|
||||||
|
# NECESSARY FOR LOKI
|
||||||
|
labels:
|
||||||
|
logging: "promtail"
|
||||||
|
logging_jobname: "containerlogs"
|
||||||
|
ports:
|
||||||
|
- 8080:80
|
||||||
|
|
||||||
|
grafana:
|
||||||
|
image: grafana/grafana:latest
|
||||||
|
container_name: grafana
|
||||||
|
ports:
|
||||||
|
- 3000:3000
|
||||||
|
volumes:
|
||||||
|
volumes:
|
||||||
|
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
|
||||||
|
- ./grafana/dashboards:/var/lib/grafana/dashboards
|
||||||
|
|
||||||
|
loki:
|
||||||
|
image: grafana/loki:latest
|
||||||
|
container_name: loki
|
||||||
|
ports:
|
||||||
|
- 3100:3100
|
||||||
|
volumes:
|
||||||
|
- ./loki/config:/etc/loki
|
||||||
|
- ./loki/certs:/etc/loki/certs
|
||||||
|
command: -config.file=/etc/loki/config.yml
|
||||||
|
|
||||||
|
promtail:
|
||||||
|
image: grafana/promtail:latest
|
||||||
|
container_name: promtail
|
||||||
|
volumes:
|
||||||
|
- ./promtail/config.yml:/etc/promtail/config.yaml
|
||||||
|
- /var/lib/docker/containers:/var/lib/docker/containers:ro
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
command: -config.file=/etc/promtail/config.yaml
|
||||||
|
depends_on:
|
||||||
|
- loki
|
||||||
81
grafana/dashboards/dashboard-exemple.json
Normal file
81
grafana/dashboards/dashboard-exemple.json
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"annotations": {
|
||||||
|
"list": [
|
||||||
|
{
|
||||||
|
"builtIn": 1,
|
||||||
|
"datasource": {
|
||||||
|
"type": "grafana",
|
||||||
|
"uid": "-- Grafana --"
|
||||||
|
},
|
||||||
|
"enable": true,
|
||||||
|
"hide": true,
|
||||||
|
"iconColor": "rgba(0, 211, 255, 1)",
|
||||||
|
"name": "Annotations & Alerts",
|
||||||
|
"type": "dashboard"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"editable": true,
|
||||||
|
"fiscalYearStartMonth": 0,
|
||||||
|
"graphTooltip": 0,
|
||||||
|
"id": 1,
|
||||||
|
"links": [],
|
||||||
|
"liveNow": false,
|
||||||
|
"panels": [
|
||||||
|
{
|
||||||
|
"datasource": {
|
||||||
|
"type": "loki",
|
||||||
|
"uid": "P8E80F9AEF21F6940"
|
||||||
|
},
|
||||||
|
"gridPos": {
|
||||||
|
"h": 9,
|
||||||
|
"w": 24,
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"id": 1,
|
||||||
|
"options": {
|
||||||
|
"dedupStrategy": "none",
|
||||||
|
"enableLogDetails": true,
|
||||||
|
"prettifyLogMessage": false,
|
||||||
|
"showCommonLabels": false,
|
||||||
|
"showLabels": false,
|
||||||
|
"showTime": false,
|
||||||
|
"sortOrder": "Descending",
|
||||||
|
"wrapLogMessage": false
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"datasource": {
|
||||||
|
"type": "loki",
|
||||||
|
"uid": "P8E80F9AEF21F6940"
|
||||||
|
},
|
||||||
|
"editorMode": "builder",
|
||||||
|
"expr": "{container=\"nginx-app\"} |= ``",
|
||||||
|
"key": "Q-d83b192b-23c0-4458-9a28-0d178f451096-0",
|
||||||
|
"queryType": "range",
|
||||||
|
"refId": "A"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"title": "nginx-app logs",
|
||||||
|
"transformations": [],
|
||||||
|
"type": "logs"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"refresh": "5s",
|
||||||
|
"schemaVersion": 39,
|
||||||
|
"tags": [],
|
||||||
|
"templating": {
|
||||||
|
"list": []
|
||||||
|
},
|
||||||
|
"time": {
|
||||||
|
"from": "now-6h",
|
||||||
|
"to": "now"
|
||||||
|
},
|
||||||
|
"timepicker": {},
|
||||||
|
"timezone": "",
|
||||||
|
"title": "dashboard-exemple",
|
||||||
|
"uid": "f5bb84b2-b3f1-4776-9ab5-5d2389adfaec",
|
||||||
|
"version": 1,
|
||||||
|
"weekStart": ""
|
||||||
|
}
|
||||||
20
grafana/provisioning/dashboards/providers.yaml
Normal file
20
grafana/provisioning/dashboards/providers.yaml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
apiVersion: 1
|
||||||
|
|
||||||
|
# providers:
|
||||||
|
# - name: 'main'
|
||||||
|
# orgId: 1
|
||||||
|
# folder: ''
|
||||||
|
# type: file
|
||||||
|
# disableDeletion: true
|
||||||
|
# options:
|
||||||
|
# path: /app.cfg/dashboards
|
||||||
|
|
||||||
|
providers:
|
||||||
|
- name: 'default'
|
||||||
|
orgId: 1
|
||||||
|
folder: ''
|
||||||
|
type: file
|
||||||
|
disableDeletion: false
|
||||||
|
updateIntervalSeconds: 3 #how often Grafana will scan for changed dashboards
|
||||||
|
options:
|
||||||
|
path: /var/lib/grafana/dashboards
|
||||||
38
grafana/provisioning/datasources/datasources.yaml
Normal file
38
grafana/provisioning/datasources/datasources.yaml
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# apiVersion: 1
|
||||||
|
|
||||||
|
# datasources:
|
||||||
|
# - name: loki
|
||||||
|
# access: proxy
|
||||||
|
# type: loki
|
||||||
|
# url: http://loki:3100
|
||||||
|
# isDefault: true
|
||||||
|
# database: ''
|
||||||
|
# user: ''
|
||||||
|
# password: ''
|
||||||
|
# basicAuth: false
|
||||||
|
# id: 1
|
||||||
|
# orgId: 1
|
||||||
|
# readOnly: false
|
||||||
|
# jsonData:
|
||||||
|
# keepCookies: []
|
||||||
|
# typeLogoUrl: public/app/plugins/datasource/loki/img/loki_icon.svg
|
||||||
|
# - name: prometheus
|
||||||
|
# access: proxy
|
||||||
|
# type: prometheus
|
||||||
|
# url: http://prometheus:9090
|
||||||
|
# isDefault: false
|
||||||
|
# orgId: 1
|
||||||
|
# editable: false
|
||||||
|
# jsonData:
|
||||||
|
# timeInterval: 10s
|
||||||
|
|
||||||
|
apiVersion: 1
|
||||||
|
|
||||||
|
datasources:
|
||||||
|
- name: Loki
|
||||||
|
type: loki
|
||||||
|
access: proxy
|
||||||
|
url: http://loki:3100
|
||||||
|
version: 1
|
||||||
|
editable: false
|
||||||
|
isDefault: true
|
||||||
45
loki/config/config.yml
Normal file
45
loki/config/config.yml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
auth_enabled: false
|
||||||
|
|
||||||
|
server:
|
||||||
|
http_listen_port: 3100
|
||||||
|
# HTTPS /TLS
|
||||||
|
# http_tls_config: &tls_server_config
|
||||||
|
# cert_file: /etc/loki/cert.pem
|
||||||
|
# key_file: /etc/loki/key.pem
|
||||||
|
|
||||||
|
common:
|
||||||
|
path_prefix: /loki
|
||||||
|
storage:
|
||||||
|
filesystem:
|
||||||
|
chunks_directory: /loki/chunks
|
||||||
|
rules_directory: /loki/rules
|
||||||
|
replication_factor: 1
|
||||||
|
ring:
|
||||||
|
kvstore:
|
||||||
|
store: inmemory
|
||||||
|
|
||||||
|
schema_config:
|
||||||
|
configs:
|
||||||
|
- from: 2020-10-24
|
||||||
|
store: boltdb-shipper
|
||||||
|
object_store: filesystem
|
||||||
|
schema: v11
|
||||||
|
index:
|
||||||
|
prefix: index_
|
||||||
|
period: 24h
|
||||||
|
|
||||||
|
ruler:
|
||||||
|
alertmanager_url: http://localhost:9093
|
||||||
|
|
||||||
|
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
|
||||||
|
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
|
||||||
|
#
|
||||||
|
# Statistics help us better understand how Loki is used, and they show us performance
|
||||||
|
# levels for most users. This helps us prioritize features and documentation.
|
||||||
|
# For more information on what's sent, look at
|
||||||
|
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
|
||||||
|
# Refer to the buildReport method to see what goes into a report.
|
||||||
|
#
|
||||||
|
# If you would like to disable reporting, uncomment the following lines:
|
||||||
|
#analytics:
|
||||||
|
# reporting_enabled: false
|
||||||
60
promtail/config.yml
Normal file
60
promtail/config.yml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# # todo
|
||||||
|
# server:
|
||||||
|
# http_listen_port: 9090
|
||||||
|
# grpc_listen_port: 0
|
||||||
|
|
||||||
|
# positions:
|
||||||
|
# filename: /tmp/positions.yaml
|
||||||
|
|
||||||
|
# clients:
|
||||||
|
# - url: http://loki
|
||||||
|
|
||||||
|
# scrape_configs:
|
||||||
|
|
||||||
|
# - job_name: nginx
|
||||||
|
# static_configs:
|
||||||
|
# - targets:
|
||||||
|
# - localhost
|
||||||
|
# labels:
|
||||||
|
# host: localhost
|
||||||
|
# job: nginx-logs
|
||||||
|
# __path__: /var/log/nginx/*log
|
||||||
|
|
||||||
|
# https://grafana.com/docs/loki/latest/clients/promtail/configuration/
|
||||||
|
# https://docs.docker.com/engine/api/v1.41/#operation/ContainerList
|
||||||
|
server:
|
||||||
|
http_listen_port: 9080
|
||||||
|
grpc_listen_port: 0
|
||||||
|
|
||||||
|
positions:
|
||||||
|
filename: /tmp/positions.yaml
|
||||||
|
|
||||||
|
clients:
|
||||||
|
# LOCAL
|
||||||
|
- url: http://loki:3100/loki/api/v1/push
|
||||||
|
# DISTANT WITH TLS
|
||||||
|
# - url: http://<Redacted>/loki/api/v1/push
|
||||||
|
# tls_config:
|
||||||
|
# ca_file: /etc/loki/certs/ca.crt
|
||||||
|
# cert_file: /etc/loki/certs/cert.pem
|
||||||
|
# key_file: /etc/loki/certs/key.pem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: flog_scrape
|
||||||
|
docker_sd_configs:
|
||||||
|
- host: unix:///var/run/docker.sock
|
||||||
|
refresh_interval: 5s
|
||||||
|
filters:
|
||||||
|
- name: label
|
||||||
|
values: ["logging=promtail"]
|
||||||
|
relabel_configs:
|
||||||
|
- source_labels: ['__meta_docker_container_name']
|
||||||
|
regex: '/(.*)'
|
||||||
|
target_label: 'container'
|
||||||
|
- source_labels: ['__meta_docker_container_log_stream']
|
||||||
|
target_label: 'logstream'
|
||||||
|
- source_labels: ['__meta_docker_container_label_logging_jobname']
|
||||||
|
target_label: 'job'
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user