diff --git a/.editorconfig b/.editorconfig index 5bfb4ea..4aa48e2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*.yml] charset = utf-8 indent_style = space -indent_size = 4 +indent_size = 2 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true diff --git a/grafana/README.md b/grafana/README.md index 4305261..6d20f3a 100644 --- a/grafana/README.md +++ b/grafana/README.md @@ -4,3 +4,10 @@ * [Run Grafana Docker image](https://grafana.com/docs/grafana/latest/installation/docker/) * [Deploy Grafana on Kubernetes](https://grafana.com/docs/grafana/latest/installation/kubernetes/) +## 使用 + +初始化账号/密码 `admin/admin` + +## 数据目录 + +`/var/lib/grafana/` diff --git a/loki/config/loki-config.yaml b/loki/config/loki-config.yaml index 6d39f98..47a8b2e 100644 --- a/loki/config/loki-config.yaml +++ b/loki/config/loki-config.yaml @@ -2,7 +2,7 @@ auth_enabled: false server: http_listen_port: 3100 - grpc_listen_port: 9096 + grpc_listen_port: 9096 #grpc监听端口,默认为9095 ingester: wal: @@ -16,7 +16,7 @@ ingester: replication_factor: 1 final_sleep: 0s chunk_idle_period: 1h # Any chunk not receiving new logs in this time will be flushed - max_chunk_age: 1h # All chunks will be flushed when they hit this age, default is 1h + max_chunk_age: 1h # 一个timeseries块在内存中的最大持续时间。如果timeseries运行的时间超过此时间,则当前块将刷新到存储并创建一个新块, default is 1h chunk_target_size: 1048576 # Loki will attempt to build chunks up to 1.5MB, flushing first if chunk_idle_period or max_chunk_age is reached first chunk_retain_period: 30s # Must be greater than index read cache TTL if using an index cache (Default index read cache TTL is 5m) max_transfer_retries: 0 # Chunk transfers disabled @@ -47,13 +47,15 @@ compactor: limits_config: reject_old_samples: true reject_old_samples_max_age: 168h + ingestion_rate_mb: 4 #修改每用户摄入速率限制,即每秒样本量,默认值为4M + ingestion_burst_size_mb: 6 #修改每用户摄入速率限制,即每秒样本量,默认值为6M chunk_store_config: - max_look_back_period: 0s + max_look_back_period: 0s #回看日志行的最大时间,可参考 168h,即只看即时日志,可以减少存储消耗。 table_manager: - retention_deletes_enabled: false - retention_period: 0s + retention_deletes_enabled: false #日志保留周期开关,默认为false + retention_period: 0s #日志保留周期 ruler: storage: diff --git a/promtail/.env b/promtail/.env new file mode 100644 index 0000000..c7f9d22 --- /dev/null +++ b/promtail/.env @@ -0,0 +1 @@ +LOKI_ADDR=192.168.0.206 \ No newline at end of file diff --git a/promtail/config/promtail-config.yaml b/promtail/config/promtail-config.yaml index a23aa35..922691d 100644 --- a/promtail/config/promtail-config.yaml +++ b/promtail/config/promtail-config.yaml @@ -6,12 +6,33 @@ positions: filename: /tmp/positions.yaml clients: - - url: http://192.168.1.96:30191/loki/api/v1/push + - url: http://k8s.foo.com:30191/loki/api/v1/push scrape_configs: - - job_name: promtail-test-logs + - job_name: test-nginx-logs static_configs: - labels: - app: 'test-logs' + job: 'test-nginx-logs' __path__: /tmp/logs/*.log - + - job_name: test-app-logs + static_configs: + - labels: + job: 'test-app-logs' + __path__: /tmp/logs/app-*/*.log + pipeline_stages: + - match: + selector: '{job="test-app-logs"}' + stages: + - regex: + source: filename + expression: '(?:logs)/(?P\S+?)/' + - labels: + pod_name: + - match: + selector: '{job="test-app-logs"}' + stages: + - regex: + source: pod_name + expression: '^(?P.+)-[^-]+$' + - labels: + pod_collection: \ No newline at end of file diff --git a/promtail/docker-compose.yml b/promtail/docker-compose.yml index 2026199..623403d 100644 --- a/promtail/docker-compose.yml +++ b/promtail/docker-compose.yml @@ -1,16 +1,20 @@ version: '2.4' services: - promtail: - image: registry.cn-hangzhou.aliyuncs.com/kennylee/promtail:2.2.1 - container_name: promtail - restart: on-failure - command: '-config.file=/promtail/config/promtail-config.yaml' - volumes: - - ./config:/promtail/config:z - # 用于测试,读取的日志 - - ./logs:/tmp/logs - logging: - driver: 'json-file' - options: - max-size: '10m' - max-file: '1' + promtail: + image: registry.cn-hangzhou.aliyuncs.com/kennylee/promtail:2.2.1 + container_name: promtail + restart: on-failure + command: '-config.file=/promtail/config/promtail-config.yaml' + ports: + - 9080 + extra_hosts: + - "k8s.foo.com:${LOKI_ADDR}" + volumes: + - ./config:/promtail/config:z + # 用于测试,读取的日志 + - ./logs:/tmp/logs + logging: + driver: 'json-file' + options: + max-size: '10m' + max-file: '1' diff --git a/promtail/logs/app-88944fdd8-8xrqc/app.log b/promtail/logs/app-88944fdd8-8xrqc/app.log new file mode 100644 index 0000000..4f5e046 --- /dev/null +++ b/promtail/logs/app-88944fdd8-8xrqc/app.log @@ -0,0 +1,3 @@ +2021-06-26 18:18:35.165 WARN [tksite-dev,e4838a12138a7943,e4838a12138a7943,true] 11 --- [http-nio-8080-exec-9] c.a.druid.pool.DruidAbstractDataSource : discard long time none received connection. , jdbcUrl : jdbc:mysql://db-mysql:3306/tksite?useUnicode=true&characterEncoding=UTF-8, version : 1.2.4, lastPacketReceivedIdleMillis : 1877901 +2021-06-24 00:54:19.438 ERROR [tksite-dev,,,] 11 --- [main] c.c.t.c.w.a.h.LoggingHealthIndicator : LoggingHealthIndicator hello: 1 +2021-06-26 17:33:39.045 INFO [tksite-dev,,,] 11 --- [main] io.lettuce.core.KqueueProvider : Starting without optional kqueue library \ No newline at end of file