<commit_before>/*
 * The Gemma project
 * 
 * Copyright (c) 2008 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package ubic.gemma.web.controller.monitoring;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import ubic.gemma.job.grid.util.SpaceMonitor;
import ubic.gemma.job.grid.util.SpacesUtil;
import ubic.gemma.job.grid.worker.SpacesRegistrationEntry;
import ubic.gemma.util.monitor.CacheMonitor;
import ubic.gemma.util.monitor.HibernateMonitor;

/**
 * Provide statistics about the system: hibernate, caches etc.
 * 
 * @author paul
 * @version $Id$
 */
@Controller
public class SystemMonitorController {

    @Autowired
    CacheMonitor cacheMonitor;

    @Autowired
    HibernateMonitor hibernateMonitor;

    @Autowired
    SpaceMonitor spaceMonitor;

    /**
     * Flush (clear) all caches. Expose to AJAX
     */
    public void flushAllCaches() {
        this.cacheMonitor.flushAllCaches();
    }
    
    /**
     * 
     */
    public void resetHibernateStatus() {
        this.hibernateMonitor.resetStats();
    }

    /**
     * Flush (clear) a cache.
     * 
     * @param cache name Expose to AJAX
     */
    public void flushCache( String name ) {
        this.cacheMonitor.flushCache( name );
    }

    public String getCacheStatus() {
        return cacheMonitor.getStats();
    }

    /**
     * Expose to AJAX
     * 
     * @return
     */
    public String getHibernateStatus() {
        return this.hibernateMonitor.getStats( true, true, true );
    }

    /**
     * Expose to AJAX<commit_msg>Method name change. flushCache to clearCache. Flushing cache is writing it to disk which is misleading since we're clearing it.<commit_after>/*
 * The Gemma project
 * 
 * Copyright (c) 2008 University of British Columbia
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package ubic.gemma.web.controller.monitoring;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import ubic.gemma.job.grid.util.SpaceMonitor;
import ubic.gemma.job.grid.util.SpacesUtil;
import ubic.gemma.job.grid.worker.SpacesRegistrationEntry;
import ubic.gemma.util.monitor.CacheMonitor;
import ubic.gemma.util.monitor.HibernateMonitor;

/**
 * Provide statistics about the system: hibernate, caches etc.
 * 
 * @author paul
 * @version $Id$
 */
@Controller
public class SystemMonitorController {

    @Autowired
    CacheMonitor cacheMonitor;

    @Autowired
    HibernateMonitor hibernateMonitor;

    @Autowired
    SpaceMonitor spaceMonitor;

    /**
     * Flush (clear) all caches. Expose to AJAX
     */
    public void clearAllCaches() {
        this.cacheMonitor.clearAllCaches();
    }
    
    /**
     * 
     */
    public void resetHibernateStatus() {
        this.hibernateMonitor.resetStats();
    }

    /**
     * Flush (clear) a cache.
     * 
     * @param cache name Expose to AJAX
     */
    public void clearCache( String name ) {
        this.cacheMonitor.clearCache( name );
    }

    public String getCacheStatus() {
        return cacheMonitor.getStats();
    }

    /**
     * Expose to AJAX
     * 
     * @return
     */
    public String getHibernateStatus() {
        return this.hibernateMonitor.getStats( true, true, true );
    }

    /**
     * Expose to AJAX
{'fraction_non_alphanumeric': 0.09306056959486562, 'fraction_numerical': 0.003208985158443642, 'mean_word_length': 3.194280908326325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4944782', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1389, 'n_words': 406}