mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-11-04 10:45:06 +01:00 
			
		
		
		
	Refactor: Use int64 type for absolut values
This commit is contained in:
		@@ -12,6 +12,12 @@
 | 
				
			|||||||
            "proc_total"
 | 
					            "proc_total"
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    "netstat": {
 | 
				
			||||||
 | 
					        "include_devices": [
 | 
				
			||||||
 | 
					            "enp5s0"
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        "send_derived_values": true
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    "numastats": {},
 | 
					    "numastats": {},
 | 
				
			||||||
    "nvidia": {},
 | 
					    "nvidia": {},
 | 
				
			||||||
    "tempstat": {
 | 
					    "tempstat": {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,7 +26,7 @@ type NetstatCollectorMetric struct {
 | 
				
			|||||||
	index     int
 | 
						index     int
 | 
				
			||||||
	tags      map[string]string
 | 
						tags      map[string]string
 | 
				
			||||||
	rate_tags map[string]string
 | 
						rate_tags map[string]string
 | 
				
			||||||
	lastValue float64
 | 
						lastValue int64
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type NetstatCollector struct {
 | 
					type NetstatCollector struct {
 | 
				
			||||||
@@ -113,28 +113,28 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
 | 
				
			|||||||
				{
 | 
									{
 | 
				
			||||||
					name:      "net_bytes_in",
 | 
										name:      "net_bytes_in",
 | 
				
			||||||
					index:     fieldReceiveBytes,
 | 
										index:     fieldReceiveBytes,
 | 
				
			||||||
					lastValue: 0,
 | 
										lastValue: -1,
 | 
				
			||||||
					tags:      tags_unit_byte,
 | 
										tags:      tags_unit_byte,
 | 
				
			||||||
					rate_tags: tags_unit_byte_per_sec,
 | 
										rate_tags: tags_unit_byte_per_sec,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					name:      "net_pkts_in",
 | 
										name:      "net_pkts_in",
 | 
				
			||||||
					index:     fieldReceivePackets,
 | 
										index:     fieldReceivePackets,
 | 
				
			||||||
					lastValue: 0,
 | 
										lastValue: -1,
 | 
				
			||||||
					tags:      tags_unit_pkts,
 | 
										tags:      tags_unit_pkts,
 | 
				
			||||||
					rate_tags: tags_unit_pkts_per_sec,
 | 
										rate_tags: tags_unit_pkts_per_sec,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					name:      "net_bytes_out",
 | 
										name:      "net_bytes_out",
 | 
				
			||||||
					index:     fieldTransmitBytes,
 | 
										index:     fieldTransmitBytes,
 | 
				
			||||||
					lastValue: 0,
 | 
										lastValue: -1,
 | 
				
			||||||
					tags:      tags_unit_byte,
 | 
										tags:      tags_unit_byte,
 | 
				
			||||||
					rate_tags: tags_unit_byte_per_sec,
 | 
										rate_tags: tags_unit_byte_per_sec,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					name:      "net_pkts_out",
 | 
										name:      "net_pkts_out",
 | 
				
			||||||
					index:     fieldTransmitPackets,
 | 
										index:     fieldTransmitPackets,
 | 
				
			||||||
					lastValue: 0,
 | 
										lastValue: -1,
 | 
				
			||||||
					tags:      tags_unit_pkts,
 | 
										tags:      tags_unit_pkts,
 | 
				
			||||||
					rate_tags: tags_unit_pkts_per_sec,
 | 
										rate_tags: tags_unit_pkts_per_sec,
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
@@ -186,28 +186,27 @@ func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
 | 
				
			|||||||
		// Check if device is a included device
 | 
							// Check if device is a included device
 | 
				
			||||||
		if devmetrics, ok := m.matches[dev]; ok {
 | 
							if devmetrics, ok := m.matches[dev]; ok {
 | 
				
			||||||
			for i := range devmetrics {
 | 
								for i := range devmetrics {
 | 
				
			||||||
				data := &devmetrics[i]
 | 
									metric := &devmetrics[i]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Read value
 | 
									// Read value
 | 
				
			||||||
				v, err := strconv.ParseFloat(f[data.index], 64)
 | 
									v, err := strconv.ParseInt(f[metric.index], 10, 64)
 | 
				
			||||||
				if err != nil {
 | 
									if err != nil {
 | 
				
			||||||
					continue
 | 
										continue
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if m.config.SendAbsoluteValues {
 | 
									if m.config.SendAbsoluteValues {
 | 
				
			||||||
					if y, err := lp.New(data.name, data.tags, m.meta, map[string]interface{}{"value": v}, now); err == nil {
 | 
										if y, err := lp.New(metric.name, metric.tags, m.meta, map[string]interface{}{"value": v}, now); err == nil {
 | 
				
			||||||
						output <- y
 | 
											output <- y
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if m.config.SendDerivedValues {
 | 
									if m.config.SendDerivedValues {
 | 
				
			||||||
					rate := (v - data.lastValue) / timeDiff
 | 
										if metric.lastValue >= 0 {
 | 
				
			||||||
					if data.lastValue == 0 {
 | 
											rate := float64(v-metric.lastValue) / timeDiff
 | 
				
			||||||
						rate = 0
 | 
											if y, err := lp.New(metric.name+"_bw", metric.rate_tags, m.meta, map[string]interface{}{"value": rate}, now); err == nil {
 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
					data.lastValue = v
 | 
					 | 
				
			||||||
					if y, err := lp.New(data.name+"_bw", data.rate_tags, m.meta, map[string]interface{}{"value": rate}, now); err == nil {
 | 
					 | 
				
			||||||
							output <- y
 | 
												output <- y
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
 | 
										metric.lastValue = v
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user