因为业务需要将grafana的仪表盘内嵌至其他网页中,本文记录详细修改过程。
首先安装grafana,笔者实际使用系统为Centos系统,因此从官方网站https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1
从该网页中可以看到如下命令行,可以直接安装
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.3.0-1.x86_64.rpm sudo yum install grafana-enterprise-9.3.0-1.x86_64.rpm
之后可以通过如下命令设置为开机启动:
systemctl daemon-reload & systemctl start grafana-server && systemctl enable grafana-server
然后ps aux|grep grafana 可以看到grafana server已经启动,并且配置文件位置为/etc/grafana/grafana.ini,具体修改内容如下:
allow_embedding = true
另外其他修改如下:
[auth.anonymous]
# enable anonymous access
enabled = true
#false
# specify organization name that should be used for unauthenticated users
org_name = Main Org.
# specify role for unauthenticated users
org_role = Editor
#Viewer
然后重启granafa就应该生效了,编写html网页代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script type="text/javascript">
$(document).ready(function(){
var iframe = document.getElementById("grafanaIframe");
if(iframe.attachEvent){
iframe.attachEvent("onload", function(){
document.querySelector('sideMenu').style.display='none';
})
} else {
iframe.onload = function(){
document.querySelector('sideMenu').style.display='none';
}
}
});
</script>
<title>Document</title>
</head>
<body>
<iframe id="grafanaIframe" src="http://aaa.bbb.ccc.ddd:3000/d/aka/casearth?orgId=1&theme=dark&kiosk" scrolling="no" frameborder="0" style="width: 100%; height: 1000px;" >
</iframe>
</body>
</html>
其中aaa.bbb.ccc.ddd换为grafana所在主机的IP地址即可,实际效果如下: