DEV Community

muckitymuck
muckitymuck

Posted on

Prometheus Additional Configs

This is for the prometheus.service created

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=ubuntu
Group=ubuntu
Type=simple
ExecStart=/usr/bin/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --storage.tsdb.retention=2d
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode

--storage.tsdb.path is for where logs will be stored
--storage.tsdb.retention is for how long will the logs be stored

Other settings prometheus.yml

global:
  scrape_interval: 15s
  evaluation_interval: 15s
# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"
    - "/etc/prometheus/mem_over.yml # A Rule for Alert noted below

scrape_configs:
  - job_name: 'prometheus'
    # scrape frequency
    scrape_interval: 1m
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'node'
    # scrape frequency
    scrape_interval: 1m
    static_configs:
      - targets: ['localhost:9100']

Enter fullscreen mode Exit fullscreen mode

A Rule that can send alerts under conditions, mem_over.yml:

groups:
- name: Memory alarm rules
  rules:
  - alert: Memory usage alarm
    expr: (node_memory_MemTotal_bytes - (node_memory_MemFree_bytes+node_memory_Buffers_bytes+node_memory_Cached_bytes )) / node_memory_MemTotal_bytes * 100 > 80
    for: 1m
    labels:
      user: prometheus
      severity: warning
    annotations:
      description: "The server: Memory usage over 80%!(Current value: {{ $value }}%)"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)