# bulk export sysctls using bsnmpd



## ziyanm (Jan 16, 2013)

I'd like to export some sysctls (specifically kstat.zfs tree) via SNMP using bsnmp. I found this example in net-mgmt/bsnmp-ucd module's man page:

```
extNames.0 = "lastpid"
extCommand.0 = "/sbin/sysctl -n kern.lastpid"
```

However this method (agent-x?) is inappropriate for exporting an entire sysctl subtree. Has anyone done something like this using either bsnmp or net-mgmt/net-snmp?

I would have thought that exporting sysctls MIBs would be "obvious" functionality to include in bsnmp. Is it perhaps a bad idea? I'm toying with the idea of writing a module to do this.


----------



## quintessence (Jan 20, 2013)

Hello,

Yes, extTable from UCD-SNMP-MIB is a choice as in the example.

Something like:


```
#!/bin/sh
echo '#'
echo '# bsnmp-ucd (8)'
echo '#'
echo 'begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"'
echo '%ucd'

sysctl kstat.zfs > text.txt
value=0;

while read line
    do
        value=`expr $value + 1`;
        echo extNames.$value = \"`cat text.txt | head -n $value | tail -n 1 | tr ':' ' ' | awk '{print $1}'`\"
        echo extCommand.$value = \"/sbin/sysctl -n `cat text.txt | head -n $value | tail -n 1 | tr ':' ' ' | awk '{print $1}'`\"
    done < "text.txt"
```

to generate config for bsnmpd UCD section


```
./test.sh
#
# bsnmp-ucd (8)
#
begemotSnmpdModulePath."ucd" = "/usr/local/lib/snmp_ucd.so"
%ucd
extNames.1 = "kstat.zfs.misc.xuio_stats.onloan_read_buf"
extCommand.1 = "/sbin/sysctl -n kstat.zfs.misc.xuio_stats.onloan_read_buf"
extNames.2 = "kstat.zfs.misc.xuio_stats.onloan_write_buf"
extCommand.2 = "/sbin/sysctl -n kstat.zfs.misc.xuio_stats.onloan_write_buf"
extNames.3 = "kstat.zfs.misc.xuio_stats.read_buf_copied"
extCommand.3 = "/sbin/sysctl -n kstat.zfs.misc.xuio_stats.read_buf_copied"
extNames.4 = "kstat.zfs.misc.xuio_stats.read_buf_nocopy"
extCommand.4 = "/sbin/sysctl -n kstat.zfs.misc.xuio_stats.read_buf_nocopy"
extNames.5 = "kstat.zfs.misc.xuio_stats.write_buf_copied"
extCommand.5 = "/sbin/sysctl -n kstat.zfs.misc.xuio_stats.write_buf_copied"
extNames.6 = "kstat.zfs.misc.xuio_stats.write_buf_nocopy"
extCommand.6 = "/sbin/sysctl -n kstat.zfs.misc.xuio_stats.write_buf_nocopy"
extNames.7 = "kstat.zfs.misc.zfetchstats.hits"
extCommand.7 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.hits"
extNames.8 = "kstat.zfs.misc.zfetchstats.misses"
extCommand.8 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.misses"
extNames.9 = "kstat.zfs.misc.zfetchstats.colinear_hits"
extCommand.9 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.colinear_hits"
extNames.10 = "kstat.zfs.misc.zfetchstats.colinear_misses"
extCommand.10 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.colinear_misses"
extNames.11 = "kstat.zfs.misc.zfetchstats.stride_hits"
extCommand.11 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.stride_hits"
extNames.12 = "kstat.zfs.misc.zfetchstats.stride_misses"
extCommand.12 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.stride_misses"
extNames.13 = "kstat.zfs.misc.zfetchstats.reclaim_successes"
extCommand.13 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.reclaim_successes"
extNames.14 = "kstat.zfs.misc.zfetchstats.reclaim_failures"
extCommand.14 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.reclaim_failures"
extNames.15 = "kstat.zfs.misc.zfetchstats.streams_resets"
extCommand.15 = "/sbin/sysctl -n kstat.zfs.misc.zfetchstats.streams_resets"
...
[snipped because of limitation in the post :)]
...


extNames.72 = "kstat.zfs.misc.arcstats.memory_throttle_count"
extCommand.72 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.memory_throttle_count"
extNames.73 = "kstat.zfs.misc.arcstats.l2_write_trylock_fail"
extCommand.73 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_trylock_fail"
extNames.74 = "kstat.zfs.misc.arcstats.l2_write_passed_headroom"
extCommand.74 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_passed_headroom"
extNames.75 = "kstat.zfs.misc.arcstats.l2_write_spa_mismatch"
extCommand.75 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_spa_mismatch"
extNames.76 = "kstat.zfs.misc.arcstats.l2_write_in_l2"
extCommand.76 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_in_l2"
extNames.77 = "kstat.zfs.misc.arcstats.l2_write_io_in_progress"
extCommand.77 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_io_in_progress"
extNames.78 = "kstat.zfs.misc.arcstats.l2_write_not_cacheable"
extCommand.78 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_not_cacheable"
extNames.79 = "kstat.zfs.misc.arcstats.l2_write_full"
extCommand.79 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_full"
extNames.80 = "kstat.zfs.misc.arcstats.l2_write_buffer_iter"
extCommand.80 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_buffer_iter"
extNames.81 = "kstat.zfs.misc.arcstats.l2_write_pios"
extCommand.81 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_pios"
extNames.82 = "kstat.zfs.misc.arcstats.l2_write_buffer_bytes_scanned"
extCommand.82 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_buffer_bytes_scanned"
extNames.83 = "kstat.zfs.misc.arcstats.l2_write_buffer_list_iter"
extCommand.83 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_buffer_list_iter"
extNames.84 = "kstat.zfs.misc.arcstats.l2_write_buffer_list_null_iter"
extCommand.84 = "/sbin/sysctl -n kstat.zfs.misc.arcstats.l2_write_buffer_list_null_iter"
extNames.85 = "kstat.zfs.misc.vdev_cache_stats.delegations"
extCommand.85 = "/sbin/sysctl -n kstat.zfs.misc.vdev_cache_stats.delegations"
extNames.86 = "kstat.zfs.misc.vdev_cache_stats.hits"
extCommand.86 = "/sbin/sysctl -n kstat.zfs.misc.vdev_cache_stats.hits"
extNames.87 = "kstat.zfs.misc.vdev_cache_stats.misses"
extCommand.87 = "/sbin/sysctl -n kstat.zfs.misc.vdev_cache_stats.misses"
```

`$ ./test.sh > test.txt` and then inserting content from test.txt to /etc/snmpd.config

And then we test what returns extOutput:


```
UCD-SNMP-MIB::extOutput.1 = STRING: 0
UCD-SNMP-MIB::extOutput.2 = STRING: 0
UCD-SNMP-MIB::extOutput.3 = STRING: 0
UCD-SNMP-MIB::extOutput.4 = STRING: 0
UCD-SNMP-MIB::extOutput.5 = STRING: 0
UCD-SNMP-MIB::extOutput.6 = STRING: 185
UCD-SNMP-MIB::extOutput.7 = STRING: 0
UCD-SNMP-MIB::extOutput.8 = STRING: 0
UCD-SNMP-MIB::extOutput.9 = STRING: 0
UCD-SNMP-MIB::extOutput.10 = STRING: 0
UCD-SNMP-MIB::extOutput.11 = STRING: 0
UCD-SNMP-MIB::extOutput.12 = STRING: 0
UCD-SNMP-MIB::extOutput.13 = STRING: 0
UCD-SNMP-MIB::extOutput.14 = STRING: 0
UCD-SNMP-MIB::extOutput.15 = STRING: 0
UCD-SNMP-MIB::extOutput.16 = STRING: 0
UCD-SNMP-MIB::extOutput.17 = STRING: 0
UCD-SNMP-MIB::extOutput.18 = STRING: 4471277
UCD-SNMP-MIB::extOutput.19 = STRING: 229761
UCD-SNMP-MIB::extOutput.20 = STRING: 1805069
UCD-SNMP-MIB::extOutput.21 = STRING: 14523
UCD-SNMP-MIB::extOutput.22 = STRING: 2666162
UCD-SNMP-MIB::extOutput.23 = STRING: 215221
UCD-SNMP-MIB::extOutput.24 = STRING: 0
UCD-SNMP-MIB::extOutput.25 = STRING: 0
UCD-SNMP-MIB::extOutput.26 = STRING: 50
UCD-SNMP-MIB::extOutput.27 = STRING: 17
UCD-SNMP-MIB::extOutput.28 = STRING: 943566
UCD-SNMP-MIB::extOutput.29 = STRING: 44018
UCD-SNMP-MIB::extOutput.30 = STRING: 3527713
UCD-SNMP-MIB::extOutput.31 = STRING: 55246
UCD-SNMP-MIB::extOutput.32 = STRING: 240308
UCD-SNMP-MIB::extOutput.33 = STRING: 8
UCD-SNMP-MIB::extOutput.34 = STRING: 53979
UCD-SNMP-MIB::extOutput.35 = STRING: 37333
UCD-SNMP-MIB::extOutput.36 = STRING: 0
UCD-SNMP-MIB::extOutput.37 = STRING: 6737
UCD-SNMP-MIB::extOutput.38 = STRING: 0
UCD-SNMP-MIB::extOutput.39 = STRING: 1119758336
UCD-SNMP-MIB::extOutput.40 = STRING: 6144
UCD-SNMP-MIB::extOutput.41 = STRING: 135862
UCD-SNMP-MIB::extOutput.42 = STRING: 135862
UCD-SNMP-MIB::extOutput.43 = STRING: 322066
UCD-SNMP-MIB::extOutput.44 = STRING: 40231
UCD-SNMP-MIB::extOutput.45 = STRING: 11
UCD-SNMP-MIB::extOutput.46 = STRING: 1362385408
UCD-SNMP-MIB::extOutput.47 = STRING: 3035213824
UCD-SNMP-MIB::extOutput.48 = STRING: 379401728
UCD-SNMP-MIB::extOutput.49 = STRING: 3035213824
UCD-SNMP-MIB::extOutput.50 = STRING: 918397320
UCD-SNMP-MIB::extOutput.51 = STRING: 34440224
UCD-SNMP-MIB::extOutput.52 = STRING: 406473728
UCD-SNMP-MIB::extOutput.53 = STRING: 477483368
UCD-SNMP-MIB::extOutput.54 = STRING: 0
UCD-SNMP-MIB::extOutput.55 = STRING: 0
UCD-SNMP-MIB::extOutput.56 = STRING: 0
UCD-SNMP-MIB::extOutput.57 = STRING: 0
UCD-SNMP-MIB::extOutput.58 = STRING: 0
UCD-SNMP-MIB::extOutput.59 = STRING: 0
UCD-SNMP-MIB::extOutput.60 = STRING: 0
UCD-SNMP-MIB::extOutput.61 = STRING: 0
UCD-SNMP-MIB::extOutput.62 = STRING: 0
UCD-SNMP-MIB::extOutput.63 = STRING: 0
UCD-SNMP-MIB::extOutput.64 = STRING: 0
UCD-SNMP-MIB::extOutput.65 = STRING: 0
UCD-SNMP-MIB::extOutput.66 = STRING: 0
UCD-SNMP-MIB::extOutput.67 = STRING: 0
UCD-SNMP-MIB::extOutput.68 = STRING: 0
UCD-SNMP-MIB::extOutput.69 = STRING: 0
UCD-SNMP-MIB::extOutput.70 = STRING: 0
UCD-SNMP-MIB::extOutput.71 = STRING: 0
UCD-SNMP-MIB::extOutput.72 = STRING: 0
UCD-SNMP-MIB::extOutput.73 = STRING: 0
UCD-SNMP-MIB::extOutput.74 = STRING: 0
UCD-SNMP-MIB::extOutput.75 = STRING: 0
UCD-SNMP-MIB::extOutput.76 = STRING: 0
UCD-SNMP-MIB::extOutput.77 = STRING: 0
UCD-SNMP-MIB::extOutput.78 = STRING: 2
UCD-SNMP-MIB::extOutput.79 = STRING: 0
UCD-SNMP-MIB::extOutput.80 = STRING: 0
UCD-SNMP-MIB::extOutput.81 = STRING: 0
UCD-SNMP-MIB::extOutput.82 = STRING: 0
UCD-SNMP-MIB::extOutput.83 = STRING: 0
UCD-SNMP-MIB::extOutput.84 = STRING: 0
UCD-SNMP-MIB::extOutput.85 = STRING: 0
UCD-SNMP-MIB::extOutput.86 = STRING: 0
UCD-SNMP-MIB::extOutput.87 = STRING: 0
```


----------



## ziyanm (Jan 21, 2013)

Hi, thanks for the suggestion. This would work, but I was hoping for a more elegant (and performant) solution. In the end I decided to go with collectd, which has a ZFS module instead of SNMP. Apparently OpenBSD has an SNMP daemon in development with some of these capabilities: http://www.packetmischief.ca/openbsd-snmp-mibs/


----------

