【Docker】 Grafana Create Custom Plugin 01

235 阅读3分钟

1. Github

How to carea custom pulgin: github.com/grafana/plu…

图片.png

2. Create Plugin

2.1 Troubleshooting

图片.png

图片.png

2.2 Docker Install Grafana

  • 拉鏡像

    docker pull grafana/grafana

  • 建容器

    docker run --privileged=true -u=root -d -p 3000:3000 -v "$(pwd)"/grafana-plugins:/var/lib/grafana/plugins --name MyGrafana grafana/grafana

    docker run --privileged=true -u=root -d -p 3000:3000 --name MyGrafana grafana/grafana

最後就是這個容器裡面什麼都要安裝,yum ,apt 等等什麼都沒有,麻煩

2.3 Docker phusion/baseimage

github.com/phusion/bas…

图片.png

2.3.1 Install image

  • 拉鏡像

    docker pull phusion/baseimage 舊版跑不起來了

    docker pull phusion/baseimage:bionic-1.0.0

  • 建容器 ,給管理員權限,留下3000給grafana

    docker run --privileged=true -u=root -d -p 3000:3000 --name MyUbuntu phusion/baseimage:bionic-1.0.0

  • 升級包管理工具

    apt update

    apt-get update

    apt-get install yum 安裝

    apt-get install nodejs/apt-get upgrade nodejs 升級

    apt-get install npm/apt-get upgrade npm

    apt-get remove package_name 卸載

2.3.2 Install grafana

  • 下载二进制包

    wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.7.linux-amd64.tar.gz

  • 解压文件

    tar -zxvf grafana-enterprise-9.4.7.linux-amd64.tar.gz

  • 移动改名

    mv grafana-9.4.7 /usr/local/grafana

  • 添加啟動服務

    Redhat/Centos:vim /usr/lib/systemd/system/grafana-server.service

    Ubuntu:vim /etc/systemd/system/grafana-server.service

  • 启动命令

    systemctl enable grafana-server.service

    systemctl start grafana-server.service

    systemctl restart grafana-server.service

    systemctl status grafana-server.service

    systemctl stop grafana-server.service

grafana-server.service

[Unit]  
Description=Grafana  
After=network.target  
  
[Service]  
Type=simple  
ExecStart=/usr/local/grafana/bin/grafana-server  
Restart=always    
  
[Install]  
WantedBy=multi-user.target

2.3.3 Install grafana plugin

  • 下载npx

    npm install -g npx

    npx -v

  • 卸載

    npm uninstall xxxx -g

    npm cache clean -f

  • 加載插件,cd進入install

    npx @grafana/create-plugin@latest

    npm install

    npm run dev

图片.png

把路走死了。。。。。。

图片.png

2.4 Other Docker Image

2.4.1 Install Image and other tools

  • Centos(OK)

    docker pull centos:7

    docker run --privileged=true -u=root -d -p 3000:3000 --name MyCentos centos:7 /usr/sbin/init

  • Redhat,要登錄docker(NG)

    docker pull redhat/rhel7:latest

    docker run --privileged=true -u=root -d -p 3000:3000 --name MyRedhat redhat/rhel7:latest /usr/sbin/init

  • 下載wegt,安裝yum源(阿里)

    yum -y install wget

    wget http://mirrors.aliyun.com/repo/Centos-7.repo

  • 下載epel.repo,安裝nodejs

    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

    yum install nodejs

    node -v

  • 安裝npm,npx

    yum install npm

    npm install npx

    npm -v / npx -v

2.4.2 Install grafana

  • 下载二进制包

    wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.7.linux-amd64.tar.gz

  • 解压文件

    tar -zxvf grafana-enterprise-9.4.7.linux-amd64.tar.gz

  • 移动改名

    mv grafana-9.4.7 /usr/local/grafana

  • 添加啟動服務

    vim /usr/lib/systemd/system/grafana-server.service

  • 启动命令

    systemctl enable grafana-server.service

    systemctl start grafana-server.service

    systemctl restart grafana-server.service

    systemctl status grafana-server.service

    systemctl stop grafana-server.service

  • 密碼

    admin@123

grafana-server.service

[Unit]
Description=Grafana
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/grafana/bin/grafana-server -homepath /usr/local/grafana
Restart=on-failure

[Install]
WantedBy=multi-user.target

2.5 Custom Plugin

2.5.1 Register Grafana cloud

grafana.com/auth/sign-i…

Tomcat@123

2.5.2 Plugin

  • 加載插件,cd進入install

    參考官網:grafana.com/developers/…

    npx @grafana/create-plugin@latest

  • 進入目錄cd

    npm install

    npm run dev

图片.png

2.5.3 Portainer

  • 創建Volume

    docker volume create portainer_data

    docker volume ls

  • 拉Portainer鏡像

    docker pull portainer/portainer

    docker run -d -p 9000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data --name MyPortainer portainer/portainer

  • 登錄,設密碼

    http://localhost:9000

    admin@12345678

2.5.4 Grafana Config

进入conf目录复制一份sample.ini并重命名为custom.ini。以后所有的配置应该编辑custom.ini,永远不要去修改defaults.ini

  • Copy ini

    cp sample.ini custom.ini

  • Config grafana

    yum install vim

    APP_MODE默認为 production,如果想要强制加载unsigned插件,可以向 custom.ini 中添加 GF_DEFAULT_APP_MODE=development

图片.png

图片.png

  • 重啟服務,不出意外,還是不行

    systemctl restart grafana-server.service

图片.png

  • 直接改配置,就能加載了

    app_mode = development

    systemctl restart grafana-server.service

2.5.5 Sign a plugin

grafana.com/developers/…

图片.png

grafana.com/docs/grafan…

图片.png

图片.png

  • 如果docker中還不行,編輯ini文件,添加如下兩項

    etc/grafana/grafana.ini

    GF_SERVER_HTTP_PORT=80

    GF_SERVER_HTTP_PORT=3000

  • 命令行生成注册文件时使用 

    yarn sign --rootUrls http://localhost:3000,http://localhost:80,http://localhost

2.6 React

  • docker cp folder

    docker cp mycontainer:/file.txt C:\path\to\destination\file.txt

3. RPM package

如果有些軟件要離線安裝,可以現在鏡像裡面的包,如果有yum,apt可忽略

mirrors.163.com/centos/7/os…