grafana prometheus 監(jiān)控

1.grafana安裝

sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.3.4-1.x86_64.rpm?

修改配置

vim /etc/grafana/grafana.ini

? [paths]

# Path to where grafana can store temp files, sessions, and the sqlite3 db (if that is used)

data = /var/lib/grafana

# Directory where grafana can store logs

logs = /var/log/grafana

# Directory where grafana will automatically scan and look for plugins

plugins = /var/lib/grafana/plugins

# The ip address to bind to, empty will bind to all interfaces

http_addr =0.0.0.0

# The http port? to use

http_port = 9300

# If you use reverse proxy and sub path specify full url (with sub path)

root_url = http://127.0.0.1:9300

安裝插件

grafana-cli plugins install grafana-piechart-panel

grafana-cli plugins install grafana-worldmap-panel

重啟配置?

service grafana-server restart

2.prometheus安裝

wget? https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz

tar -zxvf prometheus-2.5.0.linux-amd64.tar.gz

配置prometheus.yml

global:

? scrape_interval:? ? 1s

? evaluation_interval: 1s

scrape_configs:

? - job_name: prometheus

? ? static_configs:

? ? ? - targets: ['127.0.0.1:9301']

? ? ? ? labels:

? ? ? ? ? instance: prometheus

? - job_name: linux

? ? static_configs:

? ? ? - targets: ['127.0.0.1:9100']

? ? ? ? labels:

? ? ? ? ? instance:? Nelab-3-server

? ? ? - targets: ['127.0.0.1:9100']

? ? ? ? labels:

? ? ? ? ? instance: crontab-server

? ? ? - targets: ['127.0.0.1:9100']

? ? ? ? labels:

? ? ? ? ? instance: socket-server

? - job_name: 'mysql'

? ? static_configs:

? ? ? - targets: ['127.0.0.1:9104']

? ? ? ? labels:

? ? ? ? ? instance: Nelab-3-db

? - job_name: redis

? ? static_configs:

? ? ? - targets: ['127.0.0.1:9121']

? ? ? ? labels:

? ? ? ? ? instance: db1

啟動(dòng)

? ./prometheus --config.file=prometheus.yml --web.listen-address=:9301

3.安裝 prometheus_exporters

wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz

wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0-rc.0/node_exporter-0.17.0-rc.0.linux-amd64.tar.gz

wget https://github.com//oliver006/redis_exporter/releases/download/v0.22.0/redis_exporter-v0.22.0.linux-amd64.tar.gz

【mysql】

? vim .my.cnf

? [client]

? host=172.31.26.69

? port=3306

? user=game

? password=CvSMOyYW

? nohup ./mysqld_exporter --config.my-cnf=".my.cnf" &

? 【redis】

? nohup ./redis_exporter --redis.addr? redis://127.0.0.1:6379 --redis.password irbouh92 &

? 【node_exporter】

? nohup ./node_exporter &


? 4.grafana模板

? redis模板

? https://grafana.com/api/dashboards/763/revisions/1/download

? nginx 模板

? https://grafana.com//api/dashboards/2292/revisions/5/download

? mysql MySQL Overview

? https://github.com/percona/grafana-dashboards

? Elasticsearch Nginx Logs

? https://grafana.com//api/dashboards/2292/revisions/5/download

? Node Exporter Server Metrics

? https://grafana.com/api/dashboards/405/revisions/8/download



? 5.nginx日志收集

? 配置NGINX

? ? ? ? ? log_format main? '{"@timestamp":"$time_iso8601",'

? ? ? ? ? ? ? ? ? ? ? ? '"@source":"$server_addr",'

? ? ? ? ? ? ? ? ? ? ? ? '"hostname":"$hostname",'

? ? ? ? ? ? ? ? ? ? ? ? '"ip":"$http_x_forwarded_for",'

? ? ? ? ? ? ? ? ? ? ? ? '"client":"$remote_addr",'

? ? ? ? ? ? ? ? ? ? ? ? '"request_method":"$request_method",'

? ? ? ? ? ? ? ? ? ? ? ? '"scheme":"$scheme",'

? ? ? ? ? ? ? ? ? ? ? ? '"domain":"$server_name",'

? ? ? ? ? ? ? ? ? ? ? ? '"referer":"$http_referer",'

? ? ? ? ? ? ? ? ? ? ? ? '"request":"$request_uri",'

? ? ? ? ? ? ? ? ? ? ? ? '"args":"$args",'

? ? ? ? ? ? ? ? ? ? ? ? '"size":$body_bytes_sent,'

? ? ? ? ? ? ? ? ? ? ? ? '"status": $status,'

? ? ? ? ? ? ? ? ? ? ? ? '"responsetime":$request_time,'

? ? ? ? ? ? ? ? ? ? ? ? '"upstreamtime":"$upstream_response_time",'

? ? ? ? ? ? ? ? ? ? ? ? '"upstreamaddr":"$upstream_addr",'

? ? ? ? ? ? ? ? ? ? ? ? '"http_user_agent":"$http_user_agent",'

? ? ? ? ? ? ? ? ? ? ? ? '"https":"$https"'

? ? ? ? ? ? ? ? ? ? ? ? '}';

? 安裝elasticsearch

? wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.6.11.tar.gz

? 配置elasticsearch.yml


http.port: 9200

network.host: 0.0.0.0

啟動(dòng)

?nohup bin/elasticsearch &


? 安裝logstash

? wget https://artifacts.elastic.co/downloads/logstash/logstash-6.5.0.tar.gz

? 添加配置 nginx_log.conf

input {

? ? file {

? ? ? ? #這里根據(jù)自己日志命名使用正則匹配所有域名訪問日志

? ? ? ? path => [ "/var/log/nginx/*.log" ]

? ? ? ? ignore_older => 0

? ? codec => json

? ? }

}

filter {

? ? mutate {

? ? ? convert => [ "status","integer" ]

? ? ? convert => [ "size","integer" ]

? ? ? convert => [ "upstreatime","float" ]

? ? ? remove_field => "message"

? ? }

? ? geoip {

? ? ? ? source => "ip"

? ? }

}

output {

? ? elasticsearch {

? ? ? ? hosts => "127.0.0.1:9200"

? ? ? ? index => "logstash-nginx-access-%{+YYYY.MM.dd}"

? ? }

#? ? stdout {codec => rubydebug}

}

啟動(dòng)?

./bin/logstash -f config/nginx_log.conf? --path.data=/root/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 主機(jī)數(shù)據(jù)收集 主機(jī)數(shù)據(jù)的采集是集群監(jiān)控的基礎(chǔ);外部模塊收集各個(gè)主機(jī)采集到的數(shù)據(jù)分析就能對整個(gè)集群完成監(jiān)控和告警等功...
    梅_梅閱讀 6,791評論 0 7
  • 前面文章提到一個(gè)React工程中包含很多Component,可以通過向組件中傳遞參數(shù),及props,使得組件更靈活...
    SamDing閱讀 657評論 0 0
  • 今天晚上參加中美喜劇中心每周三的即興戲劇,第二次來,比第一次放開了不少。第一次時(shí)真的好緊張,雖然很投入,但不知道怎...
    佳慧阿閱讀 159評論 0 0
  • 奇跡-妖媽感恩日記打卡1/365: 1. 早上起床,小嘟嘟說要送香香姐姐去幼兒園,在去幼兒園的小區(qū)路上,兩個(gè)小天使...
    行動(dòng)派小金姐閱讀 141評論 0 0

友情鏈接更多精彩內(nèi)容