summaryrefslogtreecommitdiffstats
path: root/src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go')
-rw-r--r--src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go b/src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go
new file mode 100644
index 000000000..26891f808
--- /dev/null
+++ b/src/go/plugin/go.d/modules/clickhouse/collect_system_metrics.go
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package clickhouse
+
+import (
+ "errors"
+ "strconv"
+
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/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,
+}