Prometheus + Host + Jenkines + Nexus Maven + Grafana + MicroService Metrics.

监控安装

Prometheus 安装

1.docker-compose.yml

 1version: "3"
 2
 3services:
 4  prometheus:
 5    image: prom/prometheus
 6    container_name: prometheus
 7    restart: unless-stopped
 8    ports:
 9      - "9090:9090"
10    volumes:
11      - ./prometheus.yml:/etc/prometheus/prometheus.yml
12      # 物理机上需要 chmod +w 写权限
13      - ./prometheus-data:/prometheus:rw
14
15  grafana:
16    image: grafana/grafana-oss
17    container_name: grafana
18    restart: unless-stopped
19    ports:
20      - "3000:3000"
21    depends_on:
22      - prometheus
23    environment:
24      - GF_SECURITY_ADMIN_USER=admin
25      - GF_SECURITY_ADMIN_PASSWORD=123456
26    volumes:
27      - ./grafana:/etc/grafana/provisioning/datasources

2.prometheus.yml

 1global:
 2  scrape_interval:     15s # 默认情况下,每 15s 采集一次目标数据
 3  evaluation_interval: 15s # 每 15s 进行一次规则评估
 4
 5  # 与外部系统通信时,可以将这些标签应用到到和时间序列或告警上
 6  external_labels:
 7    monitor: 'codelab-monitor'
 8
 9rule_files:
10  - 'prometheus.rules.yml'
11
12scrape_configs:
13  - job_name: 'prometheus'
14
15    # Override the global default and scrape targets from this job every 5 seconds.
16    scrape_interval: 5s
17
18    static_configs:
19      - targets: ['localhost:9090']
20
21  # https://my.oschina.net/klblog/blog/5540728
22  - job_name: 'nexus'
23    # Override the global default and scrape targets from this job every 5 seconds.
24    scrape_interval: 5s
25    # scrape_timeout: 10s
26    metrics_path: /service/metrics/prometheus
27    scheme: http
28    static_configs:
29      - targets: ["localhost:8081"]
30
31  - job_name: 'jenkins'
32    metrics_path: '/prometheus/'
33    scheme: http
34    bearer_token: bearer_token
35    static_configs:
36      - targets: ['localhost:8080']
37        labels:
38          group: 'jenkins'
39
40  - job_name:       'host'
41    # 覆盖全局默认的参数,并将采样时间间隔设置为 5s
42    scrape_interval: 5s
43
44    static_configs:
45      - targets: ['localhost:9091']
46        labels:
47          group: 'release'
48      - targets: ['localhost:9091']
49        labels:
50          group: 'develop'

3.grafana.yml

grafana/datasource.yml

1apiVersion: 1
2
3datasources:
4- name: Prometheus
5  type: prometheus
6  url: http://prometheus:9090
7  isDefault: true
8  access: proxy
9  editable: true

Host node_exporter

1.下载node_exporter

传送门

2.安装

端口为: 9091

 1#!/bin/bash
 2
 3cat > /lib/systemd/system/node_exporter.service <<EOF
 4[Unit]
 5Description=node_exporter service
 6
 7[Service]
 8User=root
 9ExecStart=/usr/local/bin/node_exporter --web.listen-address=:9091
10
11TimeoutStopSec=10
12Restart=on-failure
13RestartSec=5
14
15[Install]
16WantedBy=multi-user.target
17EOF
18
19sudo systemctl daemon-reload
20sudo systemctl start node_exporter.service
21sudo systemctl enable node_exporter.service

3.验证

1curl -iv http://127.0.0.1:9091/metrics

Nexus Maven

1.增加Role

1role id: nx-metrics
2role name: nx-metrics 
3role description: nx-metrics
4
5Privileges:
6   filter: nx-metrics-all  & add

保存

2.使用role

Security –> Users

选择 anonymous

1Status: Active
2Roles:
3  Granted:
4    nx-anonymous
5    nx-metrics

保存

3.验证

1curl -iv http://127.0.0.1:8081/service/metrics/prometheus

Jenkines

1.安装 Prometheus 插件

2.验证

1curl -iv http://127.0.0.1:8080/prometheus/