Skip to content

Commit

Permalink
Add the metric.IsSessionExpired metric to the exporter.
Browse files Browse the repository at this point in the history
This metric reports which replicated tables have seen their Zookeeper
sessions expired. This metric is labeled by database and table, plus
additional labels that are added by default (e.g. ClickHouse hostname).
  • Loading branch information
teralype committed Oct 24, 2019
1 parent 58e4d4d commit 6ddddcf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
47 changes: 28 additions & 19 deletions pkg/apis/metrics/clickhouse_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ const (
'metric.DiskFreeBytes' AS metric,
toString(filesystemFree()) AS value,
'Free disk space available at file system' AS description,
'gauge' AS type
'gauge' AS type
UNION ALL
SELECT
concat('metric.IsSessionExpired', '{', 'database=', database, ',table=', table, '}') AS metric,
toString(is_session_expired) AS value,
'Whether the Zookeeper session has expired' AS description,
'gauge' AS type
FROM system.replicas
`

queryTableSizesSQL = `
Expand All @@ -85,13 +92,15 @@ const (
GROUP BY database, table`
)

// ClickHouseFetcher describes a fetcher for a particular ClickHouse host
type ClickHouseFetcher struct {
Hostname string
Username string
Password string
Port int
}

// NewClickHouseFetcher creates a new fetcher to retrieve metrics from a particular ClickHouse host
func NewClickHouseFetcher(hostname, username, password string, port int) *ClickHouseFetcher {
return &ClickHouseFetcher{
Hostname: hostname,
Expand All @@ -110,16 +119,16 @@ func (f *ClickHouseFetcher) newConn() *clickhouse.Conn {
func (f *ClickHouseFetcher) clickHouseQueryMetrics() ([][]string, error) {
data := make([][]string, 0)
conn := f.newConn()
if rows, err := conn.Query(heredoc.Doc(queryMetricsSQL)); err != nil {
rows, err := conn.Query(heredoc.Doc(queryMetricsSQL))
if err != nil {
return nil, err
} else {
for rows.Next() {
var metric, value, description, _type string
if err := rows.Scan(&metric, &value, &description, &_type); err == nil {
data = append(data, []string{metric, value, description, _type})
} else {
// Skip erroneous line
}
}
for rows.Next() {
var metric, value, description, _type string
if err := rows.Scan(&metric, &value, &description, &_type); err == nil {
data = append(data, []string{metric, value, description, _type})
} else {
// Skip erroneous line
}
}
return data, nil
Expand All @@ -130,16 +139,16 @@ func (f *ClickHouseFetcher) clickHouseQueryMetrics() ([][]string, error) {
func (f *ClickHouseFetcher) clickHouseQueryTableSizes() ([][]string, error) {
data := make([][]string, 0)
conn := f.newConn()
if rows, err := conn.Query(heredoc.Doc(queryTableSizesSQL)); err != nil {
rows, err := conn.Query(heredoc.Doc(queryTableSizesSQL))
if err != nil {
return nil, err
} else {
for rows.Next() {
var database, table, partitions, parts, bytes, uncompressed, _rows string
if err := rows.Scan(&database, &table, &partitions, &parts, &bytes, &uncompressed, &_rows); err == nil {
data = append(data, []string{database, table, partitions, parts, bytes, uncompressed, _rows})
} else {
// Skip erroneous line
}
}
for rows.Next() {
var database, table, partitions, parts, bytes, uncompressed, _rows string
if err := rows.Scan(&database, &table, &partitions, &parts, &bytes, &uncompressed, &_rows); err == nil {
data = append(data, []string{database, table, partitions, parts, bytes, uncompressed, _rows})
} else {
// Skip erroneous line
}
}
return data, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/metrics/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (e *Exporter) newFetcher(hostname string) *ClickHouseFetcher {
return NewClickHouseFetcher(hostname, e.chAccessInfo.Username, e.chAccessInfo.Password, e.chAccessInfo.Port)
}

// Ensure hostnames of the Pods from CHI object included into chopmetrics.Exporter state
// UpdateWatch ensures hostnames of the Pods from CHI object included into chopmetrics.Exporter state
func (e *Exporter) UpdateWatch(namespace, chiName string, hostnames []string) {
chi := &WatchedChi{
Namespace: namespace,
Expand Down

0 comments on commit 6ddddcf

Please sign in to comment.