Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7af75a

Browse files
committed
Prometheus flag
1 parent 322f7e8 commit c7af75a

File tree

10 files changed

+50
-10
lines changed

10 files changed

+50
-10
lines changed

cli/server.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,11 +844,13 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
844844
}
845845
defer closeWorkspacesFunc()
846846

847-
closeAgentStatsFunc, err := prometheusmetrics.AgentStats(ctx, logger, options.PrometheusRegistry, options.Database, time.Now(), 0)
848-
if err != nil {
849-
return xerrors.Errorf("register agent stats prometheus metric: %w", err)
847+
if cfg.Prometheus.CollectAgentStats {
848+
closeAgentStatsFunc, err := prometheusmetrics.AgentStats(ctx, logger, options.PrometheusRegistry, options.Database, time.Now(), 0)
849+
if err != nil {
850+
return xerrors.Errorf("register agent stats prometheus metric: %w", err)
851+
}
852+
defer closeAgentStatsFunc()
850853
}
851-
defer closeAgentStatsFunc()
852854

853855
//nolint:revive
854856
defer serveHandler(ctx, logger, promhttp.InstrumentMetricHandler(

cli/testdata/coder_server_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ Use a YAML configuration file when your server launch become unwieldy.
9090
--prometheus-address host:port, $CODER_PROMETHEUS_ADDRESS (default: 127.0.0.1:2112)
9191
The bind address to serve prometheus metrics.
9292

93+
--prometheus-collect-agent-stats bool, $CODER_PROMETHEUS_COLLECT_AGENT_STATS
94+
Collect agent stats (may increase charges for metrics storage) .
95+
9396
--prometheus-enable bool, $CODER_PROMETHEUS_ENABLE
9497
Serve prometheus metrics on the address defined by prometheus address.
9598

cli/testdata/server-config.yaml.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ introspection:
146146
# The bind address to serve prometheus metrics.
147147
# (default: 127.0.0.1:2112, type: host:port)
148148
address: 127.0.0.1:2112
149+
# Collect agent stats (may increase charges for metrics storage) .
150+
# (default: <unset>, type: bool)
151+
collect_agent_stats: false
149152
pprof:
150153
# Serve pprof metrics on the address defined by pprof address.
151154
# (default: <unset>, type: bool)

coderd/apidoc/docs.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/deployment.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ type DERPConfig struct {
225225
}
226226

227227
type PrometheusConfig struct {
228-
Enable clibase.Bool `json:"enable" typescript:",notnull"`
229-
Address clibase.HostPort `json:"address" typescript:",notnull"`
228+
Enable clibase.Bool `json:"enable" typescript:",notnull"`
229+
Address clibase.HostPort `json:"address" typescript:",notnull"`
230+
CollectAgentStats clibase.Bool `json:"collect_agent_stats" typescript:",notnull"`
230231
}
231232

232233
type PprofConfig struct {
@@ -722,6 +723,15 @@ when required by your organization's security policy.`,
722723
Group: &deploymentGroupIntrospectionPrometheus,
723724
YAML: "address",
724725
},
726+
{
727+
Name: "Prometheus Collect Agent Stats",
728+
Description: "Collect agent stats (may increase charges for metrics storage) .",
729+
Flag: "prometheus-collect-agent-stats",
730+
Env: "CODER_PROMETHEUS_COLLECT_AGENT_STATS",
731+
Value: &c.Prometheus.CollectAgentStats,
732+
Group: &deploymentGroupIntrospectionPrometheus,
733+
YAML: "collect_agent_stats",
734+
},
725735
// Pprof settings
726736
{
727737
Name: "pprof Enable",

docs/api/general.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \
271271
"host": "string",
272272
"port": "string"
273273
},
274+
"collect_agent_stats": true,
274275
"enable": true
275276
},
276277
"provisioner": {

docs/api/schemas.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
19011901
"host": "string",
19021902
"port": "string"
19031903
},
1904+
"collect_agent_stats": true,
19041905
"enable": true
19051906
},
19061907
"provisioner": {
@@ -2244,6 +2245,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
22442245
"host": "string",
22452246
"port": "string"
22462247
},
2248+
"collect_agent_stats": true,
22472249
"enable": true
22482250
},
22492251
"provisioner": {
@@ -3155,16 +3157,18 @@ Parameter represents a set value for the scope.
31553157
"host": "string",
31563158
"port": "string"
31573159
},
3160+
"collect_agent_stats": true,
31583161
"enable": true
31593162
}
31603163
```
31613164

31623165
### Properties
31633166

3164-
| Name | Type | Required | Restrictions | Description |
3165-
| --------- | ------------------------------------ | -------- | ------------ | ----------- |
3166-
| `address` | [clibase.HostPort](#clibasehostport) | false | | |
3167-
| `enable` | boolean | false | | |
3167+
| Name | Type | Required | Restrictions | Description |
3168+
| --------------------- | ------------------------------------ | -------- | ------------ | ----------- |
3169+
| `address` | [clibase.HostPort](#clibasehostport) | false | | |
3170+
| `collect_agent_stats` | boolean | false | | |
3171+
| `enable` | boolean | false | | |
31683172

31693173
## codersdk.ProvisionerConfig
31703174

docs/cli/server.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,16 @@ URL of a PostgreSQL database. If empty, PostgreSQL binaries will be downloaded f
555555

556556
The bind address to serve prometheus metrics.
557557

558+
### --prometheus-collect-agent-stats
559+
560+
| | |
561+
| ----------- | --------------------------------------------------------- |
562+
| Type | <code>bool</code> |
563+
| Environment | <code>$CODER_PROMETHEUS_COLLECT_AGENT_STATS</code> |
564+
| YAML | <code>introspection.prometheus.collect_agent_stats</code> |
565+
566+
Collect agent stats (may increase charges for metrics storage) .
567+
558568
### --prometheus-enable
559569

560570
| | |

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ export interface PrometheusConfig {
627627
// Named type "github.com/coder/coder/cli/clibase.HostPort" unknown, using "any"
628628
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- External type
629629
readonly address: any
630+
readonly collect_agent_stats: boolean
630631
}
631632

632633
// From codersdk/deployment.go

0 commit comments

Comments
 (0)