├── README.md ├── docker ├── docker-compose.yaml └── prometheus │ └── prometheus.yml ├── install-grafana.sh ├── install-node-exporter.sh ├── install-prometheus.sh ├── node-exporter-init.dservice ├── README.md ├── install-node-exporter.sh ├── node-exporter-init.d.service └── node_exporter.sh ├── node-exporter.service ├── prometheus.service ├── prometheus.yml ├── prometheus_ec2.yml ├── prometheus_relabeeling.yml └── prometheus_serviceDiscovery.yml /README.md: -------------------------------------------------------------------------------- 1 | # prometheus-monitoring 2 | -------------------------------------------------------------------------------- /docker/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | grafana: 4 | image: "grafana/grafana" 5 | ports: 6 | - "3000:3000" 7 | volumes: 8 | - "grafana-storage:/var/lib/grafana" 9 | 10 | prometheus: 11 | image: "prom/prometheus" 12 | ports: 13 | - "9090:9090" 14 | volumes: 15 | - "${PWD-.}/prometheus:/etc/prometheus" 16 | 17 | volumes: 18 | grafana-storage: 19 | -------------------------------------------------------------------------------- /docker/prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | external_labels: 4 | monitor: 'prometheus' 5 | 6 | scrape_configs: 7 | - job_name: 'prometheus' 8 | static_configs: 9 | - targets: ['localhost:9090'] 10 | -------------------------------------------------------------------------------- /install-grafana.sh: -------------------------------------------------------------------------------- 1 | sudo apt-get install -y adduser libfontconfig1 2 | wget https://dl.grafana.com/oss/release/grafana_7.3.4_amd64.deb 3 | sudo dpkg -i grafana_7.3.4_amd64.deb 4 | sudo systemctl daemon-reload 5 | sudo systemctl start grafana-server 6 | sudo systemctl status grafana-server 7 | sudo systemctl enable grafana-server.service 8 | -------------------------------------------------------------------------------- /install-node-exporter.sh: -------------------------------------------------------------------------------- 1 | sudo useradd --no-create-home node_exporter 2 | 3 | wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz 4 | tar xzf node_exporter-1.0.1.linux-amd64.tar.gz 5 | sudo cp node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin/node_exporter 6 | rm -rf node_exporter-1.0.1.linux-amd64.tar.gz node_exporter-1.0.1.linux-amd64 7 | 8 | sudo cp node-exporter.service /etc/systemd/system/node-exporter.service 9 | 10 | sudo systemctl daemon-reload 11 | sudo systemctl enable node-exporter 12 | sudo systemctl start node-exporter 13 | sudo systemctl status node-exporter 14 | -------------------------------------------------------------------------------- /install-prometheus.sh: -------------------------------------------------------------------------------- 1 | sudo useradd --no-create-home prometheus 2 | sudo mkdir /etc/prometheus 3 | sudo mkdir /var/lib/prometheus 4 | 5 | wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz 6 | tar -xvf prometheus-2.23.0.linux-amd64.tar.gz 7 | sudo cp prometheus-2.23.0.linux-amd64/prometheus /usr/local/bin 8 | sudo cp prometheus-2.23.0.linux-amd64/promtool /usr/local/bin 9 | sudo cp -r prometheus-2.23.0.linux-amd64/consoles /etc/prometheus/ 10 | sudo cp -r prometheus-2.23.0.linux-amd64/console_libraries /etc/prometheus 11 | sudo cp prometheus-2.23.0.linux-amd64/promtool /usr/local/bin/ 12 | 13 | rm -rf prometheus-2.23.0.linux-amd64.tar.gz prometheus-2.19.0.linux-amd64 14 | sudo cp prometheus.yml /etc/prometheus/ 15 | sudo cp prometheus.service /etc/systemd/system/prometheus.service 16 | 17 | sudo chown prometheus:prometheus /etc/prometheus 18 | sudo chown prometheus:prometheus /usr/local/bin/prometheus 19 | sudo chown prometheus:prometheus /usr/local/bin/promtool 20 | sudo chown -R prometheus:prometheus /etc/prometheus/consoles 21 | sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries 22 | sudo chown -R prometheus:prometheus /var/lib/prometheus 23 | 24 | sudo systemctl daemon-reload 25 | sudo systemctl enable prometheus 26 | sudo systemctl start prometheus 27 | sudo systemctl status prometheus 28 | 29 | 30 | -------------------------------------------------------------------------------- /node-exporter-init.dservice/README.md: -------------------------------------------------------------------------------- 1 | # install node exporter with init.d service 2 | 3 | # Steps 4 | 1. Run `install-node-exporter.sh' 5 | This will create the directory structure, download the software and run the service as init.directory 6 | -------------------------------------------------------------------------------- /node-exporter-init.dservice/install-node-exporter.sh: -------------------------------------------------------------------------------- 1 | mkdir /opt/node-exporter 2 | wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz 3 | tar xzf node_exporter-1.0.1.linux-amd64.tar.gz 4 | sudo cp node_exporter-1.0.1.linux-amd64/node_exporter /opt/node-exporter 5 | rm -rf node_exporter-1.0.1.linux-amd64.tar.gz node_exporter-1.0.1.linux-amd64 6 | sudo cp node_exporter.sh /opt/node-exporter 7 | sudo cp node-exporter-init.d.service /etc/init.d/node_exporter 8 | sudo chmod +x /etc/init.d/node_exporter 9 | sudo chmod +x /opt/node-exporter/node_exporter.sh 10 | chkconfig --add node_exporter 11 | sudo service node_exporter start 12 | sudo service node_exporter status 13 | 14 | -------------------------------------------------------------------------------- /node-exporter-init.dservice/node-exporter-init.d.service: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: node_exporter 4 | # Required-Start: $local_fs $network $named $time $syslog 5 | # Required-Stop: $local_fs $network $named $time $syslog 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 0 1 6 8 | # Description: 9 | ### END INIT INFO 10 | 11 | SCRIPT=/opt/node-exporter/node_exporter.sh 12 | RUNAS=root 13 | 14 | PIDFILE=/var/run/node_exporter.pid 15 | LOGFILE=/var/log/node_exporter.log 16 | 17 | start() { 18 | if [ -f "$PIDFILE" ] && kill -0 $(cat "$PIDFILE"); then 19 | echo 'Service already running' >&2 20 | return 1 21 | fi 22 | echo 'Starting service…' >&2 23 | local CMD="$SCRIPT &> \"$LOGFILE\" && echo \$! > $PIDFILE" 24 | su -c "$CMD" $RUNAS > "$LOGFILE" & 25 | echo 'Service started' >&2 26 | } 27 | 28 | stop() { 29 | if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then 30 | echo 'Service not running' >&2 31 | return 1 32 | fi 33 | echo 'Stopping service' >&2 34 | kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" 35 | echo 'Service stopped' >&2 36 | } 37 | 38 | uninstall() { 39 | echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] " 40 | local SURE 41 | read SURE 42 | if [ "$SURE" = "yes" ]; then 43 | stop 44 | rm -f "$PIDFILE" 45 | echo "Notice: log file is not be removed: '$LOGFILE'" >&2 46 | update-rc.d -f remove 47 | rm -fv "$0" 48 | fi 49 | } 50 | 51 | case "$1" in 52 | start) 53 | start 54 | ;; 55 | stop) 56 | stop 57 | ;; 58 | uninstall) 59 | uninstall 60 | ;; 61 | retart) 62 | stop 63 | start 64 | ;; 65 | *) 66 | echo "Usage: $0 {start|stop|restart|uninstall}" 67 | echo "Usage: $0 {start|stop|restart|uninstall}" 68 | -------------------------------------------------------------------------------- /node-exporter-init.dservice/node_exporter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | /opt/node-exporter/node_exporter --no-collector.diskstats -------------------------------------------------------------------------------- /node-exporter.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Prometheus Node Exporter Service 3 | After=network.target 4 | 5 | [Service] 6 | User=node_exporter 7 | Group=node_exporter 8 | Type=simple 9 | ExecStart=/usr/local/bin/node_exporter 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /prometheus.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Prometheus 3 | Wants=network-online.target 4 | After=network-online.target 5 | 6 | [Service] 7 | User=prometheus 8 | Group=prometheus 9 | Type=simple 10 | ExecStart=/usr/local/bin/prometheus \ 11 | --config.file /etc/prometheus/prometheus.yml \ 12 | --storage.tsdb.path /var/lib/prometheus/ \ 13 | --web.console.templates=/etc/prometheus/consoles \ 14 | --web.console.libraries=/etc/prometheus/console_libraries 15 | 16 | [Install] 17 | WantedBy=multi-user.target 18 | -------------------------------------------------------------------------------- /prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | external_labels: 4 | monitor: 'prometheus' 5 | 6 | scrape_configs: 7 | - job_name: 'prometheus' 8 | static_configs: 9 | - targets: ['localhost:9090'] 10 | -------------------------------------------------------------------------------- /prometheus_ec2.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | external_labels: 4 | monitor: 'prometheus' 5 | 6 | scrape_configs: 7 | 8 | - job_name: 'node_exporter' 9 | 10 | static_configs: 11 | 12 | - targets: ['18.219.214.162:9100'] 13 | - targets: ['7.4.5.6:9100'] 14 | -------------------------------------------------------------------------------- /prometheus_relabeeling.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | external_labels: 4 | monitor: 'prometheus' 5 | 6 | scrape_configs: 7 | - job_name: 'node' 8 | ec2_sd_configs: 9 | - region: us-east-1 10 | access_key: yourkey 11 | secret_key: yourkey 12 | port: 9100 13 | relabel_configs: 14 | - source_labels: [__meta_ec2_public_ip] 15 | regex: '(.*)' #default value 16 | target_label: _address_ 17 | replacement: '${1}:9100' 18 | # action: keep 19 | # Use the instance ID as the instance label 20 | - source_labels: [__meta_ec2_tag_Name] 21 | target_label: instance 22 | -------------------------------------------------------------------------------- /prometheus_serviceDiscovery.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 15s 3 | external_labels: 4 | monitor: 'prometheus' 5 | 6 | scrape_configs: 7 | - job_name: 'node' 8 | ec2_sd_configs: 9 | - region: us-east-2 10 | access_key: yourkey 11 | secret_key: yourkey 12 | port: 9100 13 | --------------------------------------------------------------------------------