kernel symbols for netstat -i info

kernel symbols for netstat -i info

Post by Dan Barb » Fri, 03 Feb 1995 23:57:48



I was looking for the kernel symbols that I can read to get
Ipkts, Opkts, etc.  Does anyone know what they are or where I
can find documentation on this?  

Thanks!

Dan Barber

 
 
 

kernel symbols for netstat -i info

Post by Jeff Bonwi » Tue, 07 Feb 1995 19:45:23


In article <DBARBER.95Feb2095...@dragon.atl.ge.com> dbar...@atl.ge.com (Dan Barber) writes:

>I was looking for the kernel symbols that I can read to get
>Ipkts, Opkts, etc.  Does anyone know what they are or where I
>can find documentation on this?

The "right" way to get kernel statistics in Solaris is to use the
kstat(3K) routines.  (The man pages first appeared in 2.4, but the
actual functionality has been there since 2.3.)  The following
trivial program will display all network stats:

#include <stdio.h>
#include <string.h>
#include <kstat.h>

main()
{
        int i;
        kstat_t *ksp;
        kstat_named_t *knp;
        kstat_ctl_t *kc = kstat_open();

        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
                if (strcmp(ksp->ks_class, "net") != 0)
                        continue;
                printf("interface %s:\n", ksp->ks_name);
                kstat_read(kc, ksp, NULL);
                knp = KSTAT_NAMED_PTR(ksp);
                for (i = 0; i < ksp->ks_ndata; i++)
                        printf("%30.30s = %u\n", knp[i].name, knp[i].value.ul);
        }

}

I've also included another little program (see below) that dumps out
*all* available kernel statistics.  Compile it using:

        cc -O -o kstat kstat.c -lkstat

The kstat framework is how vmstat, iostat, perfmeter (via rstatd),
sar, etc. get all of their data.  The kernel and various drivers use
the kstat(9F) DDI routines to register their statistics.  These are
exported to userland via pseudo-device, /dev/kstat.  The kstat library
provides a friendly wrapper around the underlying /dev/kstat ioctls.
(Try "truss vmstat 5" to see what's going on under the covers.)

Incidentally, since the kstat driver only exports statistics, there
are none of the security issues that you have with reading /dev/mem.
Therefore, kstat readers don't have to be setuid/setgid anymore.

Happy hacking,

Jeff Bonwick
Sun Microsystems -- OS Performance

---- begin program to dump out all kernel stats ----

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <kstat.h>

main()
{
        int j;
        kstat_t *ksp;
        kstat_named_t *kstypes;
        kstat_named_t *knp;
        kstat_intr_t *kip;
        kstat_io_t *kiop;
        kstat_timer_t *ktp;
        hrtime_t cur_time;

        kstat_ctl_t *kc = kstat_open();

        printf("kstat chain id = %d, length = %lu\n",
                kc->kc_chain_id, kc->kc_chain[0].ks_ndata);

        ksp = kstat_lookup(kc, "unix", 0, "kstat_types");
        kstat_read(kc, ksp, NULL);
        kstypes = KSTAT_NAMED_PTR(ksp);

        for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
                printf("\n%s:%d:%s class %s, type %s, KID %d\n",
                        ksp->ks_module,
                        ksp->ks_instance,
                        ksp->ks_name,
                        ksp->ks_class,
                        kstypes[ksp->ks_type].name,
                        ksp->ks_kid);
                if (kstat_read(kc, ksp, NULL) == -1) {
                        printf("%30.30s -- %s)\n", "(can't read kstat",
                                strerror(errno));
                        continue;
                }
                switch (ksp->ks_type) {

                    case KSTAT_TYPE_RAW:
                        printf("%30.30s\n", "(raw data, not shown)");
                        break;

                    case KSTAT_TYPE_NAMED:
                        knp = KSTAT_NAMED_PTR(ksp);
                        for (j = 0; j < ksp->ks_ndata; j++) {
                                printf("%30.30s = ", knp[j].name);
                                switch (knp[j].data_type) {
                                    case KSTAT_DATA_CHAR:
                                        printf("%s\n", knp[j].value.c);
                                        break;
                                    case KSTAT_DATA_LONG:
                                        printf("%ld\n", knp[j].value.l);
                                        break;
                                    case KSTAT_DATA_ULONG:
                                        printf("%lu\n", knp[j].value.ul);
                                        break;
                                    case KSTAT_DATA_LONGLONG:
                                        printf("%lld\n", knp[j].value.ll);
                                        break;
                                    case KSTAT_DATA_ULONGLONG:
                                        printf("%llu\n", knp[j].value.ull);
                                        break;
                                    case KSTAT_DATA_FLOAT:
                                        printf("%f\n", knp[j].value.f);
                                        break;
                                    case KSTAT_DATA_DOUBLE:
                                        printf("%f\n", knp[j].value.d);
                                        break;
                                    default:
                                        printf("BOGUS TYPE %u\n",
                                                knp[j].data_type);
                                        break;
                                }
                        }
                        break;

                    case KSTAT_TYPE_INTR:
                        kip = KSTAT_INTR_PTR(ksp);
                        printf("%30.30s = %lu\n", "hard",
                                kip->intrs[KSTAT_INTR_HARD]);
                        printf("%30.30s = %lu\n", "soft",
                                kip->intrs[KSTAT_INTR_SOFT]);
                        printf("%30.30s = %lu\n", "watchdog",
                                kip->intrs[KSTAT_INTR_WATCHDOG]);
                        printf("%30.30s = %lu\n", "spurious",
                                kip->intrs[KSTAT_INTR_SPURIOUS]);
                        printf("%30.30s = %lu\n", "multsvc",
                                kip->intrs[KSTAT_INTR_MULTSVC]);
                        break;

                    case KSTAT_TYPE_IO:
                        kiop = KSTAT_IO_PTR(ksp);
                        printf("%30.30s = %lu\n", "reads",
                                kiop->reads);
                        printf("%30.30s = %lu\n", "writes",
                                kiop->writes);
                        printf("%30.30s = %llu\n", "bytes read",
                                kiop->nread);
                        printf("%30.30s = %llu\n", "bytes written",
                                kiop->nwritten);
                        printf("%30.30s = %llu\n", "wait time",
                                kiop->wtime);
                        printf("%30.30s = %lu\n", "waitq length",
                                kiop->wcnt);
                        printf("%30.30s = %llu\n", "waitq length-time product",
                                kiop->wlentime);
                        printf("%30.30s = %llu\n", "last waitq update",
                                kiop->wlastupdate);
                        printf("%30.30s = %llu\n", "run time",
                                kiop->rtime);
                        printf("%30.30s = %lu\n", "runq length",
                                kiop->rcnt);
                        printf("%30.30s = %llu\n", "runq length-time product",
                                kiop->rlentime);
                        printf("%30.30s = %llu\n", "last runq update",
                                kiop->rlastupdate);
                        break;

                    case KSTAT_TYPE_TIMER:
                        cur_time = gethrtime();
                        ktp = KSTAT_TIMER_PTR(ksp);
                        for (j = 0; j < ksp->ks_ndata; j++) {
                                printf("%30.30s = %s\n",
                                        "event name", ktp[j].name);
                                printf("%30.30s = %llu\n",
                                        "number of events", ktp[j].num_events);
                                printf("%30.30s = %lld nsec\n",
                                        "elapsed time", ktp[j].elapsed_time);
                                printf("%30.30s = %lld nsec\n",
                                        "shortest event", ktp[j].min_time);
                                printf("%30.30s = %lld nsec\n",
                                        "longest event", ktp[j].max_time);
                                printf("%30.30s = %lld nsec\n",
                                        "last event start time",
                                        ktp[j].start_time);
                                printf("%30.30s = %lld nsec\n",
                                        "last event stop time",
                                        ktp[j].stop_time);
                                printf("%30.30s = %lld nsec\n",
                                        "current time", cur_time);
                        }
                        break;
                }
        }

 
 
 

1. Problem: "Netstat : error in loading shared libraries : undefined symbol : __ register _ frame _ info

Hello,

I have a proble using netstat. When I issue the netstat command I get
the following readout :

Netstat : error in loading shared libraries
: undefined symbol : __ register _ frame _ info

This problem seems to be concurrent with the isntallation of net-tools
1.51-1.

I also get the same message during system boot repeated a couple of
times before it is subdued.

Thank you in advance for your help,
Cedric the Heretic

Heaven: A place where the French are the cooks, the Germans are the engineers, and the British are the policemen.
Hell: A place where the British are the cooks, the French are the engineers, and the Germans are the policemen.

2. Single host, two network device, one hub

3. Kernel panic on 2.4.19 when running netstat (relevant info added)

4. ppp problem

5. kernel static symbols missing in DDB - some info for hackers

6. lpr -w132 wont work/ What's a generic printer for Unix

7. looking for info on /dev/kstat and kernel symbols un Solaris 2.x

8. Training

9. "=>" symbol at end of netstat -rn command

10. Socket buffer overrun info from netstat

11. getting process info from netstat ?

12. AIX 5.1 - Getting the 'netstat -s' info from a C programs

13. Finding netstat info