1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// SPDX-License-Identifier: GPL-3.0-or-later
package clickhouse
import (
"errors"
"strconv"
"github.com/netdata/netdata/go/go.d.plugin/pkg/web"
)
const querySystemMetrics = `
SELECT
metric,
value
FROM
system.metrics FORMAT CSVWithNames
`
func (c *ClickHouse) collectSystemMetrics(mx map[string]int64) error {
req, _ := web.NewHTTPRequest(c.Request)
req.URL.RawQuery = makeURLQuery(querySystemMetrics)
px := "metrics_"
var metric string
var n int
err := c.doOKDecodeCSV(req, func(column, value string, lineEnd bool) {
switch column {
case "metric":
metric = value
case "value":
if !wantSystemMetrics[metric] {
return
}
n++
if v, err := strconv.ParseInt(value, 10, 64); err == nil {
mx[px+metric] = v
}
}
})
if err != nil {
return err
}
if n == 0 {
return errors.New("no system metrics data returned")
}
return nil
}
var wantSystemMetrics = map[string]bool{
"Query": true,
"TCPConnection": true,
"HTTPConnection": true,
"MySQLConnection": true,
"PostgreSQLConnection": true,
"InterserverConnection": true,
"MemoryTracking": true,
"QueryPreempted": true,
"ReplicatedFetch": true,
"ReplicatedSend": true,
"ReplicatedChecks": true,
"ReadonlyReplica": true,
"PartsTemporary": true,
"PartsPreActive": true,
"PartsActive": true,
"PartsDeleting": true,
"PartsDeleteOnDestroy": true,
"PartsOutdated": true,
"PartsWide": true,
"PartsCompact": true,
"DistributedSend": true,
"DistributedFilesToInsert": true,
}
|