Prometheus推荐 – 引入exporter节点导出器(二进制文件)

在这篇文章中,我们将介绍Prometheus,并包括错误处理指南,适合那些不熟悉Prometheus的人。因此,由于包含不同的信息,可能会显得有些繁琐,请您谅解。

普罗米修斯的建议 – 安装导出器node-exporter(apt-get) – 续


我之前用apt-get安装node-exporter时不能使用uname的收集器,所以这次我尝试用二进制文件安装,并用Ansible来修改启动选项。

我想监视的项目 (Wǒ de

自上次从中提取部分

    • リソース監視

CPUリソース
メモリリソース
ディスクリソース
ロードアベレージ

プロセス監視

nginx
MySQL
php-fpm
uwsgi
※ というか必要なプロセス

各MW系のステータス
ログ監視

创建Ansible的yml文件

这里是参考的地方。虽然已经多次提到了,但因为它是离我想做的事情最近的,所以无可避免。
新兴的基础设施服务监控工具“Prometheus”入门。

在撰写 YAML 文件之前,让我们先讨论启动选项。

这次和上次一样,我想说能不能行,但是为了确认,所以手动解压并查看了命令帮助,结果完全不一样。。。
真是什么鬼东西啊。。。如果想要除了默认设置之外的其他设置,就必须明确地进行启用/禁用吗。。。
经过一番搜索,似乎在这里有人正在讨论。。。

我看完了,结论似乎是要全部都是个别的。
哎呀,连基本认证也消失了!

启动选项

Flags:
  -h, --help                    Show context-sensitive help (also try --help-long and --help-man).
      --collector.diskstats.ignored-devices="^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$"
                                Regexp of devices to ignore for diskstats.
      --collector.filesystem.ignored-mount-points="^/(dev|proc|sys|var/lib/docker)($|/)"
                                Regexp of mount points to ignore for filesystem collector.
      --collector.filesystem.ignored-fs-types="^(autofs|binfmt_misc|cgroup|configfs|debugfs|devpts|devtmpfs|fusectl|hugetlbfs|mqueue|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|sysfs|tracefs)$"
                                Regexp of filesystem types to ignore for filesystem collector.
      --collector.netdev.ignored-devices="^$"
                                Regexp of net devices to ignore for netdev collector.
      --collector.netstat.fields="^(.*_(InErrors|InErrs)|Ip_Forwarding|Ip(6|Ext)_(InOctets|OutOctets)|Icmp6?_(InMsgs|OutMsgs)|TcpExt_(Listen.*|Syncookies.*)|Tcp_(ActiveOpens|PassiveOpens|RetransSegs|CurrEstab)|Udp6?_(InDatagrams|OutDatagrams|NoPorts))$"
                                Regexp of fields to return for netstat collector.
      --collector.ntp.server="127.0.0.1"
                                NTP server to use for ntp collector
      --collector.ntp.protocol-version=4
                                NTP protocol version
      --collector.ntp.server-is-local
                                Certify that collector.ntp.server address is the same local host as this collector.
      --collector.ntp.ip-ttl=1  IP TTL to use while sending NTP query
      --collector.ntp.max-distance=3.46608s
                                Max accumulated distance to the root
      --collector.ntp.local-offset-tolerance=1ms
                                Offset between local clock and local ntpd time to tolerate
      --path.procfs="/proc"     procfs mountpoint.
      --path.sysfs="/sys"       sysfs mountpoint.
      --collector.qdisc.fixtures=""
                                test fixtures to use for qdisc collector end-to-end testing
      --collector.runit.servicedir="/etc/service"
                                Path to runit service directory.
      --collector.supervisord.url="http://localhost:9001/RPC2"
                                XML RPC endpoint.
      --collector.systemd.unit-whitelist=".+"
                                Regexp of systemd units to whitelist. Units must both match whitelist and not match blacklist to be included.
      --collector.systemd.unit-blacklist=".+\\.scope"
                                Regexp of systemd units to blacklist. Units must both match whitelist and not match blacklist to be included.
      --collector.systemd.private
                                Establish a private, direct connection to systemd without dbus.
      --collector.textfile.directory=""
                                Directory to read text files with metrics from.
      --collector.vmstat.fields="^(oom_kill|pgpg|pswp|pg.*fault).*"
                                Regexp of fields to return for vmstat collector.
      --collector.wifi.fixtures=""
                                test fixtures to use for wifi collector metrics
      --collector.arp           Enable the arp collector (default: enabled).
      --collector.bcache        Enable the bcache collector (default: enabled).
      --collector.bonding       Enable the bonding collector (default: enabled).
      --collector.buddyinfo     Enable the buddyinfo collector (default: disabled).
      --collector.conntrack     Enable the conntrack collector (default: enabled).
      --collector.cpu           Enable the cpu collector (default: enabled).
      --collector.diskstats     Enable the diskstats collector (default: enabled).
      --collector.drbd          Enable the drbd collector (default: disabled).
      --collector.edac          Enable the edac collector (default: enabled).
      --collector.entropy       Enable the entropy collector (default: enabled).
      --collector.filefd        Enable the filefd collector (default: enabled).
      --collector.filesystem    Enable the filesystem collector (default: enabled).
      --collector.hwmon         Enable the hwmon collector (default: enabled).
      --collector.infiniband    Enable the infiniband collector (default: enabled).
      --collector.interrupts    Enable the interrupts collector (default: disabled).
      --collector.ipvs          Enable the ipvs collector (default: enabled).
      --collector.ksmd          Enable the ksmd collector (default: disabled).
      --collector.loadavg       Enable the loadavg collector (default: enabled).
      --collector.logind        Enable the logind collector (default: disabled).
      --collector.mdadm         Enable the mdadm collector (default: enabled).
      --collector.meminfo       Enable the meminfo collector (default: enabled).
      --collector.meminfo_numa  Enable the meminfo_numa collector (default: disabled).
      --collector.mountstats    Enable the mountstats collector (default: disabled).
      --collector.netdev        Enable the netdev collector (default: enabled).
      --collector.netstat       Enable the netstat collector (default: enabled).
      --collector.nfs           Enable the nfs collector (default: enabled).
      --collector.nfsd          Enable the nfsd collector (default: enabled).
      --collector.ntp           Enable the ntp collector (default: disabled).
      --collector.qdisc         Enable the qdisc collector (default: disabled).
      --collector.runit         Enable the runit collector (default: disabled).
      --collector.sockstat      Enable the sockstat collector (default: enabled).
      --collector.stat          Enable the stat collector (default: enabled).
      --collector.supervisord   Enable the supervisord collector (default: disabled).
      --collector.systemd       Enable the systemd collector (default: disabled).
      --collector.tcpstat       Enable the tcpstat collector (default: disabled).
      --collector.textfile      Enable the textfile collector (default: enabled).
      --collector.time          Enable the time collector (default: enabled).
      --collector.uname         Enable the uname collector (default: enabled).
      --collector.vmstat        Enable the vmstat collector (default: enabled).
      --collector.wifi          Enable the wifi collector (default: enabled).
      --collector.xfs           Enable the xfs collector (default: enabled).
      --collector.zfs           Enable the zfs collector (default: enabled).
      --collector.timex         Enable the timex collector (default: enabled).
      --web.listen-address=":9100"
                                Address on which to expose metrics and web interface.
      --web.telemetry-path="/metrics"
                                Path under which to expose metrics.
      --log.level="info"        Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]
      --log.format="logger:stderr"
                                Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"
      --version                 Show application version

所以,创建一个yml文件。

顺便提一下,我正在使用最新的版本,但无法确定当上一个版本发布时链接会不会失效。

---
- hosts: samplehost
  user: sampleuser
  sudo: yes
  tasks:
  - name: check exist file
    stat:
      path: /usr/bin/node_exporter
    register: file
  - name: wget node-expoter
      url: https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
      dest: /tmp/node_exporter-0.16.0.linux-amd64.tar.gz
  - name: unarchive node-exporter
    unarchive:
      src: /tmp/node_exporter-0.16.0.linux-amd64.tar.gz
      remote_src: yes
      dest: /tmp/
  - name: copy node-exporter binary
    shell: cp /tmp/node_exporter-0.16.0.linux-amd64/node_exporter /usr/bin/node_exporter
    when: not file.stat.exists

  - name: add system account prometheus
    user:
      system: yes
      name: prometheus
      state: present
      home: /var/lib/prometheus
      shell: /bin/false
      comment: Prometheus daemon
  - name: create prometheus home directory
    file:
      state: directory
      path: /var/lib/prometheus
      mode: 0755
      group: prometheus
      owner: prometheus
  - name: create node_exporter systemd
    blockinfile:
      path: /etc/systemd/system/node_exporter.service
      create: yes
      block: |
        [Unit]
        Description=node_exporter for Prometheus

        [Service]
        Restart=always
        User=prometheus
        ExecStart=/usr/bin/node_exporter \
            --web.listen-address=0.0.0.0:9100 \
            --collector.diskstats.ignored-devices="^(dm-|ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$" \
            --collector.filesystem.ignored-mount-points="^/(dev|proc|sys|run|var/lib/(docker|lxcfs|nobody_tmp_secure))($|/)" \
            --collector.netdev.ignored-devices="^(lo|docker[0-9]|veth.+)$" \
            --no-collector.conntrack \
            --collector.cpu \
            --collector.diskstats \
            --no-collector.filefd \
            --collector.filesystem \
            --collector.loadavg \
            --collector.meminfo \
            --collector.netdev \
            --collector.netstat \
            --no-collector.ntp \
            --no-collector.sockstat \
            --collector.stat \
            --no-collector.textfile \
            --no-collector.time \
            --collector.uname \
            --collector.vmstat \
            --no-collector.arp \
            --no-collector.bcache \
            --no-collector.bonding \
            --no-collector.buddyinfo \
            --no-collector.drbd \
            --no-collector.edac \
            --no-collector.entropy \
            --no-collector.hwmon \
            --no-collector.infiniband \
            --no-collector.interrupts \
            --no-collector.ipvs \
            --no-collector.ksmd \
            --no-collector.logind \
            --no-collector.mdadm \
            --no-collector.meminfo_numa \
            --no-collector.mountstats \
            --no-collector.nfs \
            --no-collector.nfsd \
            --no-collector.qdisc \
            --no-collector.runit \
            --no-collector.supervisord \
            --no-collector.systemd \
            --no-collector.tcpstat \
            --no-collector.timex \
            --no-collector.wifi \
            --no-collector.xfs \
            --no-collector.zfs
        ExecReload=/bin/kill -HUP $MAINPID
        TimeoutStopSec=20s
        SendSIGKILL=no

        [Install]
        WantedBy=multi-user.target
  - name: add node_exporter systemd
    systemd:
      name: node_exporter.service
      enabled: yes
      state: started

暂时就这样还可以吧?

广告
将在 10 秒后关闭
bannerAds