mirror of
				https://github.com/prometheus/node_exporter.git
				synced 2025-08-20 18:33:52 -07:00 
			
		
		
		
	Remove gauges and convert to NewConstMetric format
This commit is contained in:
		
							parent
							
								
									08bc709c35
								
							
						
					
					
						commit
						e589a2b8af
					
				|  | @ -34,11 +34,6 @@ typedef struct { | ||||||
| 	uint64_t	bytes; | 	uint64_t	bytes; | ||||||
| 	uint64_t	transfers; | 	uint64_t	transfers; | ||||||
| 	uint64_t	blocks; | 	uint64_t	blocks; | ||||||
| 	double		kb_per_transfer; |  | ||||||
| 	double		transfers_per_second; |  | ||||||
| 	double		mb_per_second; |  | ||||||
| 	double		blocks_per_second; |  | ||||||
| 	double		ms_per_transaction; |  | ||||||
| } Stats; | } Stats; | ||||||
| 
 | 
 | ||||||
| int _get_ndevs() { | int _get_ndevs() { | ||||||
|  | @ -87,11 +82,6 @@ Stats _get_stats(int i) { | ||||||
| 	stats.bytes = total_bytes; | 	stats.bytes = total_bytes; | ||||||
| 	stats.transfers = total_transfers; | 	stats.transfers = total_transfers; | ||||||
| 	stats.blocks = total_blocks; | 	stats.blocks = total_blocks; | ||||||
| 	stats.kb_per_transfer =	kb_per_transfer; |  | ||||||
| 	stats.transfers_per_second = transfers_per_second; |  | ||||||
| 	stats.mb_per_second = mb_per_second; |  | ||||||
| 	stats.blocks_per_second = blocks_per_second; |  | ||||||
| 	stats.ms_per_transaction = ms_per_transaction; |  | ||||||
| 
 | 
 | ||||||
|         return stats; |         return stats; | ||||||
| } | } | ||||||
|  | @ -103,14 +93,9 @@ const ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type devstatCollector struct { | type devstatCollector struct { | ||||||
| 	bytes_total             *prometheus.CounterVec | 	bytesDesc     *prometheus.Desc | ||||||
| 	transfers_total         *prometheus.CounterVec | 	transfersDesc *prometheus.Desc | ||||||
| 	blocks_total            *prometheus.CounterVec | 	blocksDesc    *prometheus.Desc | ||||||
| 	bytes_per_transfer      *prometheus.GaugeVec |  | ||||||
| 	transfers_per_second    *prometheus.GaugeVec |  | ||||||
| 	bytes_per_second        *prometheus.GaugeVec |  | ||||||
| 	blocks_per_second       *prometheus.GaugeVec |  | ||||||
| 	seconds_per_transaction *prometheus.GaugeVec |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func init() { | func init() { | ||||||
|  | @ -121,77 +106,20 @@ func init() { | ||||||
| // Device stats.
 | // Device stats.
 | ||||||
| func NewDevstatCollector() (Collector, error) { | func NewDevstatCollector() (Collector, error) { | ||||||
| 	return &devstatCollector{ | 	return &devstatCollector{ | ||||||
| 		bytes_total: prometheus.NewCounterVec( | 		bytesDesc: prometheus.NewDesc( | ||||||
| 			prometheus.CounterOpts{ | 			prometheus.BuildFQName(Namespace, devstatSubsystem, "bytes_total"), | ||||||
| 				Namespace: Namespace, | 			"The total number of bytes transferred for reads and writes on the device.", | ||||||
| 				Subsystem: devstatSubsystem, | 			[]string{"device"}, nil, | ||||||
| 				Name:      "bytes_total", |  | ||||||
| 				Help:      "The total number of bytes transferred for reads and writes on the device.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), | 		), | ||||||
| 		transfers_total: prometheus.NewCounterVec( | 		transfersDesc: prometheus.NewDesc( | ||||||
| 			prometheus.CounterOpts{ | 			prometheus.BuildFQName(Namespace, devstatSubsystem, "transfers_total"), | ||||||
| 				Namespace: Namespace, | 			"The total number of transactions completed.", | ||||||
| 				Subsystem: devstatSubsystem, | 			[]string{"device"}, nil, | ||||||
| 				Name:      "transfers_total", |  | ||||||
| 				Help:      "The total number of transactions completed.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), | 		), | ||||||
| 		blocks_total: prometheus.NewCounterVec( | 		blocksDesc: prometheus.NewDesc( | ||||||
| 			prometheus.CounterOpts{ | 			prometheus.BuildFQName(Namespace, devstatSubsystem, "blocks_total"), | ||||||
| 				Namespace: Namespace, | 			"The total number of bytes given in terms of the devices blocksize.", | ||||||
| 				Subsystem: devstatSubsystem, | 			[]string{"device"}, nil, | ||||||
| 				Name:      "blocks_total", |  | ||||||
| 				Help:      "The total number of bytes given in terms of the devices blocksize.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), |  | ||||||
| 		bytes_per_transfer: prometheus.NewGaugeVec( |  | ||||||
| 			prometheus.GaugeOpts{ |  | ||||||
| 				Namespace: Namespace, |  | ||||||
| 				Subsystem: devstatSubsystem, |  | ||||||
| 				Name:      "bytes_per_transfer", |  | ||||||
| 				Help:      "The average number of bytes per transfer.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), |  | ||||||
| 		transfers_per_second: prometheus.NewGaugeVec( |  | ||||||
| 			prometheus.GaugeOpts{ |  | ||||||
| 				Namespace: Namespace, |  | ||||||
| 				Subsystem: devstatSubsystem, |  | ||||||
| 				Name:      "transfers_per_second", |  | ||||||
| 				Help:      "The average number of transfers per second.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), |  | ||||||
| 		bytes_per_second: prometheus.NewGaugeVec( |  | ||||||
| 			prometheus.GaugeOpts{ |  | ||||||
| 				Namespace: Namespace, |  | ||||||
| 				Subsystem: devstatSubsystem, |  | ||||||
| 				Name:      "bytes_per_second", |  | ||||||
| 				Help:      "The average bytes per second.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), |  | ||||||
| 		blocks_per_second: prometheus.NewGaugeVec( |  | ||||||
| 			prometheus.GaugeOpts{ |  | ||||||
| 				Namespace: Namespace, |  | ||||||
| 				Subsystem: devstatSubsystem, |  | ||||||
| 				Name:      "blocks_per_second", |  | ||||||
| 				Help:      "The average blocks per second.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), |  | ||||||
| 		seconds_per_transaction: prometheus.NewGaugeVec( |  | ||||||
| 			prometheus.GaugeOpts{ |  | ||||||
| 				Namespace: Namespace, |  | ||||||
| 				Subsystem: devstatSubsystem, |  | ||||||
| 				Name:      "seconds_per_transaction", |  | ||||||
| 				Help:      "The average number of seconds per transaction.", |  | ||||||
| 			}, |  | ||||||
| 			[]string{"device"}, |  | ||||||
| 		), | 		), | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
|  | @ -209,24 +137,10 @@ func (c *devstatCollector) Update(ch chan<- prometheus.Metric) (err error) { | ||||||
| 		stats := C._get_stats(i) | 		stats := C._get_stats(i) | ||||||
| 		device := fmt.Sprintf("%s%d", C.GoString(&stats.device[0]), stats.unit) | 		device := fmt.Sprintf("%s%d", C.GoString(&stats.device[0]), stats.unit) | ||||||
| 
 | 
 | ||||||
| 		c.bytes_total.With(prometheus.Labels{"device": device}).Set(float64(stats.bytes)) | 		ch <- prometheus.MustNewConstMetric(c.bytesDesc, prometheus.CounterValue, float64(stats.bytes), device) | ||||||
| 		c.transfers_total.With(prometheus.Labels{"device": device}).Set(float64(stats.transfers)) | 		ch <- prometheus.MustNewConstMetric(c.transfersDesc, prometheus.CounterValue, float64(stats.transfers), device) | ||||||
| 		c.blocks_total.With(prometheus.Labels{"device": device}).Set(float64(stats.blocks)) | 		ch <- prometheus.MustNewConstMetric(c.blocksDesc, prometheus.CounterValue, float64(stats.blocks), device) | ||||||
| 		c.bytes_per_transfer.With(prometheus.Labels{"device": device}).Set(float64(stats.kb_per_transfer) * 1000) |  | ||||||
| 		c.bytes_per_second.With(prometheus.Labels{"device": device}).Set(float64(stats.mb_per_second) * 1000000) |  | ||||||
| 		c.transfers_per_second.With(prometheus.Labels{"device": device}).Set(float64(stats.transfers_per_second)) |  | ||||||
| 		c.blocks_per_second.With(prometheus.Labels{"device": device}).Set(float64(stats.blocks_per_second)) |  | ||||||
| 		c.seconds_per_transaction.With(prometheus.Labels{"device": device}).Set(float64(stats.ms_per_transaction) / 1000) |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	c.bytes_total.Collect(ch) |  | ||||||
| 	c.transfers_total.Collect(ch) |  | ||||||
| 	c.blocks_total.Collect(ch) |  | ||||||
| 	c.bytes_per_transfer.Collect(ch) |  | ||||||
| 	c.bytes_per_second.Collect(ch) |  | ||||||
| 	c.transfers_per_second.Collect(ch) |  | ||||||
| 	c.blocks_per_second.Collect(ch) |  | ||||||
| 	c.seconds_per_transaction.Collect(ch) |  | ||||||
| 
 |  | ||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue