2
KSysGuard, the KDE System Guard
4
Copyright (c) 1999, 2000 Chris Schlaeger <cs@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of version 2 of the GNU General Public
8
License as published by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include <sys/types.h>
27
#include "ksysguardd.h"
32
static int LoadAvgOK = 0;
33
static double LoadAvg1, LoadAvg5, LoadAvg15;
35
#define LOADAVGBUFSIZE 128
36
static char LoadAvgBuf[ LOADAVGBUFSIZE ];
39
static void processLoadAvg( void )
41
sscanf( LoadAvgBuf, "%lf %lf %lf", &LoadAvg1, &LoadAvg5, &LoadAvg15 );
46
================================ public part =================================
49
void initLoadAvg( struct SensorModul* sm )
51
if ( updateLoadAvg() < 0 ) {
57
registerMonitor( "cpu/system/loadavg1", "float", printLoadAvg1, printLoadAvg1Info, sm );
58
registerMonitor( "cpu/system/loadavg5", "float", printLoadAvg5, printLoadAvg5Info, sm );
59
registerMonitor( "cpu/system/loadavg15", "float", printLoadAvg15, printLoadAvg15Info, sm );
61
/* Register some legacy monitors. These will be hidden from the module list. */
62
registerLegacyMonitor( "cpu/loadavg1", "float", printLoadAvg1, printLoadAvg1Info, sm );
63
registerLegacyMonitor( "cpu/loadavg5", "float", printLoadAvg5, printLoadAvg5Info, sm );
64
registerLegacyMonitor( "cpu/loadavg15", "float", printLoadAvg15, printLoadAvg15Info, sm );
67
void exitLoadAvg( void )
72
int updateLoadAvg( void )
80
if ( ( fd = open( "/proc/loadavg", O_RDONLY ) ) < 0 ) {
82
print_error( "Cannot open file \'/proc/loadavg\'!\n"
83
"The kernel needs to be compiled with support\n"
84
"for /proc file system enabled!\n" );
88
n = read( fd, LoadAvgBuf, LOADAVGBUFSIZE - 1 );
89
if ( n == LOADAVGBUFSIZE - 1 || n <= 0 ) {
90
log_error( "Internal buffer too small to read \'/proc/loadavg\'" );
97
LoadAvgBuf[ n ] = '\0';
103
void printLoadAvg1( const char* cmd )
110
output( "%f\n", LoadAvg1 );
113
void printLoadAvg1Info( const char* cmd )
116
output( "Load average 1 min\t0\t0\t\n" );
119
void printLoadAvg5( const char* cmd )
126
output( "%f\n", LoadAvg5 );
129
void printLoadAvg5Info( const char* cmd )
132
output( "Load average 5 min\t0\t0\t\n" );
135
void printLoadAvg15( const char* cmd )
142
output( "%f\n", LoadAvg15 );
145
void printLoadAvg15Info( const char* cmd )
148
output( "Load average 15 min\t0\t0\t\n" );