将PostgreSQL数据源添加到Grafana,插件运行状况检查失败

hwamh0ep  于 2023-05-28  发布在  PostgreSQL
关注(0)|答案(1)|浏览(295)

我使用grafana docker容器和Postgresql docker容器。我想我设法向Grafana添加了一个数据源,但是,插件健康检查失败,如下图所示。此外,当我尝试查询时,我得到一个连接错误...
[![此处为书签栏切换器。][1]][1]
我已经检查过了,我在sql db中创建的用户是一个超级用户,所以它有查询表的权限。在我的python脚本中,我使用grafana http API来添加数据源。

datasource = {
            "name": "postgres",
            "type": "postgres",
            "host": f"http://{database.config.host}",
            "database": database.config.database,
            "user": database.config.user,
            "password": database.config.password,
            "access": "proxy",
            "port": database.config.port,
            "sslmode": "disable",
        }
        headers = {
            "Content-Type": "application/json",
            "Authorization": f"Bearer {self.api_key}",
        }
        response = requests.post(
            self.grafana_url + self.API_DATASOURCES,
            json=datasource,
            headers=headers,
            timeout=2,
        )

我的日志,状态:

logger=context t=2023-05-24T23:47:11.909546523Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:11.909856964Z level=warn msg=Unauthorized error="user token not found" remote_addr=192.168.16.1 traceID=
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:11.909908982Z level=info msg="Request Completed" method=GET path=/api/live/ws status=401 remote_addr=192.168.16.1 time_ms=0 duration=790.303µs size=40 referer= handler=/api/live/ws
logger=context t=2023-05-24T23:47:24.906185083Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:24.906382401Z level=warn msg=Unauthorized error="user token not found" remote_addr=192.168.16.1 traceID=
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:24.906419291Z level=info msg="Request Completed" method=GET path=/api/live/ws status=401 remote_addr=192.168.16.1 time_ms=0 duration=416.706µs size=40 referer= handler=/api/live/ws
logger=context t=2023-05-24T23:47:26.901251349Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:26.901763659Z level=warn msg=Unauthorized error="user token not found" remote_addr=192.168.16.1 traceID=
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:26.901862131Z level=info msg="Request Completed" method=GET path=/api/live/ws status=401 remote_addr=192.168.16.1 time_ms=1 duration=1.014872ms size=40 referer= handler=/api/live/ws
logger=context t=2023-05-24T23:47:33.749570154Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:33.749850255Z level=info msg="Request Completed" method=GET path=/connections/your-connections/datasources/edit/edec663f-a7cc-4316-9aa1-d672dee7d717 status=302 remote_addr=192.168.16.1 time_ms=0 duration=523.514µs size=29 referer=http://localhost:3000/login handler=/connections/your-connections/datasources/edit/*
logger=context t=2023-05-24T23:47:33.751853587Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=context t=2023-05-24T23:47:36.899061961Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:36.899246767Z level=warn msg=Unauthorized error="user token not found" remote_addr=192.168.16.1 traceID=
logger=context userId=0 orgId=0 uname= t=2023-05-24T23:47:36.899285702Z level=info msg="Request Completed" method=GET path=/api/live/ws status=401 remote_addr=192.168.16.1 time_ms=0 duration=439.616µs size=40 referer= handler=/api/live/ws
logger=context t=2023-05-24T23:47:42.741638708Z level=warn msg="failed to look up session from cookie" error="user token not found"
logger=http.server t=2023-05-24T23:47:42.75135848Z level=info msg="Successful Login" User=admin@localhost
logger=context userId=1 orgId=1 uname=newuser t=2023-05-24T23:47:42.894368364Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=192.168.16.1 time_ms=0 duration=841.72µs size=0 referer= handler=/api/live/ws
logger=context userId=1 orgId=1 uname=newuser t=2023-05-24T23:47:42.912548509Z level=info msg="Request Completed" method=GET path=/api/datasources/uid/edec663f-a7cc-4316-9aa1-d672dee7d717 status=404 remote_addr=192.168.16.1 time_ms=0 duration=461.639µs size=35 referer=http://localhost:3000/connections/your-connections/datasources/edit/edec663f-a7cc-4316-9aa1-d672dee7d717 handler=/api/datasources/uid/:uid
logger=context userId=1 orgId=1 uname=newuser t=2023-05-24T23:47:42.946075661Z level=info msg="Request Completed" method=GET path=/api/datasources/edec663f-a7cc-4316-9aa1-d672dee7d717 status=400 remote_addr=192.168.16.1 time_ms=0 duration=341.626µs size=27 referer=http://localhost:3000/connections/your-connections/datasources/edit/edec663f-a7cc-4316-9aa1-d672dee7d717 handler=/api/datasources/:id
logger=context userId=1 orgId=1 uname=newuser t=2023-05-24T23:47:56.90833634Z level=info msg="Request Completed" method=GET path=/api/live/ws status=-1 remote_addr=192.168.16.1 time_ms=1 duration=1.658ms size=0 referer= handler=/api/live/ws
logger=context userId=1 orgId=1 uname=newuser t=2023-05-24T23:48:00.997970403Z level=error msg="Plugin health check failed" error="failed to check plugin health: health check failed" remote_addr=192.168.16.1 traceID=
logger=context userId=1 orgId=1 uname=newuser t=2023-05-24T23:48:00.998018152Z level=error msg="Request Completed" method=GET path=/api/datasources/uid/fb4800be-7c42-40fb-be33-f3e0d87ebaab/health status=500 remote_addr=192.168.16.1 time_ms=0 duration=623.119µs size=53 referer=http://localhost:3000/connections/your-connections/datasources/edit/fb4800be-7c42-40fb-be33-f3e0d87ebaab handler=/api/datasources/uid/:uid/health
4nkexdtk

4nkexdtk1#

为了将来的参考,http payload:

{"name": "PostgreSQLPython", "type": "postgres", "url": "local_postgres:5432", "user": "postgres_user_fake", "database": "postgres_db_name_fake", "basicAuth": false, "access": "proxy", "withCredentials": false, "isDefault": true, "jsonData": {"tlsAuth": false, "connMaxLifetime": 14400, "database": "postgres_db_name_fake", "maxIdleConns": 100, "maxIdleConnsAuto": true, "maxOpenConns": 100, "sslmode": "disable", "postgresVersion": 1500}, "secureJsonData": {"password": "postgres_password_fake"}}

请注意,URL没有http://...在一些论坛上他们推荐了它,但似乎对于Grafana 9.3及以上版本不再需要它。
headers ={'Accept':'application/json',"Content-Type":"application/json","Authorization":f "承载{self. api_key}",}
还有...
对于Docker容器,我们需要使用别名。感谢上面的评论。

然后我们到达极乐世界

相关问题