Add new endpoint /activity that returns active queries
This commit is contained in:
parent
fa8f3a2997
commit
38ecb5ffc4
11
api.go
11
api.go
@ -54,6 +54,7 @@ func setupRoutes(router *gin.Engine) {
|
||||
api.POST("/connect", API_Connect)
|
||||
api.GET("/databases", API_GetDatabases)
|
||||
api.GET("/connection", API_ConnectionInfo)
|
||||
api.GET("/activity", API_Activity)
|
||||
api.GET("/tables", API_GetTables)
|
||||
api.GET("/tables/:table", API_GetTable)
|
||||
api.GET("/tables/:table/rows", API_GetTableRows)
|
||||
@ -272,6 +273,16 @@ func API_ConnectionInfo(c *gin.Context) {
|
||||
c.JSON(200, res.Format()[0])
|
||||
}
|
||||
|
||||
func API_Activity(c *gin.Context) {
|
||||
res, err := dbClient.Activity()
|
||||
if err != nil {
|
||||
c.JSON(400, NewError(err))
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, res)
|
||||
}
|
||||
|
||||
func API_TableIndexes(c *gin.Context) {
|
||||
res, err := dbClient.TableIndexes(c.Params.ByName("table"))
|
||||
|
||||
|
@ -127,6 +127,11 @@ func (client *Client) TableIndexes(table string) (*Result, error) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Returns all active queriers on the server
|
||||
func (client *Client) Activity() (*Result, error) {
|
||||
return client.Query(PG_ACTIVITY)
|
||||
}
|
||||
|
||||
func (client *Client) Query(query string) (*Result, error) {
|
||||
res, err := client.query(query)
|
||||
|
||||
|
@ -28,4 +28,18 @@ FROM information_schema.columns
|
||||
WHERE table_name = $1`
|
||||
|
||||
PG_TABLES = `SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_schema,table_name`
|
||||
|
||||
PG_ACTIVITY = `SELECT
|
||||
datname,
|
||||
query,
|
||||
state,
|
||||
waiting,
|
||||
query_start,
|
||||
state_change,
|
||||
pid,
|
||||
datid,
|
||||
application_name,
|
||||
client_addr
|
||||
FROM pg_stat_activity
|
||||
WHERE state IS NOT NULL`
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user