# gateway-docker-deploy
**Repository Path**: jiangsu-lanjiang-intelligent/gateway-docker-deploy
## Basic Information
- **Project Name**: gateway-docker-deploy
- **Description**: 网关部署
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-04-07
- **Last Updated**: 2023-04-10
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## 一键部署网关相关容器
traefik + grafana + loki + promtail + prometheus + consul
```
mkdir /data && cd /data
git clone https://gitee.com/jiangsu-lanjiang-intelligent/gateway-docker-deploy.git && cd gateway-docker-deploy
mkdir -p loki/data && chmod -R 777 loki/data
mkdir -p grafana/data && chmod -R 777 grafana/data
docker-compose up -d
```
## grafana 配置
- 安装grafana-piechart-panel插件
```
docker exec -it grafana grafana-cli plugins install grafana-piechart-panel
docker restart grafana
```
- 在grafana中增加prometheus和loki的数据源
- traefik - prometheus
```
import 12250
```
- traefik - loki
```
{"annotations":{"list":[{"builtIn":1,"datasource":"-- Grafana --","enable":true,"hide":true,"iconColor":"rgba(0, 211, 255, 1)","name":"Annotations & Alerts","type":"dashboard"}]},"description":"Loki version 2 showcase using JSON Traefik access logs.","editable":true,"gnetId":13713,"graphTooltip":0,"id":4,"links":[],"panels":[{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"thresholds":{"mode":"absolute","steps":[]}},"overrides":[]},"gridPos":{"h":2,"w":24,"x":0,"y":0},"id":32,"interval":"","options":{"content":"
\n

\n
Traefik Dashboard\n
","mode":"html"},"pluginVersion":"7.4.3","targets":[{"expr":"loki_build_info","format":"table","instant":false,"interval":"","legendFormat":"","refId":"A"}],"timeFrom":null,"timeShift":null,"title":"","transparent":true,"type":"text"},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]},"unit":"short"},"overrides":[]},"gridPos":{"h":4,"w":6,"x":0,"y":2},"id":4,"interval":"1m","options":{"colorMode":"background","graphMode":"area","justifyMode":"auto","orientation":"auto","reduceOptions":{"calcs":["sum"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":"sum(count_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" [$__interval]))","legendFormat":"","refId":"A"}],"timeFrom":"1h","timeShift":null,"title":"Total requests ","transformations":[],"transparent":true,"type":"stat"},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"light-blue","value":null}]},"unit":"short"},"overrides":[]},"gridPos":{"h":8,"w":9,"x":6,"y":2},"id":5,"interval":"30s","options":{"colorMode":"background","graphMode":"area","justifyMode":"auto","orientation":"auto","reduceOptions":{"calcs":["sum"],"fields":"","values":false},"text":{},"textMode":"auto"},"pluginVersion":"7.4.3","targets":[{"expr":"sum by (OriginStatus) (count_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" | json | __error__=\"\" [$__interval]))","legendFormat":"HTTP Status: {{OriginStatus}}","refId":"A"}],"timeFrom":"3h","timeShift":null,"title":"Requests per status code","transformations":[],"transparent":true,"type":"stat"},{"cacheTimeout":null,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"noValue":"0","thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null},{"color":"red","value":80}]},"unit":"percent"},"overrides":[]},"gridPos":{"h":4,"w":4,"x":15,"y":2},"id":19,"interval":"5m","links":[],"maxDataPoints":1,"options":{"colorMode":"background","graphMode":"none","justifyMode":"center","orientation":"auto","reduceOptions":{"calcs":["mean"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":" sum(rate({filename=\"/var/log/access.log\"} |~ \"RequestProtocol\" | json | OriginStatus >= 400 |__error__=\"\"[$__interval])) / (sum(rate({job=\"/var/log/traefik.log\"} |~ \"RequestProtocol\" | json | __error__=\"\"[$__interval])) / 100)","legendFormat":"","refId":"A"}],"timeFrom":"1h","timeShift":null,"title":"% of 4/5xx ","transparent":true,"type":"stat"},{"aliasColors":{},"bars":false,"cacheTimeout":null,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"thresholds":{"mode":"absolute","steps":[]},"unit":"none"},"overrides":[]},"fill":1,"fillGradient":0,"gridPos":{"h":4,"w":5,"x":19,"y":2},"hiddenSeries":false,"id":36,"interval":"1m","legend":{"avg":false,"current":false,"hideEmpty":true,"hideZero":true,"max":false,"min":false,"show":false,"total":false,"values":false},"lines":true,"linewidth":1,"links":[],"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":" sum by (OriginStatus,ServiceName) (count_over_time({filename=\"/var/log/access.log\"} |~ \"RequestProtocol\" | json | OriginStatus >= 400 |__error__=\"\"[$__interval]))","legendFormat":" {{ServiceName}} / {{OriginStatus}} ","refId":"A"}],"thresholds":[],"timeFrom":"3h","timeRegions":[],"timeShift":null,"title":" 4/5xx Services","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":false,"values":[]},"yaxes":[{"$$hashKey":"object:405","decimals":0,"format":"none","label":null,"logBase":1,"max":null,"min":"0","show":true},{"$$hashKey":"object:406","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]}},"overrides":[]},"gridPos":{"h":4,"w":6,"x":0,"y":6},"id":22,"interval":"5m","options":{"colorMode":"background","graphMode":"none","justifyMode":"auto","orientation":"auto","reduceOptions":{"calcs":["mean"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":"count(sum by (ClientHost) (count_over_time({filename=\"/var/log/access.log\"}|= \"RequestProtocol\" | json | __error__=\"\" [$__interval])))","legendFormat":"","refId":"A"}],"timeFrom":"5m","timeShift":null,"title":"Users right now","transformations":[],"transparent":true,"type":"stat"},{"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"mappings":[],"thresholds":{"mode":"absolute","steps":[{"color":"purple","value":null}]},"unit":"decbytes"},"overrides":[]},"gridPos":{"h":4,"w":8,"x":15,"y":6},"id":8,"interval":"1m","options":{"colorMode":"background","graphMode":"none","justifyMode":"center","orientation":"auto","reduceOptions":{"calcs":["sum"],"fields":"","values":false},"text":{},"textMode":"value"},"pluginVersion":"7.4.3","targets":[{"expr":"sum_over_time({filename=\"/var/log/access.log\"}|= \"RequestProtocol\" | json | OriginStatus=200 | unwrap DownstreamContentSize | __error__=\"\" [$__interval])","legendFormat":"Bytes sent","refId":"A"}],"timeFrom":"5m","timeShift":null,"title":"Total Bytes Sent","transformations":[{"id":"reduce","options":{"reducers":["sum"]}},{"id":"organize","options":{"excludeByName":{},"indexByName":{},"renameByName":{"Total":"Bytes Sent"}}}],"transparent":true,"type":"stat"},{"aliasColors":{},"breakPoint":"50%","cacheTimeout":null,"combine":{"label":"Others","threshold":0},"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"thresholds":{"mode":"absolute","steps":[]}},"overrides":[]},"fontSize":"80%","format":"short","gridPos":{"h":8,"w":8,"x":0,"y":10},"id":33,"interval":"5m","legend":{"percentage":true,"show":true,"values":true},"legendType":"Right side","links":[],"maxDataPoints":3,"nullPointMode":"connected","pieType":"pie","pluginVersion":"7.3.4","strokeWidth":1,"targets":[{"expr":"sum by (RouterName) (count_over_time({filename=\"/var/log/access.log\"}|= \"RequestProtocol\" | json | __error__=\"\" [$__interval]))","legendFormat":"{{RouterName}}","refId":"A"}],"timeFrom":"1h","timeShift":null,"title":"Requests Route","transformations":[],"transparent":true,"type":"grafana-piechart-panel","valueName":"current"},{"datasource":"Loki","fieldConfig":{"defaults":{"custom":{}},"overrides":[]},"gridPos":{"h":8,"w":16,"x":8,"y":10},"id":11,"interval":"","options":{"showLabels":false,"showTime":true,"sortOrder":"Descending","wrapLogMessage":false},"targets":[{"expr":"{filename=\"/var/log/access.log\"} |= \"RequestProtocol\"| json | line_format \"Status:{{.OriginStatus}} Client From {{.ClientAddr}} {{.RequestMethod}} {{.RequestAddr}}{{.RequestPath}} Route To {{.ServiceAddr}}\"","legendFormat":"","refId":"A"}],"timeFrom":"5m","timeShift":null,"title":"Logs","transparent":true,"type":"logs"},{"aliasColors":{"95th percentile":"blue","max latency":"super-light-blue"},"bars":false,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"unit":"ns"},"overrides":[]},"fill":5,"fillGradient":9,"gridPos":{"h":9,"w":8,"x":0,"y":18},"hiddenSeries":false,"id":16,"interval":"30s","legend":{"alignAsTable":false,"avg":false,"current":false,"max":true,"min":false,"rightSide":false,"show":true,"total":false,"values":true},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[{"$$hashKey":"object:232","alias":"max latency","dashes":true,"fillGradient":3}],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"quantile_over_time(0.95,{filename=\"/var/log/access.log\"} |= \"RequestProtocol\"| json | unwrap Duration | __error__=\"\" [$__interval]) by (ServiceName)","hide":false,"legendFormat":" {{ ServiceName }}","refId":"C"}],"thresholds":[{"$$hashKey":"object:168","colorMode":"critical","fill":true,"line":true,"op":"gt","value":0.3,"yaxis":"left"}],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"95th percentile of Request Time","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"$$hashKey":"object:178","format":"ns","label":null,"logBase":1,"max":null,"min":null,"show":true},{"$$hashKey":"object:179","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}},{"aliasColors":{"95th percentile":"blue","max latency":"super-light-blue"},"bars":false,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"unit":"ns"},"overrides":[]},"fill":5,"fillGradient":9,"gridPos":{"h":9,"w":8,"x":8,"y":18},"hiddenSeries":false,"id":34,"interval":"30s","legend":{"alignAsTable":false,"avg":false,"current":false,"max":false,"min":false,"rightSide":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[{"$$hashKey":"object:232","alias":"max latency","dashes":true,"fillGradient":3}],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"max by (ServiceName) (max_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" |json | unwrap Duration | __error__=\"\" [$__interval]))","hide":false,"legendFormat":"{{ ServiceName}}","refId":"D"}],"thresholds":[{"$$hashKey":"object:168","colorMode":"critical","fill":true,"line":true,"op":"gt","value":0.3,"yaxis":"left"}],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"Max Age of Request Time","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"$$hashKey":"object:178","format":"ns","label":null,"logBase":1,"max":null,"min":null,"show":true},{"$$hashKey":"object:179","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}},{"aliasColors":{"95th percentile":"blue","max latency":"super-light-blue"},"bars":false,"dashLength":10,"dashes":false,"datasource":"Loki","description":"","fieldConfig":{"defaults":{"custom":{},"unit":"decbytes"},"overrides":[]},"fill":5,"fillGradient":9,"gridPos":{"h":9,"w":8,"x":16,"y":18},"hiddenSeries":false,"id":35,"interval":"30s","legend":{"alignAsTable":false,"avg":false,"current":false,"max":false,"min":false,"rightSide":false,"show":true,"total":false,"values":false},"lines":true,"linewidth":1,"nullPointMode":"null","options":{"alertThreshold":true},"percentage":false,"pluginVersion":"7.4.3","pointradius":2,"points":false,"renderer":"flot","seriesOverrides":[{"$$hashKey":"object:232","alias":"max latency","dashes":true,"fillGradient":3}],"spaceLength":10,"stack":false,"steppedLine":false,"targets":[{"expr":"sum by (ServiceName) (sum_over_time({filename=\"/var/log/access.log\"} |= \"RequestProtocol\" |json | unwrap RequestContentSize | __error__=\"\" [$__interval]))","hide":false,"legendFormat":"{{ ServiceName}}","refId":"D"}],"thresholds":[{"$$hashKey":"object:168","colorMode":"critical","fill":true,"line":true,"op":"gt","value":0.3,"yaxis":"left"}],"timeFrom":null,"timeRegions":[],"timeShift":null,"title":"Requests Size","tooltip":{"shared":true,"sort":0,"value_type":"individual"},"transparent":true,"type":"graph","xaxis":{"buckets":null,"mode":"time","name":null,"show":true,"values":[]},"yaxes":[{"$$hashKey":"object:178","format":"decbytes","label":null,"logBase":1,"max":null,"min":null,"show":true},{"$$hashKey":"object:179","format":"short","label":null,"logBase":1,"max":null,"min":null,"show":false}],"yaxis":{"align":false,"alignLevel":null}}],"refresh":false,"schemaVersion":27,"style":"dark","tags":[],"templating":{"list":[]},"time":{"from":"now-1h","to":"now"},"timepicker":{"refresh_intervals":["10s","30s","1m","5m","15m","30m","1h","2h","1d"]},"timezone":"","title":"Traefik Via Loki","uid":"fJarCeaGk","version":2}
```