use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.
the class AdminAPI method getAdminPostgresLoad.
@Validate
@Override
public void getAdminPostgresLoad(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
PostgresClient.getInstance(vertxContext.owner()).select("SELECT pg_stat_reset()", reply -> {
if (reply.succeeded()) {
/* wait 10 seconds for stats to gather and then query stats table for info */
vertxContext.owner().setTimer(10000, new Handler<Long>() {
@Override
public void handle(Long timerID) {
PostgresClient.getInstance(vertxContext.owner(), "public").select("SELECT numbackends as CONNECTIONS, xact_commit as TX_COMM, xact_rollback as " + "TX_RLBCK, blks_read + blks_hit as READ_TOTAL, " + "blks_hit * 100 / (blks_read + blks_hit) " + "as BUFFER_HIT_PERCENT FROM pg_stat_database WHERE datname = '" + dbname + "'", reply2 -> {
if (reply2.succeeded()) {
OutStream stream = new OutStream();
stream.setData(reply2.result().getRows());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresLoadResponse.withJsonOK(stream)));
} else {
log.error(reply2.cause().getMessage(), reply2.cause());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminPostgresLoadResponse.withPlainInternalServerError(reply2.cause().getMessage())));
}
});
}
});
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
}
});
}
use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.
the class AdminAPI method getAdminDbCacheSummary.
@Override
public void getAdminDbCacheSummary(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
PostgresClient.getInstance(vertxContext.owner()).select("CREATE EXTENSION IF NOT EXISTS \"pg_buffercache\"", reply1 -> {
if (reply1.succeeded()) {
PostgresClient.getInstance(vertxContext.owner()).select("SELECT c.relname, pg_size_pretty(count(*) * 8192) as buffered, round(100.0 * count(*) / " + "(SELECT setting FROM pg_settings WHERE name='shared_buffers')::integer,1) AS buffers_percent," + "round(100.0 * count(*) * 8192 / pg_relation_size(c.oid),1) AS percent_of_relation FROM pg_class c " + "INNER JOIN pg_buffercache b ON b.relfilenode = c.relfilenode INNER JOIN pg_database d " + "ON (b.reldatabase = d.oid AND d.datname = current_database()) GROUP BY c.oid,c.relname " + "ORDER BY 3 DESC LIMIT 20;", reply2 -> {
if (reply2.succeeded()) {
OutStream stream = new OutStream();
stream.setData(reply2.result().getRows());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminDbCacheSummaryResponse.withJsonOK(stream)));
} else {
log.error(reply2.cause().getMessage(), reply2.cause());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply2.cause().getMessage()));
}
});
} else {
log.error(reply1.cause().getMessage(), reply1.cause());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply1.cause().getMessage()));
}
});
}
use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.
the class AdminAPI method getAdminSlowQueries.
@Validate
@Override
public void getAdminSlowQueries(int querytimerunning, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
/**
* the queries returned are of this backend's most recent query. If state is active this field shows the currently
* executing query. In all other states, it shows the last query that was executed.
*/
PostgresClient.getInstance(vertxContext.owner()).select("SELECT EXTRACT(EPOCH FROM now() - query_start) as runtime, client_addr, usename, datname, state, query " + "FROM pg_stat_activity " + "WHERE now() - query_start > '" + querytimerunning + " seconds'::interval " + "ORDER BY runtime DESC;", reply -> {
if (reply.succeeded()) {
OutStream stream = new OutStream();
stream.setData(reply.result().getRows());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminSlowQueriesResponse.withJsonOK(stream)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
}
});
}
use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.
the class AdminAPI method getAdminHealth.
@Override
public void getAdminHealth(Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
OutStream stream = new OutStream();
stream.setData("OK");
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminHealthResponse.withAnyOK(stream)));
}
use of org.folio.rest.tools.utils.OutStream in project raml-module-builder by folio-org.
the class AdminAPI method getAdminListLockingQueries.
@Validate
@Override
public void getAdminListLockingQueries(String dbname, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
PostgresClient.getInstance(vertxContext.owner()).select("SELECT blockedq.pid AS blocked_pid, blockedq.query as blocked_query, " + "blockingq.pid AS blocking_pid, blockingq.query as blocking_query FROM pg_catalog.pg_locks blocked " + "JOIN pg_stat_activity blockedq ON blocked.pid = blockedq.pid " + "JOIN pg_catalog.pg_locks blocking ON (blocking.transactionid=blocked.transactionid AND blocked.pid != blocking.pid) " + "JOIN pg_stat_activity blockingq ON blocking.pid = blockingq.pid " + "WHERE NOT blocked.granted AND blockingq.datname='" + dbname + "';", reply -> {
if (reply.succeeded()) {
OutStream stream = new OutStream();
stream.setData(reply.result().getResults());
System.out.println("locking q -> " + new io.vertx.core.json.JsonArray(reply.result().getResults()).encode());
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(GetAdminListLockingQueriesResponse.withJsonOK(stream)));
} else {
log.error(reply.cause().getMessage(), reply.cause());
asyncResultHandler.handle(io.vertx.core.Future.failedFuture(reply.cause().getMessage()));
}
});
}
Aggregations