Skip to content

Commit

Permalink
Add templates for application host
Browse files Browse the repository at this point in the history
  • Loading branch information
ernitingarg committed Oct 22, 2023
1 parent 8365605 commit 40912c1
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This tool automatically generates deployment package required for monitoring hos

### Services for Application Host(s)

Please make sure below services are running on application host. (_The configuration and deployment of services related to application host is not covered in this document, however a docker-compose file can be used to install below services in application host machine_)
Please make sure below services are running on application host. (_The configuration and deployment of services related to application host is not covered in this document, however you can find template files at path [application](application)._)

- Application
- outputs log to file or console
Expand Down
42 changes: 42 additions & 0 deletions application/templates/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: '3'
services:
nodeexporter:
image: prom/node-exporter:latest
container_name: nodeexporter
restart: always
ports:
- 9100:9100
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.ignored-mount-points=^/(sys|proc|dev|host|etc|run)($$|/)'

cadvisor:
image: google/cadvisor:latest
container_name: cadvisor
privileged: true
restart: always
ports:
- 8080:8080
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro

promtail:
image: grafana/promtail:latest
container_name: promtail
restart: always
ports:
- 9080:9080
volumes:
- /var/log:/var/log
- ${MY_APP_PATH}/promtail:/etc/promtail # eg: /home/demo-app (Also, please keep promtail.yml file inside /home/demo-app/promtail )
command:
- '--config.file=/etc/promtail/promtail.yml'
111 changes: 111 additions & 0 deletions application/templates/promtail/promtail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
server:
http_listen_port: 9080
grpc_listen_port: 0

# this is important for maintaining position of logs.
# if this file is deleted, all the logs will be resent.
positions:
filename: ${MY_APP_PATH}/promtail/log_positions.yaml # eg: /home/demo-app/

clients:
- url: http://${MONITORING_IP_ADDRESS}:3100/loki/api/v1/push # IP address of monitoring host

scrape_configs:
- job_name: application_job
pipeline_stages:
- regex:
expression: '^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) \[(?P<threadName>[\s\S]*)\] (?P<level>\w+)\s*(?P<component>[a-zA-Z0-9.]*) - (?P<content>[\s\S]*)'
- multiline:
firstline: '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}'
- template:
source: timestamp
template: '{{ Replace .Value "," "." 1 }}'
- timestamp:
source: timestamp
format: "2006-01-02 15:04:05.000"
- labels:
level:
- metrics:
log_lines_total:
type: Counter
description: "total number of log lines"
prefix: promtail_custom_
max_idle_duration: 24h
config:
match_all: true
action: inc
log_bytes_total:
type: Counter
description: "total bytes of log lines"
prefix: promtail_custom_
max_idle_duration: 24h
config:
match_all: true
count_entry_bytes: true
action: add
- match:
selector: '{target_os="Linux"}'
stages:
- regex:
source: filename
expression: "/(.+/)(?P<filename>\\S+)"
- template:
source: filename
template: "${HOST_NAME}_{{ .Value }}" # Name of machine
- labels:
filename:
- match:
selector: '{target_os="Windows"}'
stages:
- regex:
source: filename
expression: "([a-z]:)\\\\(.+\\\\)(?P<filename>\\S+)"
- template:
source: filename
template: "${HOST_NAME}_{{ .Value }}" # Name of machine
- labels:
filename:
static_configs:
- labels:
target_app: ${MY_APP_NAME} # Application Name (eg: demo-app)
target_os: Linux
target_env: ${ENV} # Environment (eg: production)
target_host: ${HOST_NAME} # Name of machine
__path__: ${MY_APP_LOG_PATH} # Application log path (g: /home/demo-app/logs/*log)

- job_name: windows_system_job
pipeline_stages:
- labeldrop:
- channel
- computer
windows_events:
use_incoming_timestamp: true
bookmark_path: "./bookmark.xml"
eventlog_name: "Application"
xpath_query: "*"
labels:
target_app: system
target_os: Windows
target_env: ${ENV} # Environment (eg: production)
target_host: ${HOST_NAME} # Name of machine

- job_name: linux_system_job
pipeline_stages:
- match:
selector: '{target_os="Linux"}'
stages:
- regex:
source: filename
expression: "/(.+/)(?P<filename>\\S+)"
- template:
source: filename
template: "${HOST_NAME}_{{ .Value }}" # Name of machine
- labels:
filename:
static_configs:
- labels:
target_app: system
target_os: Linux
target_env: ${ENV} # Environment (eg: production)
target_host: ${HOST_NAME} # Name of machine
__path__: /var/log/*log

0 comments on commit 40912c1

Please sign in to comment.