Skip to content

Commit

Permalink
feat: loki and promtail
Browse files Browse the repository at this point in the history
  • Loading branch information
janikvonrotz committed Feb 3, 2025
1 parent b7b4bc0 commit af69821
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 57 deletions.
2 changes: 2 additions & 0 deletions plays/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
tags: n8n_exporter
- role: restic_exporter
tags: restic_exporter
- role: promtail
tags: promtail
- role: loki
tags: loki
- role: acme_sh
Expand Down
28 changes: 23 additions & 5 deletions roles/loki/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Configure the role.

```yml
# https://hub.docker.com/r/grafana/loki/
loki_image: grafana/loki
loki_image: grafana/loki:3.3.2
loki_hostname: loki01
loki_description: log index for grafana # default: Loki
loki_nginx_data_dir: /usr/share/nginx/proxies # default: "{{ nginx_data_dir }}/proxies"
Expand Down Expand Up @@ -43,11 +43,29 @@ The following tags are available:
## Docs
### Add Loki datasource to Grafana
In the grafana dashboard add a new connection and select "Loki".
Enter URL <http://loki01:3100> of your container instance.
Save and test the connection.
### Send test request to push api
Send test data to push api with with curl using basic auth.
Send test data to push api with with curl.
```
curl -v -H "Content-Type: application/json" -XPOST -s "http://localhost:3100/loki/api/v1/push" --data-raw \
```bash
curl -v -H "Content-Type: application/json" -XPOST -s "http://loki01:3100/loki/api/v1/push" --data-raw \
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}'
```
```


Send test data to push api with with curl with basic auth.

```bash
curl -v -H "Content-Type: application/json" -XPOST -s "https://monitor.example.com/loki/api/v1/push" \
-u loki:$BASIC_AUTH_PASSWORD \
--data-raw \
'{"streams": [{ "stream": { "foo": "bar2" }, "values": [ [ "1570818238000000000", "fizzbuzz" ] ] }]}'
```
79 changes: 28 additions & 51 deletions roles/loki/templates/local-config.yml
Original file line number Diff line number Diff line change
@@ -1,69 +1,46 @@
# https://github.com/grafana/loki/blob/v2.3.0/cmd/loki/loki-local-config.yaml
#FROM: https://raw.githubusercontent.com/grafana/loki/refs/tags/v3.3.2/cmd/loki/loki-local-config.yaml
auth_enabled: false

server:
http_listen_port: 3100
grpc_listen_port: 9096
log_level: debug
grpc_server_max_concurrent_streams: 1000

ingester:
wal:
enabled: true
dir: /tmp/wal
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
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
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
common:
instance_addr: 127.0.0.1
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory

query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100

schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
store: tsdb
object_store: filesystem
schema: v11
schema: v13
index:
prefix: index_
period: 24h

storage_config:
boltdb_shipper:
active_index_directory: /tmp/loki/boltdb-shipper-active
cache_location: /tmp/loki/boltdb-shipper-cache
cache_ttl: 24h # Can be increased for faster performance over longer query periods, uses more disk space
shared_store: filesystem
filesystem:
directory: /tmp/loki/chunks

compactor:
working_directory: /tmp/loki/boltdb-shipper-compactor
shared_store: filesystem

limits_config:
reject_old_samples: true
reject_old_samples_max_age: 168h

chunk_store_config:
max_look_back_period: 0s

table_manager:
retention_deletes_enabled: false
retention_period: 0s
pattern_ingester:
enabled: true

ruler:
storage:
type: local
local:
directory: /tmp/loki/rules
rule_path: /tmp/loki/rules-temp
alertmanager_url: http://localhost:9093
ring:
kvstore:
store: inmemory
enable_api: true

frontend:
encoding: protobuf
3 changes: 2 additions & 1 deletion roles/promtail/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Configure the role.

```yml
# https://hub.docker.com/r/grafana/promtail/
promtail_image: grafana/promtail:2.3.0
promtail_image: grafana/promtail:3.3.2
promtail_hostname: promtail01
promtail_description: forwad logs to loki # default: Promtail
promtail_state: stopped # default: started
promtail_data_dir: /usr/share/promtail # default: "/usr/share/{{ promtail_hostname }}"
promtail_push_url: loki.example.com/loki/api/v1/push
promtail_loki_basic_auth_username: log # default: loki
Expand Down
1 change: 1 addition & 0 deletions roles/promtail/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
promtail_description: Promtail
promtail_loki_basic_auth_username: loki
promtail_data_dir: /usr/share/{{ promtail_hostname }}
promtail_state: started
1 change: 1 addition & 0 deletions roles/promtail/tasks/promtail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
image: "{{ promtail_image }}"
restart_policy: unless-stopped
recreate: false
state: "{{ promtail_state }}"
volumes:
- "{{ docker_data_dir }}:/var/lib/docker:ro"
- "{{ promtail_data_dir }}:/etc/promtail"
Expand Down
2 changes: 2 additions & 0 deletions roles/promtail/templates/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#FROM: https://github.com/grafana/loki/blob/v3.3.2/clients/cmd/promtail/promtail-local-config.yaml

server:
http_listen_address: 0.0.0.0
http_listen_port: 9080
Expand Down

0 comments on commit af69821

Please sign in to comment.