mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	ZFS Collector: Add xuio_stats functionality
Signed-Off-By: Joe Handzik <joseph.t.handzik@hpe.com>
This commit is contained in:
		
							parent
							
								
									3c9e779989
								
							
						
					
					
						commit
						05048c067d
					
				|  | @ -2392,6 +2392,24 @@ node_zfsVdevCache_hits 0 | |||
| # HELP node_zfsVdevCache_misses kstat.zfs.misc.vdev_cache_stats.misses | ||||
| # TYPE node_zfsVdevCache_misses untyped | ||||
| node_zfsVdevCache_misses 0 | ||||
| # HELP node_zfsXuio_onloan_read_buf kstat.zfs.misc.xuio_stats.onloan_read_buf | ||||
| # TYPE node_zfsXuio_onloan_read_buf untyped | ||||
| node_zfsXuio_onloan_read_buf 32 | ||||
| # HELP node_zfsXuio_onloan_write_buf kstat.zfs.misc.xuio_stats.onloan_write_buf | ||||
| # TYPE node_zfsXuio_onloan_write_buf untyped | ||||
| node_zfsXuio_onloan_write_buf 0 | ||||
| # HELP node_zfsXuio_read_buf_copied kstat.zfs.misc.xuio_stats.read_buf_copied | ||||
| # TYPE node_zfsXuio_read_buf_copied untyped | ||||
| node_zfsXuio_read_buf_copied 0 | ||||
| # HELP node_zfsXuio_read_buf_nocopy kstat.zfs.misc.xuio_stats.read_buf_nocopy | ||||
| # TYPE node_zfsXuio_read_buf_nocopy untyped | ||||
| node_zfsXuio_read_buf_nocopy 0 | ||||
| # HELP node_zfsXuio_write_buf_copied kstat.zfs.misc.xuio_stats.write_buf_copied | ||||
| # TYPE node_zfsXuio_write_buf_copied untyped | ||||
| node_zfsXuio_write_buf_copied 0 | ||||
| # HELP node_zfsXuio_write_buf_nocopy kstat.zfs.misc.xuio_stats.write_buf_nocopy | ||||
| # TYPE node_zfsXuio_write_buf_nocopy untyped | ||||
| node_zfsXuio_write_buf_nocopy 0 | ||||
| # HELP node_zfsZil_zil_commit_count kstat.zfs.misc.zil.zil_commit_count | ||||
| # TYPE node_zfsZil_zil_commit_count untyped | ||||
| node_zfsZil_zil_commit_count 10 | ||||
|  |  | |||
							
								
								
									
										8
									
								
								collector/fixtures/proc/spl/kstat/zfs/xuio_stats
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								collector/fixtures/proc/spl/kstat/zfs/xuio_stats
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,8 @@ | |||
| 2 1 0x01 6 288 8009100742 353415816865654 | ||||
| name                            type data | ||||
| onloan_read_buf                 4    32 | ||||
| onloan_write_buf                4    0 | ||||
| read_buf_copied                 4    0 | ||||
| read_buf_nocopy                 4    0 | ||||
| write_buf_copied                4    0 | ||||
| write_buf_nocopy                4    0 | ||||
|  | @ -36,6 +36,7 @@ type zfsSubsystemName string | |||
| const ( | ||||
| 	arc            = zfsSubsystemName("zfsArc") | ||||
| 	vdevCache      = zfsSubsystemName("zfsVdevCache") | ||||
| 	xuio           = zfsSubsystemName("zfsXuio") | ||||
| 	zfetch         = zfsSubsystemName("zfsFetch") | ||||
| 	zil            = zfsSubsystemName("zfsZil") | ||||
| 	zpoolSubsystem = zfsSubsystemName("zfsPool") | ||||
|  | @ -86,6 +87,10 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) (err error) { | |||
| 	err = c.updateVdevCacheStats(ch) | ||||
| 	if err != nil { return err } | ||||
| 
 | ||||
| 	// XuioStats
 | ||||
| 	err = c.updateXuioStats(ch) | ||||
| 	if err != nil { return err } | ||||
| 
 | ||||
| 	// Pool stats
 | ||||
| 	return c.updatePoolStats(ch) | ||||
| } | ||||
|  |  | |||
|  | @ -31,6 +31,7 @@ const ( | |||
| 	zfsArcstatsExt       = "arcstats" | ||||
| 	zfsFetchstatsExt     = "zfetchstats" | ||||
| 	zfsVdevCacheStatsExt = "vdev_cache_stats" | ||||
| 	zfsXuioStatsExt      = "xuio_stats" | ||||
| 	zfsZilExt            = "zil" | ||||
| ) | ||||
| 
 | ||||
|  | @ -91,6 +92,18 @@ func (c *zfsCollector) updateVdevCacheStats(ch chan<- prometheus.Metric) (err er | |||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (c *zfsCollector) updateXuioStats(ch chan<- prometheus.Metric) (err error) { | ||||
| 	file, err := c.openProcFile(filepath.Join(zfsProcpathBase, zfsXuioStatsExt)) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	defer file.Close() | ||||
| 
 | ||||
| 	return c.parseProcfsFile(file, zfsXuioStatsExt, func(s zfsSysctl, v zfsMetricValue) { | ||||
| 		ch <- c.constSysctlMetric(xuio, s, v) | ||||
| 	}) | ||||
| } | ||||
| 
 | ||||
| func (c *zfsCollector) parseProcfsFile(reader io.Reader, fmt_ext string, handler func(zfsSysctl, zfsMetricValue)) (err error) { | ||||
| 	scanner := bufio.NewScanner(reader) | ||||
| 
 | ||||
|  |  | |||
|  | @ -161,3 +161,39 @@ func TestVdevCacheStatsParsing(t *testing.T) { | |||
| 		t.Fatal("VdevCacheStats parsing handler was not called for some expected sysctls") | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestXuioStatsParsing(t *testing.T) { | ||||
| 	xuioStatsFile, err := os.Open("fixtures/proc/spl/kstat/zfs/xuio_stats") | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| 	defer xuioStatsFile.Close() | ||||
| 
 | ||||
| 	c := zfsCollector{} | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| 
 | ||||
| 	handlerCalled := false | ||||
| 	err = c.parseProcfsFile(xuioStatsFile, "xuio_stats", func(s zfsSysctl, v zfsMetricValue) { | ||||
| 
 | ||||
| 		if s != zfsSysctl("kstat.zfs.misc.xuio_stats.onloan_read_buf") { | ||||
| 			return | ||||
| 		} | ||||
| 
 | ||||
| 		handlerCalled = true | ||||
| 
 | ||||
| 		if v != zfsMetricValue(32) { | ||||
| 			t.Fatalf("Incorrect value parsed from procfs data") | ||||
| 		} | ||||
| 
 | ||||
| 	}) | ||||
| 
 | ||||
| 	if err != nil { | ||||
| 		t.Fatal(err) | ||||
| 	} | ||||
| 
 | ||||
| 	if !handlerCalled { | ||||
| 		t.Fatal("XuioStats parsing handler was not called for some expected sysctls") | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue