Skip to content

Commit

Permalink
orchestrator/clickhouse: add configuration of a /metrics endpoint
Browse files Browse the repository at this point in the history
This is optional and not enabled by default.
  • Loading branch information
vincentbernat committed Nov 12, 2023
1 parent 9db516e commit 403464f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/akvorado.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ clickhouse:
consumers: 4
servers:
- clickhouse:9000
prometheus-endpoint: /metrics
asns:
64501: ACME Corporation
networks:
Expand Down
2 changes: 2 additions & 0 deletions console/data/docs/02-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,8 @@ provided:
- `system-log-ttl` defines the TTL for system log tables. Set to 0 to disable.
As these tables are partitioned by month, it's useless to use a too low value.
The default value is 30 days. This requires a restart of ClickHouse.
- `prometheus-endpoint` defines the endpoint to configure to expose ClickHouse
metrics to Prometheus. When not defined, this is left unconfigured.
- `networks` maps subnets to attributes. Attributes are `name`,
`role`, `site`, `region`, and `tenant`. They are exposed as
`SrcNetName`, `DstNetName`, `SrcNetRole`, `DstNetRole`, etc.
Expand Down
1 change: 1 addition & 0 deletions console/data/docs/99-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ identified with a specific icon:

- 💥 *inlet*: many metrics renamed to match [Prometheus best practices](https://prometheus.io/docs/practices/naming/)
- 🌱 *docker*: update ClickHouse to 23.8 (this is not mandatory)
- 🌱 *orchestrator*: add `orchestrator``clickhouse``prometheus-endpoint` to configure an endpoint to expose metrics to Prometheus

## 1.9.1 - 2023-10-06

Expand Down
5 changes: 5 additions & 0 deletions docker/grafana/provisioning/datasources/akvorado.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ datasources:
access: proxy
url: http://prometheus:9090/prometheus
uid: PBFA97CFB590B2093
- name: Akvorado
type: marcusolsson-json-datasource
access: direct
url: /api/v0/console/lines
uid: P92BCD8FE492171BD
isDefault: true
3 changes: 3 additions & 0 deletions orchestrator/clickhouse/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Configuration struct {
MaxPartitions int `validate:"isdefault|min=1"`
// SystemLogTTL is the TTL to set for system log tables.
SystemLogTTL time.Duration `validate:"isdefault|min=1m"`
// PrometheusEndpoint defines the endpoint ClickHouse can use to expose
// metrics to Prometheus. If not defined, this is not configured.
PrometheusEndpoint string
// ASNs is a mapping from AS numbers to names. It replaces or
// extends the builtin list of AS numbers.
ASNs map[uint32]string
Expand Down
18 changes: 14 additions & 4 deletions orchestrator/clickhouse/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,25 @@ cat > /etc/clickhouse-server/config.d/akvorado.xml <<'EOCONFIG'
</{{ $table }}>
{{- end }}
{{- end }}
{{- if ne .PrometheusEndpoint "" }}
<prometheus>
<endpoint>{{ .PrometheusEndpoint }}</endpoint>
<metrics>true</metrics>
<events>true</events>
<asynchronous_metrics>true</asynchronous_metrics>
</prometheus>
{{- end }}
</clickhouse>
EOCONFIG
`))
)

type initShVariables struct {
FlowSchemaHash string
FlowSchema string
SystemLogTTL int
SystemLogTables []string
FlowSchemaHash string
FlowSchema string
SystemLogTTL int
SystemLogTables []string
PrometheusEndpoint string
}

func (c *Component) addHandlerEmbedded(url string, path string) {
Expand Down Expand Up @@ -82,6 +91,7 @@ func (c *Component) registerHTTPHandlers() error {
"query_thread_log",
"trace_log",
},
PrometheusEndpoint: c.config.PrometheusEndpoint,
}); err != nil {
c.r.Err(err).Msg("unable to serialize init.sh")
http.Error(w, fmt.Sprintf("Unable to serialize init.sh"), http.StatusInternalServerError)
Expand Down

0 comments on commit 403464f

Please sign in to comment.