Blog Details

Linux 作業系統 cutexyz > Blog > 武功秘籍 > 武功秘籍 – Grafana

武功秘籍 – Grafana

# ==== install prometheus ====
# get the latest prometheus from https://github.com/prometheus/prometheus/releases/
cd /tmp
wget https://github.com/prometheus/prometheus/releases/download/v2.44.0/prometheus-2.44.0.linux-amd64.tar.gz  
# 安裝
tar -zxf prometheus-2.44.0.linux-amd64.tar.gz  解壓縮
cd prometheus-2.44.0.linux-amd64/
mv prometheus promtool /usr/local/bin/
mkdir /etc/prometheus
mv ./* /etc/prometheus
nano /etc/systemd/system/prometheus.service

# input these content into the file we just opened  複製貼上
[Unit]
Description=Prometheus
After=network-online.target

[Service]
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/etc/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries

[Install]
WantedBy=multi-user.target




# enable service
sudo systemctl enable --now prometheus

# check the service  到網站輸入網址  (<your_ip>記得改成你的ip)
service prometheus status
http://<your_ip>:9090 

# ==== install grafana 1 ====
sudo apt-get install -y adduser libfontconfig1 musl
wget https://dl.grafana.com/oss/release/grafana_11.0.0_amd64.deb
sudo dpkg -i grafana_11.0.0_amd64.deb
sudo systemctl daemon-reload

# enable service, 啟動
sudo systemctl enable --now grafana-server 

# check the service  到網站輸入網址  (<your_ip>記得改成你的ip)
service grafana-server status
http://<your_ip>:3000
# id/passsord => admin/admin

# ==== Install Node_exporter ====
# find the latest version from https://github.com/prometheus/node_exporter/releases
# download it to /tmp
cd /tmp
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz 安裝

# extract file
tar -zxf node_exporter-1.6.0.linux-amd64.tar.gz   解壓縮

# move dir & files
cd node_exporter-1.6.0.linux-amd64/
mv node_exporter /usr/local/bin

# edit the service config   
nano /etc/systemd/system/node_exporter.service

# put these content to the file we just opened  複製貼上
[Unit]
Description=Node Exporter
After=network-online.target

[Service]
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=multi-user.target






# enable service
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter

#check the service
service node_exporter status

# ==== adjust config ====
nano /etc/prometheus/prometheus.yml  
# add these tree lines to the end of the file 複製貼上
  - job_name: "node_exporter"
    static_configs:
      - targets: ["localhost:9100"]

# it should like this  複製貼上後長這樣
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "node_exporter"
    static_configs:
      - targets: ["localhost:9100"]





# restart the service
service prometheus restart

# go to the control panel of prometheus  到網站輸入網址 (<your_ip>記得改成你的ip)
http://<your_ip>:9090

# point to the top menu bar and click Status => Targets,
# you should be able to see two Endpoints
# node_exporter (1/1 up)
# and
# prometheus (1/1 up)

# go to grafana-server control panel
# http://<your-ip>:3000/login   到網站輸入的的ip跟網址
# click data sources then prometheus then go to the bottom and click "Save & test"
# go back to the frontpage of grafana
# click Dashboards and system redirect you to create new dashboard
# click Dashboards on the top-left corner
# click the New button on the right and pull down the menu then click "import"
# in the "Import via grafana.com" input box, input 11074
# after that, in the "VictoriaMetrics" parts, choose prometheus in the pull down menu and click import button in the bottom.



Leave A Comment

All fields marked with an asterisk (*) are required