@Admin @Description( "List the currently active config of Neo4j." ) @Procedure( name = "dbms.listConfig", mode = DBMS ) public Stream<ConfigResult> listConfig( @Name( value = "searchString", defaultValue = "" ) String searchString ) { Config config = graph.getDependencyResolver().resolveDependency( Config.class ); String lowerCasedSearchString = searchString.toLowerCase(); return config.getConfigValues().values().stream() .filter( c -> !c.internal() ) .filter( c -> c.name().toLowerCase().contains( lowerCasedSearchString ) ) .map( ConfigResult::new ) .sorted( Comparator.comparing( c -> c.name ) ); }
@Admin @Description( "Retrieve the status of all available collector daemons, for this database." ) @Procedure( name = "db.stats.status", mode = Mode.READ ) public Stream<StatusResult> status() { CollectorStateMachine.Status status = dataCollector.queryCollector.status(); return Stream.of( new StatusResult( Sections.QUERIES, status.message, Collections.emptyMap() ) ); }
@Admin @Description( "Stop data collection of a given data section. Valid sections are '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.stop", mode = Mode.READ ) public Stream<ActionResult> stop( @Name( value = "section" ) String section ) throws InvalidArgumentsException { CollectorStateMachine.Result result = collectorStateMachine( section ).stop( Long.MAX_VALUE ); return Stream.of( new ActionResult( section, result.success, result.message ) ); }
@Admin @Description( "Clear collected data of a given data section. Valid sections are '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.clear", mode = Mode.READ ) public Stream<ActionResult> clear( @Name( value = "section" ) String section ) throws InvalidArgumentsException { CollectorStateMachine.Result result = collectorStateMachine( section ).clear(); return Stream.of( new ActionResult( section, result.success, result.message ) ); }
@Admin @Description( "Retrieve all available statistical data about the current database, in an anonymized form." ) @Procedure( name = "db.stats.retrieveAllAnonymized", mode = Mode.READ ) public Stream<RetrieveResult> retrieveAllAnonymized( @Name( value = "graphToken" ) String graphToken, @Name( value = "config", defaultValue = "" ) Map<String, Object> config ) throws IndexNotFoundKernelException, TransactionFailureException, InvalidArgumentsException { Map<String, Object> metaData = new HashMap<>(); metaData.put( "graphToken", graphToken ); metaData.put( "retrieveTime", ZonedDateTime.now() ); TokensSection.putTokenCounts( metaData, dataCollector.kernel ); Stream<RetrieveResult> meta = Stream.of( new RetrieveResult( "META", metaData ) ); return Stream.of( meta, GraphCountsSection.retrieve( dataCollector.kernel, Anonymizer.IDS ), QueriesSection.retrieve( dataCollector.queryCollector.doGetData(), new IdAnonymizer( transaction.tokenRead() ), RetrieveConfig.of( config ).maxInvocations ) ).flatMap( x -> x ); }
@Admin @Description( "Clears all query caches." ) @Procedure( name = "dbms.clearQueryCaches", mode = DBMS ) public Stream<StringResult> clearAllQueryCaches() { QueryExecutionEngine queryExecutionEngine = graph.getDependencyResolver().resolveDependency( QueryExecutionEngine.class ); long numberOfClearedQueries = queryExecutionEngine.clearQueryCaches() - 1; // this query itself does not count String result = numberOfClearedQueries == 0 ? "Query cache already empty." : "Query caches successfully cleared of " + numberOfClearedQueries + " queries."; log.info( "Called dbms.clearQueryCaches(): " + result ); return Stream.of( new StringResult( result ) ); }
@Admin @Description( "Start data collection of a given data section. Valid sections are '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.collect", mode = Mode.READ ) public Stream<ActionResult> collect( @Name( value = "section" ) String section, @Name( value = "config", defaultValue = "" ) Map<String, Object> config ) throws InvalidArgumentsException { CollectorStateMachine.Result result = collectorStateMachine( section ).collect( config ); return Stream.of( new ActionResult( section, result.success, result.message ) ); }
@Admin @Description( "Retrieve statistical data about the current database. Valid sections are '" + Sections.GRAPH_COUNTS + "', '" + Sections.TOKENS + "', '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.retrieve", mode = Mode.READ ) public Stream<RetrieveResult> retrieve( @Name( value = "section" ) String section, @Name( value = "config", defaultValue = "" ) Map<String, Object> config ) throws InvalidArgumentsException, IndexNotFoundKernelException, TransactionFailureException { String upperSection = section.toUpperCase(); switch ( upperSection ) { case Sections.GRAPH_COUNTS: return GraphCountsSection.retrieve( dataCollector.kernel, Anonymizer.PLAIN_TEXT ); case Sections.TOKENS: return TokensSection.retrieve( dataCollector.kernel ); case Sections.QUERIES: return QueriesSection.retrieve( dataCollector.queryCollector.doGetData(), new PlainText( dataCollector.valueMapper ), RetrieveConfig.of( config ).maxInvocations ); default: throw Sections.unknownSectionException( section ); } }
@Admin @Description( "List the currently active config of Neo4j." ) @Procedure( name = "dbms.listConfig", mode = DBMS ) public Stream<ConfigResult> listConfig( @Name( value = "searchString", defaultValue = "" ) String searchString ) { Config config = graph.getDependencyResolver().resolveDependency( Config.class ); String lowerCasedSearchString = searchString.toLowerCase(); return config.getConfigValues().values().stream() .filter( c -> !c.internal() ) .filter( c -> c.name().toLowerCase().contains( lowerCasedSearchString ) ) .map( ConfigResult::new ) .sorted( Comparator.comparing( c -> c.name ) ); }
@Admin @Description( "Retrieve the status of all available collector daemons, for this database." ) @Procedure( name = "db.stats.status", mode = Mode.READ ) public Stream<StatusResult> status() { CollectorStateMachine.Status status = dataCollector.queryCollector.status(); return Stream.of( new StatusResult( Sections.QUERIES, status.message, Collections.emptyMap() ) ); }
@Admin @Description( "Stop data collection of a given data section. Valid sections are '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.stop", mode = Mode.READ ) public Stream<ActionResult> stop( @Name( value = "section" ) String section ) throws InvalidArgumentsException { CollectorStateMachine.Result result = collectorStateMachine( section ).stop( Long.MAX_VALUE ); return Stream.of( new ActionResult( section, result.success, result.message ) ); }
@Admin @Description( "Clear collected data of a given data section. Valid sections are '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.clear", mode = Mode.READ ) public Stream<ActionResult> clear( @Name( value = "section" ) String section ) throws InvalidArgumentsException { CollectorStateMachine.Result result = collectorStateMachine( section ).clear(); return Stream.of( new ActionResult( section, result.success, result.message ) ); }
@Admin @Description( "Retrieve all available statistical data about the current database, in an anonymized form." ) @Procedure( name = "db.stats.retrieveAllAnonymized", mode = Mode.READ ) public Stream<RetrieveResult> retrieveAllAnonymized( @Name( value = "graphToken" ) String graphToken, @Name( value = "config", defaultValue = "" ) Map<String, Object> config ) throws IndexNotFoundKernelException, TransactionFailureException, InvalidArgumentsException { Map<String, Object> metaData = new HashMap<>(); metaData.put( "graphToken", graphToken ); metaData.put( "retrieveTime", ZonedDateTime.now() ); TokensSection.putTokenCounts( metaData, dataCollector.kernel ); Stream<RetrieveResult> meta = Stream.of( new RetrieveResult( "META", metaData ) ); return Stream.of( meta, GraphCountsSection.retrieve( dataCollector.kernel, Anonymizer.IDS ), QueriesSection.retrieve( dataCollector.queryCollector.doGetData(), new IdAnonymizer( transaction.tokenRead() ), RetrieveConfig.of( config ).maxInvocations ) ).flatMap( x -> x ); }
@Admin @Description( "Clears all query caches." ) @Procedure( name = "dbms.clearQueryCaches", mode = DBMS ) public Stream<StringResult> clearAllQueryCaches() { QueryExecutionEngine queryExecutionEngine = graph.getDependencyResolver().resolveDependency( QueryExecutionEngine.class ); long numberOfClearedQueries = queryExecutionEngine.clearQueryCaches() - 1; // this query itself does not count String result = numberOfClearedQueries == 0 ? "Query cache already empty." : "Query caches successfully cleared of " + numberOfClearedQueries + " queries."; log.info( "Called dbms.clearQueryCaches(): " + result ); return Stream.of( new StringResult( result ) ); }
@Admin @Description( "Start data collection of a given data section. Valid sections are '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.collect", mode = Mode.READ ) public Stream<ActionResult> collect( @Name( value = "section" ) String section, @Name( value = "config", defaultValue = "" ) Map<String, Object> config ) throws InvalidArgumentsException { CollectorStateMachine.Result result = collectorStateMachine( section ).collect( config ); return Stream.of( new ActionResult( section, result.success, result.message ) ); }
@Admin @Description( "Retrieve statistical data about the current database. Valid sections are '" + Sections.GRAPH_COUNTS + "', '" + Sections.TOKENS + "', '" + Sections.QUERIES + "'" ) @Procedure( name = "db.stats.retrieve", mode = Mode.READ ) public Stream<RetrieveResult> retrieve( @Name( value = "section" ) String section, @Name( value = "config", defaultValue = "" ) Map<String, Object> config ) throws InvalidArgumentsException, IndexNotFoundKernelException, TransactionFailureException { String upperSection = section.toUpperCase(); switch ( upperSection ) { case Sections.GRAPH_COUNTS: return GraphCountsSection.retrieve( dataCollector.kernel, Anonymizer.PLAIN_TEXT ); case Sections.TOKENS: return TokensSection.retrieve( dataCollector.kernel ); case Sections.QUERIES: return QueriesSection.retrieve( dataCollector.queryCollector.doGetData(), new PlainText( dataCollector.valueMapper ), RetrieveConfig.of( config ).maxInvocations ); default: throw Sections.unknownSectionException( section ); } }