69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
-
-
+
+
-
+
|
#define HEADERLEN 14
#define VERSION "0.8.7"
extern char *optarg;
extern int optind, opterr, optopt;
void bargraph(float percent, float secondper, char marks[BARLEN+HEADERLEN],int usefull) {
char percentone[BARLEN], percenttwo[BARLEN], remain[BARLEN];
void bargraph(float percent, float secondper, char marks[BARLEN+HEADERLEN+1],int usefull) {
char percentone[BARLEN+1], percenttwo[BARLEN+1], remain[BARLEN+1];
unsigned int numberofmarks, numofmarkstwo, remainnum;
numberofmarks=(int) ((float) (BARLEN*(percent/100)));
if (!usefull) numofmarkstwo=(int) ((float) (BARLEN*(secondper/100))); else numofmarkstwo=(BARLEN-numberofmarks);
remainnum=BARLEN-(numberofmarks+numofmarkstwo);
memset(percentone, '#', numberofmarks);
memset(percenttwo, '%', numofmarkstwo);
memset(remain, '.', remainnum);
percentone[numberofmarks]=0;
percenttwo[numofmarkstwo]=0;
remain[remainnum]=0;
sprintf(marks,"%s\033[1;31m%s\033[1;37m%s",percentone, percenttwo, remain);
snprintf(marks, BARLEN+HEADERLEN+1, "%s\033[1;31m%s\033[1;37m%s", percentone, percenttwo, remain);
return;
}
#ifndef HAVE_LIBSTATGRAB
/*
Extracted alot from sysinfo.c (part of the procps package?) by
Michael K. Johnson <johnsonm@redhat.com>
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
-
-
-
+
+
+
|
return(results);
}
#endif
int main(int argc, char *argv[]) {
float percentram, percentswap, percentbuffer, percentused, percentfree;
float ramfree, ramtotal, swapfree, swaptotal, doloop=0, cachedbuffer, totaltotal;
char realbarchart[BARLEN+HEADERLEN], swapbarchart[BARLEN+HEADERLEN], totalbarchart[BARLEN+HEADERLEN];
int i, divisor=1024, dototals=0, doold=0, linestoup=2;
unsigned long meminfo_cached;
char realbarchart[BARLEN+HEADERLEN+1], swapbarchart[BARLEN+HEADERLEN+1], totalbarchart[BARLEN+HEADERLEN+1];
int i, dototals=0, doold=0, linestoup=2;
unsigned long meminfo_cached, divisor=1024;
#ifndef HAVE_LIBSTATGRAB
struct sysinfo sinfo;
meminfo_cached=get_meminfo("Cached:");
#else
sg_mem_stats *mem_stats=NULL;
sg_swap_stats *swap_stats=NULL;
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
-
-
+
+
-
+
|
percentfree=(float) (((sinfo.freeram+sinfo.freeswap+meminfo_cached+sinfo.bufferram)/totaltotal)*100);
percentused=(int) (100-((int) percentfree));
if (!(swaptotal==0)) { percentswap=(float) ((swapfree/swaptotal)*100); } else { percentswap=0; }
bargraph(percentswap,0,swapbarchart,0);
bargraph(percentram,percentbuffer,realbarchart,0);
bargraph((int) percentfree,(int) percentused,totalbarchart,1);
if (!doold) {
printf("Physical : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%i/%i)\n", realbarchart ,(int) (percentram+percentbuffer), (int) (ramfree+cachedbuffer)/divisor, (int) ramtotal/divisor);
printf("Swap : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%i/%i)\n",swapbarchart ,(int) percentswap,(int) swapfree/divisor, (int) swaptotal/divisor);
printf("Physical : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n", realbarchart ,(int) (percentram+percentbuffer), (unsigned long) (ramfree+cachedbuffer)/divisor, (unsigned long) ramtotal/divisor);
printf("Swap : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",swapbarchart ,(int) percentswap,(unsigned long) swapfree/divisor, (unsigned long) swaptotal/divisor);
if (dototals)
printf("Total : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%i=%i+%i)\n", totalbarchart, (int) (sinfo.totalram+sinfo.totalswap)/divisor,(int) ((sinfo.freeram+sinfo.freeswap)/divisor), (int) ((totaltotal-((sinfo.freeram+sinfo.freeswap+cachedbuffer)))/divisor));
printf("Total : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%lu=%lu+%lu)\n", totalbarchart, (unsigned long) (sinfo.totalram+sinfo.totalswap)/divisor,(unsigned long) ((sinfo.freeram+sinfo.freeswap)/divisor), (unsigned long) ((totaltotal-((sinfo.freeram+sinfo.freeswap+cachedbuffer)))/divisor));
} else {
printf(" total used free shared buffers cached\n");
printf("Mem: %12lu %10lu %10lu %10lu %10lu %10lu\n",(sinfo.totalram/divisor), (sinfo.totalram-sinfo.freeram)/divisor, (sinfo.freeram/divisor), (sinfo.sharedram/divisor), (sinfo.bufferram/divisor), (((unsigned long) cachedbuffer)/divisor));
printf("Swap: %12lu %10lu %10lu\n",(sinfo.totalswap/divisor), ((sinfo.totalswap-sinfo.freeswap)/divisor), (sinfo.freeswap/divisor));
if (dototals) printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",(long) totaltotal/divisor,(((long) totaltotal)-((sinfo.freeram+sinfo.freeswap)))/divisor,(sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer))/divisor);
}
if (doloop==0) { return(0); } else { usleep(doloop*1000000); printf("\033[%iA",linestoup); }
}
return(0);
}
|