如何将 Grafana 仪表板从一台服务器完全复制到另一台服务器
How to completely copy Grafana dashboard(s) from one server to other server
我在服务器 1 上托管的 Grafana 中有 20 多个仪表板。我们购买了另一台服务器,并在 Server2 机器上安装了相同版本的 Grafana。
我想知道是否可以将 Server-1 Grafana 实例连同所有仪表板完全克隆到 Server2?
目前Grafana只支持仪表板一一导入导出。
我想到的另一种可能性是使用标准 SCP 命令将所有 Grafana files/directories 从 Server-1 复制到 server-2。但是我不确定我需要复制哪些文件。
如果您使用的是 built-in sqlite3 数据库,那么您确实可以将 data
目录和 conf/custom.ini
复制到新服务器,这将包括您所有的仪表板、插件等。在该设置中,数据库包含在您的 grafana 安装下的 data/grafana.db
中。
您可以使用 wizzy 将仪表板从一台服务器复制到另一台服务器。
使用说明安装 wizzy
https://grafana-wizzy.com/home/getting-started/
然后运行以下命令:
设置服务器 1 的配置:
wizzy set grafana envs local1 url http://server1:3000
wizzy set grafana envs local1 username admin
wizzy set grafana envs local1 password admin
设置服务器 2 的配置:
wizzy set grafana envs local2 url http://server2:3000
wizzy set grafana envs local2 username admin
wizzy set grafana envs local2 password admin
从服务器 1 复制到服务器 2:
wizzy set context grafana local1
wizzy import dashboards
wizzy set context grafana local2
wizzy export dashboards
您的仪表板现在应该从服务器 1 复制到服务器 2。如果有任何问题,请在 https://github.com/grafana-wizzy/wizzy/issues
上打开一个 GitHub 问题
这是导出所有仪表板的简单 Perl 脚本。只需更改前两个变量即可。
#!/usr/bin/perl
use strict;
my $Grafana= "www.Agendare.MX:3000";
my $Auth= "API token goes here.";
my @List=`curl -sH "Authorization: Bearer $Auth" 'http://$Grafana/api/search' | jq .[].uid -S`;
mkdir "dashexpo";
foreach my $Uid (@List) {
$Uid=~ s/["\n]//g;
my $Title=`curl -sH "Authorization: Bearer $Auth" 'http://$Grafana/api/dashboards/uid/$Uid' | jq .dashboard.title`;
my @Dashboard=`curl -sH "Authorization: Bearer $Auth" 'http://$Grafana/api/dashboards/uid/$Uid' | jq .dashboard -S --tab`;
$Title=~ s/["\n]//g;
print "Exporting $Uid: $Title\n";
$Title=~ s/ /_/g;
my $File= "dashexpo/$Title\.json";
open(FH, ">$File");
print FH @Dashboard;
close(FH);
}
我在服务器 1 上托管的 Grafana 中有 20 多个仪表板。我们购买了另一台服务器,并在 Server2 机器上安装了相同版本的 Grafana。
我想知道是否可以将 Server-1 Grafana 实例连同所有仪表板完全克隆到 Server2?
目前Grafana只支持仪表板一一导入导出。
我想到的另一种可能性是使用标准 SCP 命令将所有 Grafana files/directories 从 Server-1 复制到 server-2。但是我不确定我需要复制哪些文件。
如果您使用的是 built-in sqlite3 数据库,那么您确实可以将 data
目录和 conf/custom.ini
复制到新服务器,这将包括您所有的仪表板、插件等。在该设置中,数据库包含在您的 grafana 安装下的 data/grafana.db
中。
您可以使用 wizzy 将仪表板从一台服务器复制到另一台服务器。
使用说明安装 wizzy https://grafana-wizzy.com/home/getting-started/
然后运行以下命令:
设置服务器 1 的配置:
wizzy set grafana envs local1 url http://server1:3000
wizzy set grafana envs local1 username admin
wizzy set grafana envs local1 password admin
设置服务器 2 的配置:
wizzy set grafana envs local2 url http://server2:3000
wizzy set grafana envs local2 username admin
wizzy set grafana envs local2 password admin
从服务器 1 复制到服务器 2:
wizzy set context grafana local1
wizzy import dashboards
wizzy set context grafana local2
wizzy export dashboards
您的仪表板现在应该从服务器 1 复制到服务器 2。如果有任何问题,请在 https://github.com/grafana-wizzy/wizzy/issues
上打开一个 GitHub 问题这是导出所有仪表板的简单 Perl 脚本。只需更改前两个变量即可。
#!/usr/bin/perl
use strict;
my $Grafana= "www.Agendare.MX:3000";
my $Auth= "API token goes here.";
my @List=`curl -sH "Authorization: Bearer $Auth" 'http://$Grafana/api/search' | jq .[].uid -S`;
mkdir "dashexpo";
foreach my $Uid (@List) {
$Uid=~ s/["\n]//g;
my $Title=`curl -sH "Authorization: Bearer $Auth" 'http://$Grafana/api/dashboards/uid/$Uid' | jq .dashboard.title`;
my @Dashboard=`curl -sH "Authorization: Bearer $Auth" 'http://$Grafana/api/dashboards/uid/$Uid' | jq .dashboard -S --tab`;
$Title=~ s/["\n]//g;
print "Exporting $Uid: $Title\n";
$Title=~ s/ /_/g;
my $File= "dashexpo/$Title\.json";
open(FH, ">$File");
print FH @Dashboard;
close(FH);
}