feat(inputs.influxdb): Collect uptime statistics (#12493)
This commit is contained in:
parent
5174fb1e94
commit
40aa899fa8
|
|
@ -123,6 +123,12 @@ type memstats struct {
|
||||||
GCCPUFraction float64 `json:"GCCPUFraction"`
|
GCCPUFraction float64 `json:"GCCPUFraction"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type system struct {
|
||||||
|
CurrentTime string `json:"currentTime"`
|
||||||
|
Started string `json:"started"`
|
||||||
|
Uptime uint64 `json:"uptime"`
|
||||||
|
}
|
||||||
|
|
||||||
// Gathers data from a particular URL
|
// Gathers data from a particular URL
|
||||||
// Parameters:
|
// Parameters:
|
||||||
//
|
//
|
||||||
|
|
@ -189,6 +195,24 @@ func (i *InfluxDB) gatherURL(
|
||||||
}
|
}
|
||||||
|
|
||||||
if keyStr, ok := key.(string); ok {
|
if keyStr, ok := key.(string); ok {
|
||||||
|
if keyStr == "system" {
|
||||||
|
var p system
|
||||||
|
if err := dec.Decode(&p); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
acc.AddFields("influxdb_system",
|
||||||
|
map[string]interface{}{
|
||||||
|
"current_time": p.CurrentTime,
|
||||||
|
"started": p.Started,
|
||||||
|
"uptime": p.Uptime,
|
||||||
|
},
|
||||||
|
map[string]string{
|
||||||
|
"url": url,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if keyStr == "memstats" {
|
if keyStr == "memstats" {
|
||||||
var m memstats
|
var m memstats
|
||||||
if err := dec.Decode(&m); err != nil {
|
if err := dec.Decode(&m); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ func TestInfluxDB(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
require.NoError(t, acc.GatherError(plugin.Gather))
|
require.NoError(t, acc.GatherError(plugin.Gather))
|
||||||
|
|
||||||
require.Len(t, acc.Metrics, 34)
|
require.Len(t, acc.Metrics, 35)
|
||||||
|
|
||||||
fields := map[string]interface{}{
|
fields := map[string]interface{}{
|
||||||
"heap_inuse": int64(18046976),
|
"heap_inuse": int64(18046976),
|
||||||
|
|
@ -119,6 +119,13 @@ func TestInfluxDB(t *testing.T) {
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, "influxdb_memstats", fields, tags)
|
acc.AssertContainsTaggedFields(t, "influxdb_memstats", fields, tags)
|
||||||
|
|
||||||
|
fields = map[string]interface{}{
|
||||||
|
"current_time": "2023-01-11T16:51:52.723166944Z",
|
||||||
|
"started": "2023-01-11T16:51:23.355766023Z",
|
||||||
|
"uptime": uint64(29),
|
||||||
|
}
|
||||||
|
acc.AssertContainsTaggedFields(t, "influxdb_system", fields, tags)
|
||||||
|
|
||||||
acc.AssertContainsTaggedFields(t, "influxdb",
|
acc.AssertContainsTaggedFields(t, "influxdb",
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"n_shards": 1,
|
"n_shards": 1,
|
||||||
|
|
@ -147,12 +154,22 @@ func TestInfluxDB2(t *testing.T) {
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
require.NoError(t, acc.GatherError(plugin.Gather))
|
require.NoError(t, acc.GatherError(plugin.Gather))
|
||||||
|
|
||||||
require.Len(t, acc.Metrics, 34)
|
require.Len(t, acc.Metrics, 35)
|
||||||
|
|
||||||
acc.AssertContainsTaggedFields(t, "influxdb",
|
acc.AssertContainsTaggedFields(t, "influxdb",
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"n_shards": 1,
|
"n_shards": 1,
|
||||||
}, map[string]string{})
|
}, map[string]string{})
|
||||||
|
|
||||||
|
fields := map[string]interface{}{
|
||||||
|
"current_time": "2023-01-11T17:04:59.928454705Z",
|
||||||
|
"started": "2023-01-11T16:51:23.355766023Z",
|
||||||
|
"uptime": uint64(816),
|
||||||
|
}
|
||||||
|
tags := map[string]string{
|
||||||
|
"url": fakeInfluxServer.URL + "/endpoint",
|
||||||
|
}
|
||||||
|
acc.AssertContainsTaggedFields(t, "influxdb_system", fields, tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestErrorHandling(t *testing.T) {
|
func TestErrorHandling(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,11 @@
|
||||||
"numSeries": 1
|
"numSeries": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"system": {
|
||||||
|
"currentTime": "2023-01-11T16:51:52.723166944Z",
|
||||||
|
"started": "2023-01-11T16:51:23.355766023Z",
|
||||||
|
"uptime": 29
|
||||||
|
},
|
||||||
"memstats": {
|
"memstats": {
|
||||||
"Alloc": 17034016,
|
"Alloc": 17034016,
|
||||||
"TotalAlloc": 201739016,
|
"TotalAlloc": 201739016,
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,11 @@
|
||||||
"numSeries": 1
|
"numSeries": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"system": {
|
||||||
|
"currentTime": "2023-01-11T17:04:59.928454705Z",
|
||||||
|
"started": "2023-01-11T16:51:23.355766023Z",
|
||||||
|
"uptime": 816
|
||||||
|
},
|
||||||
"memstats": {
|
"memstats": {
|
||||||
"Alloc": 17034016,
|
"Alloc": 17034016,
|
||||||
"TotalAlloc": 201739016,
|
"TotalAlloc": 201739016,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue