lkmonitor.c

Go to the documentation of this file.
00001 /*
00002 lkmonitor (Linux Kernel Monitor)
00003 
00004 Application for monitoring and tuning a Linux kernel.
00005 
00006 Copyright (C) 2005-2006  Fernando ApesteguĂ­a
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 */
00022 #ifdef HAVE_CONFIG_H
00023 #  include <config.h>
00024 #endif
00025 #include <glib.h>
00026 #include <gtk/gtk.h>
00027 
00028 #include "eggtrayicon.h"
00029 #include "support.h"
00030 
00031 #include "others.h"
00032 #include "lininfo.h"
00033 
00034 
00035 
00041 struct {
00042         EggTrayIcon *eti;
00043     GtkWidget *eb;
00044     GtkWidget *image;     
00045   }     docklet;
00046 
00047 
00048 extern GThread *gt_collector;
00049 extern GtkWidget *window1;
00050 
00054 void lkmonitor_exit()
00055 {
00056         extern gboolean collector_exit;
00057 
00058         collector_exit=TRUE;
00059         gtk_main_quit();
00060 }
00061 
00065 void docklet_onclick(GtkWidget *w)
00066 {
00067         extern gboolean is_icon;
00068         
00069         gtk_widget_show(window1);
00070         is_icon=FALSE;
00071         
00072 }
00073 
00077 void lkmonitor_create_tray_icon(){
00078 
00079   gint w = 0;
00080   gint h = 0;
00081         
00082   docklet.eti = egg_tray_icon_new("lkmonitor");
00083   docklet.eb = gtk_event_box_new();
00084   docklet.image = gtk_image_new();
00085 
00086   GdkPixbuf *pb = NULL;
00087   GdkPixbuf *pb_scaled = NULL;
00088 
00089   pb =create_pixbuf("lkmonitor/spider-shadow32.png");
00090   gtk_icon_size_lookup(GTK_ICON_SIZE_LARGE_TOOLBAR, &w, &h);
00091   pb_scaled = gdk_pixbuf_scale_simple(pb, w, h, GDK_INTERP_BILINEAR);
00092   gtk_image_set_from_pixbuf(GTK_IMAGE(docklet.image), pb_scaled);
00093 
00094 
00095   gtk_container_add(GTK_CONTAINER(docklet.eb), docklet.image);
00096   gtk_container_add(GTK_CONTAINER(docklet.eti), docklet.eb);
00097   gtk_widget_show_all(GTK_WIDGET(docklet.eti));
00098   
00099  
00100   g_signal_connect(G_OBJECT(docklet.eb), "button-press-event", G_CALLBACK(docklet_onclick), window1);
00101   
00102   
00103   g_object_ref(G_OBJECT(docklet.eti));
00104 }
00105 
00106 
00111 void lkmonitor_init_widgets(GtkWidget *window)
00112 {
00113 
00114   GtkListStore *block_list;
00115   GtkListStore *char_list;
00116   GtkCellRenderer *b_renderer;
00117   GtkCellRenderer *c_renderer;
00118   GtkTreeView *gtv_char;
00119   GtkTreeView *gtv_block;
00120 
00121         /*Tree views to show devices*/
00122         /*For block devices*/
00123         
00124         /*First column*/
00125   gtv_block= (GtkTreeView *)lookup_widget(window,"gtv_block");
00126   block_list=gtk_list_store_new(2,G_TYPE_INT, G_TYPE_STRING);
00127   gtk_tree_view_set_model(GTK_TREE_VIEW(gtv_block),GTK_TREE_MODEL(block_list));
00128  
00129   b_renderer = gtk_cell_renderer_text_new ();
00130   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_block),
00131                                                -1,      
00132                                                _("Number"),  
00133                                                b_renderer,
00134                                                "text", 0,
00135                                                NULL);
00136 
00137   /*Second column*/
00138 
00139   b_renderer = gtk_cell_renderer_text_new ();
00140   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_block),
00141                                                -1,      
00142                                                _("Device"),  
00143                                                b_renderer,
00144                                                "text", 1,
00145                                                NULL);
00146                                                                                            
00147   
00148   /*For char devices*/  
00149   
00150   /*First column*/
00151   gtv_char= (GtkTreeView *)lookup_widget(window,"gtv_char");
00152   char_list=gtk_list_store_new(2,G_TYPE_INT, G_TYPE_STRING);
00153   gtk_tree_view_set_model(GTK_TREE_VIEW(gtv_char),GTK_TREE_MODEL(char_list));
00154  
00155   c_renderer = gtk_cell_renderer_text_new ();
00156   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_char),
00157                                                -1,      
00158                                                _("Number"),  
00159                                                c_renderer,
00160                                                "text", 0,
00161                                                NULL);
00162 
00163   /*Second column*/
00164 
00165   c_renderer = gtk_cell_renderer_text_new ();
00166   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gtv_char),
00167                                                -1,      
00168                                                _("Device"),  
00169                                                c_renderer,
00170                                                "text", 1,
00171                                                NULL);
00172 }
00173 
00182 void lkmonitor_fill_tv(GtkListStore *model, GtkTreeView *gtv,
00183                                         GtkTreeIter iter, char *buffer)
00184 {
00185         g_assert(model!=NULL && gtv!=NULL && buffer !=NULL);
00186         
00187         char *pointer;
00188         char name[50];
00189         int num;
00190         //Now add data to model
00191 
00192         pointer=buffer;
00193 
00194         while(*pointer!='\0'){
00195                 gtk_list_store_append(model,&iter);
00196                 sscanf(pointer,"%d %s",&num,name);
00197                 gtk_list_store_set(model,&iter,0,num,1,name,-1);
00198                 pointer=strchr(pointer,'\n')+1;
00199         }
00200 }
00201 
00204 void lkmonitor_write_settings()
00205 {
00206   //This is called from a callback, so we are still running in a gtk lock.
00207   GtkEntry *ent;
00208   GtkLabel *lbl;
00209   GtkSpinButton *spb;
00210   GString *gs;
00211   int val1,val2,val3,val4;
00212         
00213 /*For Identification*/
00214   ent=GTK_ENTRY(lookup_widget(window1,"ent_hostname"));
00215   gs=g_string_new(gtk_entry_get_text(ent));
00216   write_string_to_file(gs->str,HOST_NAME);
00217         
00218   ent=GTK_ENTRY(lookup_widget(window1,"ent_domainname"));
00219   gs=g_string_new(gtk_entry_get_text(ent));
00220   write_string_to_file(gs->str,DOMAIN_NAME);
00221         
00222 /*For Files*/
00223         
00224   spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_fdmax"));
00225   val1=(int)gtk_spin_button_get_value_as_int(spb);
00226 
00227   write_values_to_file(3,FILE_MAX,val1);
00228 
00229 /*For Inodes*/
00230         lbl=GTK_LABEL(lookup_widget(window1,"lbl_inmax"));
00231         val1=atoi((char *)gtk_label_get_text(lbl));
00232         
00233         lbl=GTK_LABEL(lookup_widget(window1,"lbl_ina"));
00234         val2=atoi((char *)gtk_label_get_text(lbl));
00235         
00236         write_values_to_file(2,INODES,val1,val2);
00237 
00238 /*For POSIX signals*/
00239         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_mq"));
00240         val1=gtk_spin_button_get_value_as_int(spb);
00241         write_values_to_file(1,P_MAX_Q,val1);
00242         
00243         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_mpq"));
00244         val1=gtk_spin_button_get_value_as_int(spb);
00245         write_values_to_file(1,P_MAX_M,val1);
00246         
00247         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_ms"));
00248         val1=gtk_spin_button_get_value_as_int(spb);
00249         write_values_to_file(1,P_MAX_S,val1);
00250 
00251 /*For shared memory*/
00252         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_pages"));
00253         val1=gtk_spin_button_get_value_as_int(spb);
00254         write_values_to_file(1,PAGE_MAX,val1);
00255         
00256         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_max_segs"));
00257         val1=gtk_spin_button_get_value_as_int(spb);
00258         write_values_to_file(1,SEG_MAX,val1);
00259         
00260         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_seg_size"));
00261         val1=gtk_spin_button_get_value_as_int(spb);
00262         write_values_to_file(1,SEG_SIZE,val1);
00263         
00264 /*For semaphores*/
00265         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_sem_per_id"));
00266         val1=gtk_spin_button_get_value_as_int(spb);
00267         
00268         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_sem_val"));
00269         val2=gtk_spin_button_get_value_as_int(spb);
00270         
00271         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_ops"));
00272         val3=gtk_spin_button_get_value_as_int(spb);
00273         
00274         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_sem_id"));
00275         val4=gtk_spin_button_get_value_as_int(spb);
00276         
00277         write_values_to_file(4,SEM,val1,val2,val3,val4);
00278         
00279 /*For threads*/
00280         spb=GTK_SPIN_BUTTON(lookup_widget(window1,"spb_maxthreads"));
00281         val1=gtk_spin_button_get_value_as_int(spb);
00282         
00283         write_values_to_file(1,THREADS_MAX,val1);
00284 }

Generated on Sat Dec 2 11:27:51 2006 for lkmonitor by  doxygen 1.5.1