/* * Copyright 2007-2017 Charles du Jeu - Abstrium SAS * This file is part of Pydio. * * Pydio is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Pydio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Pydio. If not, see . * * The latest code can be found at . */ import React from 'react' import {RaisedButton} from 'material-ui' const {Doughnut} = require('react-chartjs') import PluginEditor from '../core/PluginEditor' const CacheServerDashboard = React.createClass({ mixins:[AdminComponents.MessagesConsumerMixin], getInitialState:function(){ return {cacheStatuses:[], loading:false}; }, componentDidMount:function(){ this.checkCacheStats(); }, clearCache: function(namespace){ PydioApi.getClient().request({get_action:'cache_service_clear_cache', namespace:namespace}, function(transp) { this.checkCacheStats(); }.bind(this)); }, checkCacheStats: function(){ this.setState({loading:true}); PydioApi.getClient().request({get_action:'cache_service_expose_stats'}, function(transp) { this.setState({loading: false}); if (!this.isMounted()) return; var response = transp.responseJSON; this.setState({cacheStatuses:response}); setTimeout(this.checkCacheStats.bind(this), 4000); }.bind(this)); }, formatUptime(time){ var sec_num = parseInt(time, 10); // don't forget the second param var hours = Math.floor(sec_num / 3600); var minutes = Math.floor((sec_num - (hours * 3600)) / 60); var seconds = sec_num - (hours * 3600) - (minutes * 60); if (hours < 10) {hours = "0"+hours;} if (minutes < 10) {minutes = "0"+minutes;} if (seconds < 10) {seconds = "0"+seconds;} return hours+':'+minutes+':'+seconds; }, renderCachePane: function(cacheData){ let healthPercent = parseInt( 100 * cacheData.misses / cacheData.hits); let health; if(healthPercent < 5) { health = '< 5%'; }else if(healthPercent < 20){ health = '< 20%'; }else if(healthPercent < 40){ health = '< 40%'; }else if(healthPercent < 60){ health = '> 40%'; }else{ health = '> 60%'; } let memoryUsage; if(cacheData.memory_available){ memoryUsage = (
Memory Usage
{parseInt( 100 * cacheData.memory_usage / cacheData.memory_available) }%
); }else{ memoryUsage = (
Memory Usage
{PathUtils.roundFileSize(cacheData.memory_usage)}
); } return (

Namespace '{cacheData.namespace}'

{memoryUsage}
Cache Health
{health}
Uptime: {this.formatUptime(cacheData.uptime)}
); }, renderClearButton:function(cacheData){ return (
); }, renderStatusPane: function(){ var overall = (this.state.cacheStatuses.length?this.renderCachePane(this.state.cacheStatuses[0]):null); return (

Status

{overall}

Cache Control

{this.state.cacheStatuses.map(this.renderClearButton.bind(this))}
); }, render: function(){ var pane = this.renderStatusPane(); return (
); } }); export {CacheServerDashboard as default}