Show
Ignore:
Timestamp:
10/03/07 16:43:01 (5 years ago)
Author:
andi
Message:

design updates

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/openmct/packages/system/owi/src/sysinfo.c

    r429 r468  
    3434#include <sys/sysinfo.h> 
    3535#include "includes/argument.h" 
     36#include "includes/file.h" 
    3637#include "includes/language.h" 
    3738#include "includes/template.h" 
     
    7071 */ 
    7172void sysinfo_list() { 
    72    sysinfo_general(); 
    73     
    74    printf("<table>\n" 
    75           "<tr><td valign=\"top\">\n"); 
    76      
    77    sysinfo_filesystems(); 
    78   
    79    printf("</td><td>&nbsp;</td><td valign=\"top\">\n"); 
    80  
    81    sysinfo_network(); 
    82  
    83    printf("</td></tr>\n" 
    84           "</table>\n"); 
    85 } 
    86  
    87 /* \fn sysinfo_general() 
    88  * Display general system information like swap, ram, uptime ... 
    89  */ 
    90 void sysinfo_general() { 
    9173   /* System information */ 
    9274   struct sysinfo si; 
     75   /* Hostname */ 
     76   char *hostname = proc_read_line("/bin/hostname -f", 0); 
     77   /* Version */ 
     78   char *version = file_read_line("/etc/openmct.release", 0); 
     79   /* OS Version */ 
     80   char *osversion = proc_read_line("/bin/uname -a", 0); 
     81   /* Datum */ 
     82   char *date = proc_read_line("date", 0); 
     83   /* Uptime */ 
     84   char *uptime = proc_read_line("uptime", 0); 
    9385 
    94    /* Get system information */ 
    95    if (!sysinfo(&si)) { 
    96       owi_headline(1, SYSINFO_HEADLINE); 
    97       owi_headline(2, SYSINFO_DESCRIPTION); 
    98       printf("<table class=\"%s\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\">\n" 
    99              "<thead>\n" 
    100              "<tr>\n" 
    101              "<th>Load (1 / 5 / 15 minute load avarage)</th>\n" 
    102              "<th>Memory (All / Free / Shared)</th>\n" 
    103              "<th>Speicher in Puffern:</t>\n" 
    104              "<th>Swap (All / Free):</th>\n" 
    105              "<th>Tasks</th>\n" 
    106              "</tr>\n" 
    107              "</thead>\n" 
    108              "<tr onmouseover=\"this.className='%s';\"" 
    109              " onmouseout=\"this.className='%s';\">\n" 
    110              "<td>%u / %u / %u</td>\n" 
    111              "<td>%u MB / %u MB / %u MB</td>\n" 
    112              "<td>%u</td>\n" 
    113              "<td>%u MB / %u MB</td>\n" 
    114              "<td>%d</td>\n" 
    115              "</tr>\n" 
    116              "</table>\n", 
    117              CONTENT_TABLE_BOX_CLASS, 
    118              CONTENT_TABLE_CLASS_MOUSEOVER, 
    119              CONTENT_TABLE_CLASS_MOUSEOUT, 
    120              (unsigned int)si.loads[0], (unsigned int)si.loads[1], 
    121              (unsigned int)si.loads[2], (unsigned int)(si.totalram / 1024 / 1024), 
    122              (unsigned int)(si.freeram / 1024 / 1024), 
    123              (unsigned int)(si.sharedram / 1024 / 1024), 
    124              (unsigned int)si.bufferram, 
    125              (unsigned int)(si.totalswap / 1024 / 1024), 
    126              (unsigned int)(si.freeswap / 1024 / 1024), 
    127              (unsigned int)si.procs); 
    128    } 
     86   sysinfo(&si); 
     87 
     88   printf("<h4>%s</h4>\n" 
     89          "<table class=\"detail\">\n" 
     90          "<thead>\n" 
     91          "<tr>\n" 
     92          "<th colspan=\"2\">%s</th>\n" 
     93          "</tr>\n" 
     94          "</thead>\n" 
     95          "<tbody>\n" 
     96          "<tr>\n" 
     97          "<td class=\"description\">Name</td>\n" 
     98          "<td class=\"value\">%s</td>\n" 
     99          "</tr>\n" 
     100          "<tr>\n" 
     101          "<td class=\"description\">Version</td>\n" 
     102          "<td class=\"value\">%s</td>\n" 
     103          "</tr>\n" 
     104          "<tr>\n" 
     105          "<td class=\"description\">OS Version</td>\n" 
     106          "<td class=\"value\">%s</td>\n" 
     107          "</tr>\n" 
     108          "<tr>\n" 
     109          "<td class=\"description\">Date</td>\n" 
     110          "<td class=\"value\">%s</td>\n" 
     111          "</tr>\n" 
     112          "<tr>\n" 
     113          "<td class=\"description\">Uptime</td>\n" 
     114          "<td class=\"value\">%s</td>\n" 
     115          "</tr>\n" 
     116          "<tr>\n" 
     117          "<td class=\"description\">Memory Usage</td>\n" 
     118          "<td class=\"value\">%ld %%</td>\n" 
     119          "</tr>\n" 
     120          "<tr>\n" 
     121          "<td class=\"description\">Diskspace Usage</td>\n" 
     122          "<td class=\"value\">%s</td>\n" 
     123          "</tr>\n" 
     124          "</tbody>\n" 
     125          "</table>\n", 
     126          SYSINFO_HEADLINE, 
     127          SYSINFO_HEADLINE_BOX, 
     128          hostname, 
     129          version, 
     130          osversion, 
     131          date, 
     132          uptime, 
     133          (si.totalram - si.freeram) / (si.totalram * 100), 
     134          "0"); 
    129135} 
    130  
    131 /* \fn sysinfo_filesystems() 
    132  * Display information about mounted devices (like filesystem, diskspace ...) 
    133  */ 
    134 void sysinfo_filesystems() { 
    135    /* File handler */ 
    136    FILE *fp = NULL; 
    137    /* Mount information */ 
    138    char device[256], mountpoint[256], fs[256]; 
    139  
    140    /* Try to open mount information file */ 
    141    fp = fopen("/proc/mounts", "r"); 
    142    /* Ok? */ 
    143    if (fp) { 
    144       owi_headline(1, SYSINFO_FILESYSTEMS); 
    145       owi_headline(2, SYSINFO_FILESYSTEMS_DESCRIPTION); 
    146       printf("<table class=\"%s\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\">\n" 
    147              "<thead>\n" 
    148              "<tr>\n" 
    149              "<th>Ger&auml;t</th>\n" 
    150              "<th>Eingeh&auml;ngt auf</th>\n" 
    151              "<th>Dateisystem</th>\n" 
    152              "</tr>\n" 
    153              "</thead>\n", 
    154              CONTENT_TABLE_BOX_CLASS); 
    155       /* Read until file end reached */ 
    156       while (fscanf(fp, "%s %s %s", device, mountpoint, fs) == 3) { 
    157          if (strcasecmp(fs, "0")) { 
    158             printf("<tr onmouseover=\"this.className='%s';\"" 
    159                       " onmouseout=\"this.className='%s';\">\n" 
    160                    "<td>%s</td>\n" 
    161                    "<td>%s</td>\n" 
    162                    "<td>%s</td>\n" 
    163                    "</tr>\n", 
    164                    CONTENT_TABLE_CLASS_MOUSEOVER, 
    165                    CONTENT_TABLE_CLASS_MOUSEOUT, 
    166                    device, 
    167                    mountpoint, 
    168                    fs); 
    169          } 
    170       } 
    171       printf("</table>\n"); 
    172       /* Close */ 
    173       fclose(fp); 
    174    } 
    175 } 
    176  
    177 /* \fn sysinfo_network() 
    178  * Display network devices information 
    179  */ 
    180 void sysinfo_network() { 
    181    /* File handler */ 
    182    FILE *fp = NULL; 
    183    /* Device information */ 
    184    char device[1024], line[1024]; 
    185    /* Trafic information */ 
    186    int in, out; 
    187  
    188    /* Try to open network information file */ 
    189    fp = fopen("/proc/net/dev", "r"); 
    190    /* Ok? */ 
    191    if (fp) { 
    192       owi_headline(1, SYSINFO_NETWORK_DEVICES); 
    193       owi_headline(2, SYSINFO_NETWORK_DEVICES_DESCRIPTION); 
    194       printf("<table class=\"%s\" cellpadding=\"0\" cellspacing=\"0\" align=\"left\">\n" 
    195              "<thead>\n" 
    196              "<tr>\n" 
    197              "<th>Interface</th>\n" 
    198              "<th>In</th>\n" 
    199              "<th>Out</th>\n" 
    200              "</tr>\n" 
    201              "</thead>\n", 
    202              CONTENT_TABLE_BOX_CLASS); 
    203       /* Skip first line */ 
    204       fgets(line, sizeof(line) - 1, fp); 
    205       /* Read while not end of file */ 
    206       while (fgets(line, sizeof(line) - 1, fp)) { 
    207          /* : found? */ 
    208          if (strchr(line, ':')) { 
    209             sscanf(line, "%*[ ]%[^:]:%d %*s %*s %*s %*s %*s %*s %*s %d", device, &in, &out); 
    210             /* printf("[%s]<>[%s]\n", device, p->ifa_name); */ 
    211             printf("<tr onmouseover=\"this.className='%s';\"" 
    212                    " onmouseout=\"this.className='%s';\">\n" 
    213                    "<td>%s</td>\n" 
    214                    "<td>%d MB</td>\n" 
    215                    "<td>%d MB</td>\n" 
    216                    "</tr>\n", 
    217                    CONTENT_TABLE_CLASS_MOUSEOVER, 
    218                    CONTENT_TABLE_CLASS_MOUSEOUT, 
    219                    device, 
    220                    in / 1024 / 1024, 
    221                    out / 1024 / 1024); 
    222          } 
    223       } 
    224  
    225       printf("</table>\n"); 
    226        /* Close */ 
    227       fclose(fp); 
    228    } 
    229 }