diff --git a/api.go b/api.go index 17a257c..142a7e5 100644 --- a/api.go +++ b/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")) diff --git a/client.go b/client.go index dea1871..bdc1ed5 100644 --- a/client.go +++ b/client.go @@ -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) diff --git a/statements.go b/statements.go index f73d5a1..f4ef943 100644 --- a/statements.go +++ b/statements.go @@ -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` )