~ubuntu-branches/ubuntu/trusty/net-snmp/trusty

« back to all changes in this revision

Viewing changes to agent/mibgroup/hardware/memory/memory_irix.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2007-12-08 14:59:50 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20071208145950-u1tykhpw56nyzqik
Tags: 5.4.1~dfsg-4ubuntu1
* Merge from debian unstable.
* Remaining Ubuntu changes:
  - Remove stop links from rc0 and rc6
  - Munge Maintainer field as per spec.
* Ubuntu changes dropped:
  - Symlink common files between the packages, CDBS ought to handle that
    for us automatically.
* The latest Debian changes has dropped history from the changelog. Slot in
  the Ubuntu changes as best I can. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <net-snmp/net-snmp-config.h>
 
2
#include <net-snmp/net-snmp-includes.h>
 
3
#include <net-snmp/agent/net-snmp-agent-includes.h>
 
4
#include <net-snmp/agent/hardware/memory.h>
 
5
 
 
6
#if HAVE_SYS_SWAP_H
 
7
#include <sys/swap.h>
 
8
#endif
 
9
 
 
10
#if HAVE_SYS_SYSGET_H
 
11
#include <sys/sysget.h>
 
12
#endif
 
13
 
 
14
#if HAVE_SYS_SYSMP_H
 
15
#include <sys/sysmp.h>
 
16
#endif
 
17
 
 
18
    /*
 
19
     * Load the latest memory usage statistics
 
20
     */
 
21
int netsnmp_mem_arch_load( netsnmp_cache *cache, void *magic ) {
 
22
 
 
23
    netsnmp_memory_info *mem;
 
24
    struct rminfo meminfo; /* struct for getting memory info, see sys/sysmp.h */
 
25
    int pagesz, rminfosz;
 
26
    off_t swaptotal, swapfree;
 
27
 
 
28
    /*
 
29
     * Retrieve the memory information from the underlying O/S...
 
30
     */
 
31
    DEBUGMSGTL(("hardware/memory/memory_irix", "Start retrieving values from OS\n"));
 
32
    pagesz = getpagesize();
 
33
    DEBUGMSGTL(("hardware/memory/memory_irix", "Page size: %d\n", pagesz));
 
34
    rminfosz = (int)sysmp(MP_SASZ, MPSA_RMINFO);
 
35
    DEBUGMSGTL(("hardware/memory/memory_irix", "rminfo size: %d\n", rminfosz));
 
36
    if (sysmp(MP_SAGET, MPSA_RMINFO, &meminfo, rminfosz) < 0) {
 
37
        snmp_log(LOG_ERR, "memory_irix: sysmp failed!\n");
 
38
        return -1;
 
39
    }
 
40
    swapctl(SC_GETSWAPTOT, &swaptotal);
 
41
    swapctl(SC_GETFREESWAP, &swapfree);
 
42
 
 
43
    /*
 
44
     * ... and save this in a standard form.
 
45
     */
 
46
    mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_PHYSMEM, 1 );
 
47
    if (!mem) {
 
48
        snmp_log_perror("No Physical Memory info entry");
 
49
    } else {
 
50
        if (!mem->descr)
 
51
             mem->descr = strdup("Physical memory");
 
52
        mem->units = pagesz;
 
53
        mem->size  = meminfo.physmem;
 
54
        mem->free  = meminfo.availrmem;
 
55
        mem->other = -1;
 
56
        DEBUGMSGTL(("hardware/memory/memory_irix", "Physical memory: size %u, free %u\n", mem->size, mem->free));
 
57
    }
 
58
 
 
59
    mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_VIRTMEM, 1 );
 
60
    if (!mem) {
 
61
        snmp_log_perror("No Virtual Memory info entry");
 
62
    } else {
 
63
        if (!mem->descr)
 
64
             mem->descr = strdup("Virtual memory");
 
65
        mem->units = pagesz;     /* swaptotal is in blocks, so adjust below */
 
66
        mem->size  = meminfo.physmem + (swaptotal*512/pagesz);
 
67
        mem->free  = meminfo.availsmem;
 
68
        mem->other = -1;
 
69
        DEBUGMSGTL(("hardware/memory/memory_irix", "Virtual memory: size %u, free %u\n", mem->size, mem->free));
 
70
    }
 
71
 
 
72
    mem = netsnmp_memory_get_byIdx( NETSNMP_MEM_TYPE_SWAP, 1 );
 
73
    if (!mem) {
 
74
        snmp_log_perror("No Swap info entry");
 
75
    } else {
 
76
        if (!mem->descr)
 
77
             mem->descr = strdup("Swap space");
 
78
        mem->units = 1024;
 
79
        mem->size  = swaptotal/2; /* blocks to KB */
 
80
        mem->free  = swapfree/2;  /* blocks to KB */
 
81
        mem->other = -1;
 
82
        DEBUGMSGTL(("hardware/memory/memory_irix", "Swap: size %u, free %u\n", mem->size, mem->free));
 
83
    }
 
84
 
 
85
    return 0;
 
86
}
 
87