Search in sources :

Example 31 with OutStream

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()));
        }
    });
}
Also used : RestVerticle(org.folio.rest.RestVerticle) LRUCache(org.folio.rest.tools.utils.LRUCache) AES(org.folio.rest.security.AES) Date(java.util.Date) StatsTracker(org.folio.rest.tools.monitor.StatsTracker) Context(io.vertx.core.Context) BodyPart(javax.mail.BodyPart) PomReader(org.folio.rest.tools.PomReader) MemoryMXBean(java.lang.management.MemoryMXBean) Logger(org.apache.log4j.Logger) ThreadInfo(java.lang.management.ThreadInfo) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) LogUtil(org.folio.rest.tools.utils.LogUtil) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) JsonObject(io.vertx.core.json.JsonObject) ManagementFactory(java.lang.management.ManagementFactory) AsyncResult(io.vertx.core.AsyncResult) MemoryUsage(java.lang.management.MemoryUsage) MimeMultipart(javax.mail.internet.MimeMultipart) DecimalFormat(java.text.DecimalFormat) ThreadMXBean(java.lang.management.ThreadMXBean) Validate(org.folio.rest.annotations.Validate) TenantTool(org.folio.rest.tools.utils.TenantTool) PostgresClient(org.folio.rest.persist.PostgresClient) IOUtils(org.apache.commons.io.IOUtils) OutStream(org.folio.rest.tools.utils.OutStream) Response(javax.ws.rs.core.Response) AdminResource(org.folio.rest.jaxrs.resource.AdminResource) ClientGenerator(org.folio.rest.tools.ClientGenerator) LogManager(org.apache.log4j.LogManager) Handler(io.vertx.core.Handler) InputStream(java.io.InputStream) OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 32 with OutStream

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()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream)

Example 33 with OutStream

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()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Example 34 with OutStream

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)));
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream)

Example 35 with OutStream

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()));
        }
    });
}
Also used : OutStream(org.folio.rest.tools.utils.OutStream) Validate(org.folio.rest.annotations.Validate)

Aggregations

OutStream (org.folio.rest.tools.utils.OutStream)40 Validate (org.folio.rest.annotations.Validate)26 FieldException (org.z3950.zing.cql.cql2pgjson.FieldException)13 CQLParseException (org.z3950.zing.cql.CQLParseException)8 PostgresClient (org.folio.rest.persist.PostgresClient)7 List (java.util.List)5 JsonObject (io.vertx.core.json.JsonObject)4 Response (javax.ws.rs.core.Response)4 CQLWrapper (org.folio.rest.persist.cql.CQLWrapper)4 Map (java.util.Map)3 Limit (org.folio.rest.persist.Criteria.Limit)3 Offset (org.folio.rest.persist.Criteria.Offset)3 TenantTool (org.folio.rest.tools.utils.TenantTool)3 CQL2PgJSON (org.z3950.zing.cql.cql2pgjson.CQL2PgJSON)3 io.vertx.core (io.vertx.core)2 AsyncResult (io.vertx.core.AsyncResult)2 JsonArray (io.vertx.core.json.JsonArray)2 Logger (io.vertx.core.logging.Logger)2 LoggerFactory (io.vertx.core.logging.LoggerFactory)2 InputStream (java.io.InputStream)2