Merge pull request #142654 from yrd/prometheus-config-modules

nixos/prometheus: add new configuration options

authored by Bas van Dijk and committed by GitHub dd1edacb faf28d50

+1139 -281
+1139 -281
nixos/modules/services/monitoring/prometheus/default.nix
··· 37 pkgs.runCommandLocal 38 "${name}-${replaceStrings [" "] [""] what}-checked" 39 { buildInputs = [ cfg.package ]; } '' 40 - ln -s ${file} $out 41 - promtool ${what} $out 42 - '' else file; 43 44 # Pretty-print JSON to a file 45 writePrettyJSON = name: x: 46 - pkgs.runCommandLocal name {} '' 47 echo '${builtins.toJSON x}' | ${pkgs.jq}/bin/jq . > $out 48 ''; 49 ··· 63 }; 64 }; 65 66 - prometheusYml = let 67 - yml = if cfg.configText != null then 68 - pkgs.writeText "prometheus.yml" cfg.configText 69 - else generatedPrometheusYml; 70 - in promtoolCheck "check config" "prometheus.yml" yml; 71 72 cmdlineArgs = cfg.extraFlags ++ [ 73 "--storage.tsdb.path=${workingDir}/data/" ··· 80 "--alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}" 81 "--alertmanager.timeout=${toString cfg.alertmanagerTimeout}s" 82 ] ++ optional (cfg.webExternalUrl != null) "--web.external-url=${cfg.webExternalUrl}" 83 - ++ optional (cfg.retentionTime != null) "--storage.tsdb.retention.time=${cfg.retentionTime}"; 84 85 filterValidPrometheus = filterAttrsListRecursive (n: v: !(n == "_module" || v == null)); 86 filterAttrsListRecursive = pred: x: 87 if isAttrs x then 88 - listToAttrs ( 89 - concatMap (name: 90 - let v = x.${name}; in 91 - if pred name v then [ 92 - (nameValuePair name (filterAttrsListRecursive pred v)) 93 - ] else [] 94 - ) (attrNames x) 95 - ) 96 else if isList x then 97 map (filterAttrsListRecursive pred) x 98 else x; 99 100 - mkDefOpt = type : defaultStr : description : mkOpt type (description + '' 101 102 Defaults to <literal>${defaultStr}</literal> in prometheus 103 when set to <literal>null</literal>. 104 ''); 105 106 - mkOpt = type : description : mkOption { 107 type = types.nullOr type; 108 default = null; 109 inherit description; 110 }; 111 112 promTypes.globalConfig = types.submodule { 113 options = { 114 scrape_interval = mkDefOpt types.str "1m" '' ··· 131 }; 132 }; 133 134 - promTypes.remote_read = types.submodule { 135 options = { 136 - url = mkOption { 137 type = types.str; 138 description = '' 139 - ServerName extension to indicate the name of the server. 140 - http://tools.ietf.org/html/rfc4366#section-3.1 141 ''; 142 }; 143 - name = mkOpt types.str '' 144 - Name of the remote read config, which if specified must be unique among remote read configs. 145 - The name will be used in metrics and logging in place of a generated value to help users distinguish between 146 - remote read configs. 147 ''; 148 - required_matchers = mkOpt (types.attrsOf types.str) '' 149 - An optional list of equality matchers which have to be 150 - present in a selector to query the remote read endpoint. 151 ''; 152 - remote_timeout = mkOpt types.str '' 153 - Timeout for requests to the remote read endpoint. 154 ''; 155 - read_recent = mkOpt types.bool '' 156 - Whether reads should be made for queries for time ranges that 157 - the local storage should have complete data for. 158 ''; 159 - basic_auth = mkOpt (types.submodule { 160 - options = { 161 - username = mkOption { 162 - type = types.str; 163 - description = '' 164 - HTTP username 165 - ''; 166 - }; 167 - password = mkOpt types.str "HTTP password"; 168 - password_file = mkOpt types.str "HTTP password file"; 169 - }; 170 - }) '' 171 - Sets the `Authorization` header on every remote read request with the 172 - configured username and password. 173 - password and password_file are mutually exclusive. 174 - ''; 175 - bearer_token = mkOpt types.str '' 176 - Sets the `Authorization` header on every remote read request with 177 - the configured bearer token. It is mutually exclusive with `bearer_token_file`. 178 ''; 179 - bearer_token_file = mkOpt types.str '' 180 - Sets the `Authorization` header on every remote read request with the bearer token 181 - read from the configured file. It is mutually exclusive with `bearer_token`. 182 - ''; 183 - tls_config = mkOpt promTypes.tls_config '' 184 - Configures the remote read request's TLS settings. 185 - ''; 186 - proxy_url = mkOpt types.str "Optional Proxy URL."; 187 }; 188 }; 189 190 - promTypes.remote_write = types.submodule { 191 options = { 192 - url = mkOption { 193 - type = types.str; 194 - description = '' 195 - ServerName extension to indicate the name of the server. 196 - http://tools.ietf.org/html/rfc4366#section-3.1 197 - ''; 198 - }; 199 - remote_timeout = mkOpt types.str '' 200 - Timeout for requests to the remote write endpoint. 201 ''; 202 - write_relabel_configs = mkOpt (types.listOf promTypes.relabel_config) '' 203 - List of remote write relabel configurations. 204 ''; 205 - name = mkOpt types.str '' 206 - Name of the remote write config, which if specified must be unique among remote write configs. 207 - The name will be used in metrics and logging in place of a generated value to help users distinguish between 208 - remote write configs. 209 ''; 210 - basic_auth = mkOpt (types.submodule { 211 - options = { 212 - username = mkOption { 213 - type = types.str; 214 - description = '' 215 - HTTP username 216 - ''; 217 - }; 218 - password = mkOpt types.str "HTTP password"; 219 - password_file = mkOpt types.str "HTTP password file"; 220 - }; 221 - }) '' 222 - Sets the `Authorization` header on every remote write request with the 223 - configured username and password. 224 - password and password_file are mutually exclusive. 225 ''; 226 - bearer_token = mkOpt types.str '' 227 - Sets the `Authorization` header on every remote write request with 228 - the configured bearer token. It is mutually exclusive with `bearer_token_file`. 229 ''; 230 - bearer_token_file = mkOpt types.str '' 231 - Sets the `Authorization` header on every remote write request with the bearer token 232 - read from the configured file. It is mutually exclusive with `bearer_token`. 233 - ''; 234 - tls_config = mkOpt promTypes.tls_config '' 235 - Configures the remote write request's TLS settings. 236 - ''; 237 - proxy_url = mkOpt types.str "Optional Proxy URL."; 238 - queue_config = mkOpt (types.submodule { 239 - options = { 240 - capacity = mkOpt types.int '' 241 - Number of samples to buffer per shard before we block reading of more 242 - samples from the WAL. It is recommended to have enough capacity in each 243 - shard to buffer several requests to keep throughput up while processing 244 - occasional slow remote requests. 245 - ''; 246 - max_shards = mkOpt types.int '' 247 - Maximum number of shards, i.e. amount of concurrency. 248 - ''; 249 - min_shards = mkOpt types.int '' 250 - Minimum number of shards, i.e. amount of concurrency. 251 - ''; 252 - max_samples_per_send = mkOpt types.int '' 253 - Maximum number of samples per send. 254 - ''; 255 - batch_send_deadline = mkOpt types.str '' 256 - Maximum time a sample will wait in buffer. 257 - ''; 258 - min_backoff = mkOpt types.str '' 259 - Initial retry delay. Gets doubled for every retry. 260 - ''; 261 - max_backoff = mkOpt types.str '' 262 - Maximum retry delay. 263 - ''; 264 - }; 265 - }) '' 266 - Configures the queue used to write to remote storage. 267 - ''; 268 - metadata_config = mkOpt (types.submodule { 269 - options = { 270 - send = mkOpt types.bool '' 271 - Whether metric metadata is sent to remote storage or not. 272 - ''; 273 - send_interval = mkOpt types.str '' 274 - How frequently metric metadata is sent to remote storage. 275 - ''; 276 - }; 277 - }) '' 278 - Configures the sending of series metadata to remote storage. 279 - Metadata configuration is subject to change at any point 280 - or be removed in future releases. 281 ''; 282 }; 283 }; ··· 335 by the target will be ignored. 336 ''; 337 338 - scheme = mkDefOpt (types.enum ["http" "https"]) "http" '' 339 The URL scheme with which to fetch metrics from targets. 340 ''; 341 ··· 343 Optional HTTP URL parameters. 344 ''; 345 346 - basic_auth = mkOpt (types.submodule { 347 - options = { 348 - username = mkOption { 349 - type = types.str; 350 - description = '' 351 - HTTP username 352 - ''; 353 - }; 354 - password = mkOpt types.str "HTTP password"; 355 - password_file = mkOpt types.str "HTTP password file"; 356 - }; 357 - }) '' 358 Sets the `Authorization` header on every scrape request with the 359 configured username and password. 360 password and password_file are mutually exclusive. ··· 380 Optional proxy URL. 381 ''; 382 383 - ec2_sd_configs = mkOpt (types.listOf promTypes.ec2_sd_config) '' 384 - List of EC2 service discovery configurations. 385 ''; 386 387 dns_sd_configs = mkOpt (types.listOf promTypes.dns_sd_config) '' 388 List of DNS service discovery configurations. 389 ''; 390 391 - consul_sd_configs = mkOpt (types.listOf promTypes.consul_sd_config) '' 392 - List of Consul service discovery configurations. 393 ''; 394 395 file_sd_configs = mkOpt (types.listOf promTypes.file_sd_config) '' ··· 404 relevant Prometheus configuration docs</link> for more detail. 405 ''; 406 407 static_configs = mkOpt (types.listOf promTypes.static_config) '' 408 List of labeled target groups for this job. 409 ''; ··· 416 List of metric relabel configurations. 417 ''; 418 419 sample_limit = mkDefOpt types.int "0" '' 420 Per-scrape limit on number of scraped samples that will be accepted. 421 If more than this number of samples are present after metric relabelling 422 the entire scrape will be treated as failed. 0 means no limit. 423 ''; 424 }; 425 }; 426 427 - promTypes.static_config = types.submodule { 428 options = { 429 - targets = mkOption { 430 - type = types.listOf types.str; 431 description = '' 432 - The targets specified by the target group. 433 ''; 434 }; 435 - labels = mkOption { 436 - type = types.attrsOf types.str; 437 - default = {}; 438 description = '' 439 - Labels assigned to all metrics scraped from the targets. 440 ''; 441 }; 442 }; 443 }; 444 ··· 447 region = mkOption { 448 type = types.str; 449 description = '' 450 - The AWS Region. 451 ''; 452 }; 453 endpoint = mkOpt types.str '' ··· 464 <literal>AWS_SECRET_ACCESS_KEY</literal> is used. 465 ''; 466 467 - profile = mkOpt types.str '' 468 Named AWS profile used to connect to the API. 469 ''; 470 ··· 482 rule. 483 ''; 484 485 - filters = mkOpt (types.listOf promTypes.filter) '' 486 Filters can be used optionally to filter the instance list by other criteria. 487 ''; 488 }; 489 }; 490 491 - promTypes.filter = types.submodule { 492 options = { 493 - name = mkOption { 494 type = types.str; 495 description = '' 496 - See <link xlink:href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html">this list</link> 497 - for the available filters. 498 ''; 499 }; 500 501 - values = mkOption { 502 - type = types.listOf types.str; 503 - default = []; 504 description = '' 505 - Value of the filter. 506 ''; 507 }; 508 }; 509 }; 510 511 - promTypes.dns_sd_config = types.submodule { 512 options = { 513 - names = mkOption { 514 - type = types.listOf types.str; 515 description = '' 516 - A list of DNS SRV record names to be queried. 517 ''; 518 }; 519 520 - refresh_interval = mkDefOpt types.str "30s" '' 521 - The time after which the provided names are refreshed. 522 ''; 523 }; 524 }; 525 526 - promTypes.consul_sd_config = types.submodule { 527 - options = { 528 - server = mkDefOpt types.str "localhost:8500" '' 529 - Consul server to query. 530 ''; 531 532 - token = mkOpt types.str "Consul token"; 533 534 - datacenter = mkOpt types.str "Consul datacenter"; 535 536 - scheme = mkDefOpt types.str "http" "Consul scheme"; 537 538 - username = mkOpt types.str "Consul username"; 539 540 - password = mkOpt types.str "Consul password"; 541 542 - tls_config = mkOpt promTypes.tls_config '' 543 - Configures the Consul request's TLS settings. 544 ''; 545 546 - services = mkOpt (types.listOf types.str) '' 547 - A list of services for which targets are retrieved. 548 ''; 549 550 - tags = mkOpt (types.listOf types.str) '' 551 - An optional list of tags used to filter nodes for a given 552 - service. Services must contain all tags in the list. 553 ''; 554 555 - node_meta = mkOpt (types.attrsOf types.str) '' 556 - Node metadata used to filter nodes for a given service. 557 ''; 558 559 - tag_separator = mkDefOpt types.str "," '' 560 - The string by which Consul tags are joined into the tag label. 561 ''; 562 563 - allow_stale = mkOpt types.bool '' 564 - Allow stale Consul results 565 - (see <link xlink:href="https://www.consul.io/api/index.html#consistency-modes"/>). 566 567 - Will reduce load on Consul. 568 ''; 569 570 - refresh_interval = mkDefOpt types.str "30s" '' 571 - The time after which the provided names are refreshed. 572 573 - On large setup it might be a good idea to increase this value 574 - because the catalog will change all the time. 575 ''; 576 }; 577 }; 578 579 - promTypes.file_sd_config = types.submodule { 580 options = { 581 - files = mkOption { 582 type = types.listOf types.str; 583 description = '' 584 - Patterns for files from which target groups are extracted. Refer 585 - to the Prometheus documentation for permitted filename patterns 586 - and formats. 587 ''; 588 }; 589 590 - refresh_interval = mkDefOpt types.str "5m" '' 591 - Refresh interval to re-read the files. 592 ''; 593 }; 594 }; 595 596 - promTypes.gce_sd_config = types.submodule { 597 options = { 598 - # Use `mkOption` instead of `mkOpt` for project and zone because they are 599 - # required configuration values for `gce_sd_config`. 600 - project = mkOption { 601 type = types.str; 602 description = '' 603 - The GCP Project. 604 ''; 605 }; 606 607 - zone = mkOption { 608 type = types.str; 609 description = '' 610 - The zone of the scrape targets. If you need multiple zones use multiple 611 - gce_sd_configs. 612 ''; 613 }; 614 615 - filter = mkOpt types.str '' 616 - Filter can be used optionally to filter the instance list by other 617 - criteria Syntax of this filter string is described here in the filter 618 - query parameter section: <link 619 - xlink:href="https://cloud.google.com/compute/docs/reference/latest/instances/list" 620 - />. 621 ''; 622 623 refresh_interval = mkDefOpt types.str "60s" '' 624 - Refresh interval to re-read the cloud instance list. 625 ''; 626 627 - port = mkDefOpt types.port "80" '' 628 - The port to scrape metrics from. If using the public IP address, this 629 - must instead be specified in the relabeling rule. 630 ''; 631 632 - tag_separator = mkDefOpt types.str "," '' 633 - The tag separator used to separate concatenated GCE instance network tags. 634 635 - See the GCP documentation on network tags for more information: <link 636 - xlink:href="https://cloud.google.com/vpc/docs/add-remove-network-tags" 637 - /> 638 ''; 639 }; 640 }; 641 642 promTypes.relabel_config = types.submodule { 643 options = { 644 source_labels = mkOpt (types.listOf types.str) '' ··· 670 ''; 671 672 action = 673 - mkDefOpt (types.enum ["replace" "keep" "drop" "hashmod" "labelmap" "labeldrop" "labelkeep"]) "replace" '' 674 - Action to perform based on regex matching. 675 ''; 676 }; 677 }; 678 679 - promTypes.tls_config = types.submodule { 680 options = { 681 - ca_file = mkOpt types.str '' 682 - CA certificate to validate API server certificate with. 683 ''; 684 - 685 - cert_file = mkOpt types.str '' 686 - Certificate file for client cert authentication to the server. 687 ''; 688 - 689 - key_file = mkOpt types.str '' 690 - Key file for client cert authentication to the server. 691 ''; 692 - 693 - server_name = mkOpt types.str '' 694 - ServerName extension to indicate the name of the server. 695 - http://tools.ietf.org/html/rfc4366#section-3.1 696 ''; 697 - 698 - insecure_skip_verify = mkOpt types.bool '' 699 - Disable validation of the server certificate. 700 ''; 701 }; 702 }; 703 704 - in { 705 706 imports = [ 707 (mkRenamedOptionModule [ "services" "prometheus2" ] [ "services" "prometheus" ]) ··· 753 754 extraFlags = mkOption { 755 type = types.listOf types.str; 756 - default = []; 757 description = '' 758 Extra commandline options when launching Prometheus. 759 ''; ··· 829 830 globalConfig = mkOption { 831 type = promTypes.globalConfig; 832 - default = {}; 833 description = '' 834 Parameters that are valid in all configuration contexts. They 835 also serve as defaults for other configuration sections ··· 838 839 remoteRead = mkOption { 840 type = types.listOf promTypes.remote_read; 841 - default = []; 842 description = '' 843 Parameters of the endpoints to query from. 844 See <link xlink:href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_read">the official documentation</link> for more information. ··· 847 848 remoteWrite = mkOption { 849 type = types.listOf promTypes.remote_write; 850 - default = []; 851 description = '' 852 Parameters of the endpoints to send samples to. 853 See <link xlink:href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write">the official documentation</link> for more information. ··· 856 857 rules = mkOption { 858 type = types.listOf types.str; 859 - default = []; 860 description = '' 861 Alerting and/or Recording rules to evaluate at runtime. 862 ''; ··· 864 865 ruleFiles = mkOption { 866 type = types.listOf types.path; 867 - default = []; 868 description = '' 869 Any additional rules files to include in this configuration. 870 ''; ··· 872 873 scrapeConfigs = mkOption { 874 type = types.listOf promTypes.scrape_config; 875 - default = []; 876 description = '' 877 A list of scrape configurations. 878 ''; ··· 891 } ]; 892 } ] 893 ''; 894 - default = []; 895 description = '' 896 A list of alertmanagers to send alerts to. 897 See <link xlink:href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config">the official documentation</link> for more information. ··· 950 951 config = mkIf cfg.enable { 952 assertions = [ 953 - ( let 954 # Match something with dots (an IPv4 address) or something ending in 955 # a square bracket (an IPv6 addresses) followed by a port number. 956 legacy = builtins.match "(.*\\..*|.*]):([[:digit:]]+)" cfg.listenAddress; 957 - in { 958 assertion = legacy == null; 959 message = '' 960 Do not specify the port for Prometheus to listen on in the ··· 974 }; 975 systemd.services.prometheus = { 976 wantedBy = [ "multi-user.target" ]; 977 - after = [ "network.target" ]; 978 preStart = mkIf (!cfg.enableReload) '' 979 - ${lib.getBin pkgs.envsubst}/bin/envsubst -o "/run/prometheus/prometheus-substituted.yaml" \ 980 - -i "${prometheusYml}" 981 ''; 982 serviceConfig = { 983 ExecStart = "${cfg.package}/bin/prometheus" + ··· 985 concatStringsSep " \\\n " cmdlineArgs); 986 ExecReload = mkIf cfg.enableReload "+${reload}/bin/reload-prometheus"; 987 User = "prometheus"; 988 - Restart = "always"; 989 EnvironmentFile = mkIf (cfg.environmentFile != null && !cfg.enableReload) [ cfg.environmentFile ]; 990 RuntimeDirectory = "prometheus"; 991 RuntimeDirectoryMode = "0700";
··· 37 pkgs.runCommandLocal 38 "${name}-${replaceStrings [" "] [""] what}-checked" 39 { buildInputs = [ cfg.package ]; } '' 40 + ln -s ${file} $out 41 + promtool ${what} $out 42 + '' else file; 43 44 # Pretty-print JSON to a file 45 writePrettyJSON = name: x: 46 + pkgs.runCommandLocal name { } '' 47 echo '${builtins.toJSON x}' | ${pkgs.jq}/bin/jq . > $out 48 ''; 49 ··· 63 }; 64 }; 65 66 + prometheusYml = 67 + let 68 + yml = 69 + if cfg.configText != null then 70 + pkgs.writeText "prometheus.yml" cfg.configText 71 + else generatedPrometheusYml; 72 + in 73 + promtoolCheck "check config" "prometheus.yml" yml; 74 75 cmdlineArgs = cfg.extraFlags ++ [ 76 "--storage.tsdb.path=${workingDir}/data/" ··· 83 "--alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}" 84 "--alertmanager.timeout=${toString cfg.alertmanagerTimeout}s" 85 ] ++ optional (cfg.webExternalUrl != null) "--web.external-url=${cfg.webExternalUrl}" 86 + ++ optional (cfg.retentionTime != null) "--storage.tsdb.retention.time=${cfg.retentionTime}"; 87 88 filterValidPrometheus = filterAttrsListRecursive (n: v: !(n == "_module" || v == null)); 89 filterAttrsListRecursive = pred: x: 90 if isAttrs x then 91 + listToAttrs 92 + ( 93 + concatMap 94 + (name: 95 + let v = x.${name}; in 96 + if pred name v then [ 97 + (nameValuePair name (filterAttrsListRecursive pred v)) 98 + ] else [ ] 99 + ) 100 + (attrNames x) 101 + ) 102 else if isList x then 103 map (filterAttrsListRecursive pred) x 104 else x; 105 106 + # 107 + # Config types: helper functions 108 + # 109 + 110 + mkDefOpt = type: defaultStr: description: mkOpt type (description + '' 111 112 Defaults to <literal>${defaultStr}</literal> in prometheus 113 when set to <literal>null</literal>. 114 ''); 115 116 + mkOpt = type: description: mkOption { 117 type = types.nullOr type; 118 default = null; 119 inherit description; 120 }; 121 122 + mkSdConfigModule = extraOptions: types.submodule { 123 + options = { 124 + basic_auth = mkOpt promTypes.basic_auth '' 125 + Optional HTTP basic authentication information. 126 + ''; 127 + 128 + authorization = mkOpt 129 + (types.submodule { 130 + options = { 131 + type = mkDefOpt types.str "Bearer" '' 132 + Sets the authentication type. 133 + ''; 134 + 135 + credentials = mkOpt types.str '' 136 + Sets the credentials. It is mutually exclusive with `credentials_file`. 137 + ''; 138 + 139 + credentials_file = mkOpt types.str '' 140 + Sets the credentials to the credentials read from the configured file. 141 + It is mutually exclusive with `credentials`. 142 + ''; 143 + }; 144 + }) '' 145 + Optional `Authorization` header configuration. 146 + ''; 147 + 148 + oauth2 = mkOpt promtypes.oauth2 '' 149 + Optional OAuth 2.0 configuration. 150 + Cannot be used at the same time as basic_auth or authorization. 151 + ''; 152 + 153 + proxy_url = mkOpt types.str '' 154 + Optional proxy URL. 155 + ''; 156 + 157 + follow_redirects = mkDefOpt types.bool "true" '' 158 + Configure whether HTTP requests follow HTTP 3xx redirects. 159 + ''; 160 + 161 + tls_config = mkOpt promTypes.tls_config '' 162 + TLS configuration. 163 + ''; 164 + } // extraOptions; 165 + }; 166 + 167 + # 168 + # Config types: general 169 + # 170 + 171 promTypes.globalConfig = types.submodule { 172 options = { 173 scrape_interval = mkDefOpt types.str "1m" '' ··· 190 }; 191 }; 192 193 + promTypes.basic_auth = types.submodule { 194 options = { 195 + username = mkOption { 196 type = types.str; 197 description = '' 198 + HTTP username 199 ''; 200 }; 201 + password = mkOpt types.str "HTTP password"; 202 + password_file = mkOpt types.str "HTTP password file"; 203 + }; 204 + }; 205 + 206 + promTypes.tls_config = types.submodule { 207 + options = { 208 + ca_file = mkOpt types.str '' 209 + CA certificate to validate API server certificate with. 210 ''; 211 + 212 + cert_file = mkOpt types.str '' 213 + Certificate file for client cert authentication to the server. 214 ''; 215 + 216 + key_file = mkOpt types.str '' 217 + Key file for client cert authentication to the server. 218 ''; 219 + 220 + server_name = mkOpt types.str '' 221 + ServerName extension to indicate the name of the server. 222 + http://tools.ietf.org/html/rfc4366#section-3.1 223 ''; 224 + 225 + insecure_skip_verify = mkOpt types.bool '' 226 + Disable validation of the server certificate. 227 ''; 228 }; 229 }; 230 231 + promtypes.oauth2 = types.submodule { 232 options = { 233 + client_id = mkOpt types.str '' 234 + OAuth client ID. 235 ''; 236 + 237 + client_secret = mkOpt types.str '' 238 + OAuth client secret. 239 ''; 240 + 241 + client_secret_file = mkOpt types.str '' 242 + Read the client secret from a file. It is mutually exclusive with `client_secret`. 243 ''; 244 + 245 + scopes = mkOpt (types.listOf types.str) '' 246 + Scopes for the token request. 247 ''; 248 + 249 + token_url = mkOpt types.str '' 250 + The URL to fetch the token from. 251 ''; 252 + 253 + endpoint_params = mkOpt (types.attrsOf types.str) '' 254 + Optional parameters to append to the token URL. 255 ''; 256 }; 257 }; ··· 309 by the target will be ignored. 310 ''; 311 312 + scheme = mkDefOpt (types.enum [ "http" "https" ]) "http" '' 313 The URL scheme with which to fetch metrics from targets. 314 ''; 315 ··· 317 Optional HTTP URL parameters. 318 ''; 319 320 + basic_auth = mkOpt promTypes.basic_auth '' 321 Sets the `Authorization` header on every scrape request with the 322 configured username and password. 323 password and password_file are mutually exclusive. ··· 343 Optional proxy URL. 344 ''; 345 346 + azure_sd_configs = mkOpt (types.listOf promTypes.azure_sd_config) '' 347 + List of Azure service discovery configurations. 348 + ''; 349 + 350 + consul_sd_configs = mkOpt (types.listOf promTypes.consul_sd_config) '' 351 + List of Consul service discovery configurations. 352 + ''; 353 + 354 + digitalocean_sd_configs = mkOpt (types.listOf promTypes.digitalocean_sd_config) '' 355 + List of DigitalOcean service discovery configurations. 356 + ''; 357 + 358 + docker_sd_configs = mkOpt (types.listOf promTypes.docker_sd_config) '' 359 + List of Docker service discovery configurations. 360 + ''; 361 + 362 + dockerswarm_sd_configs = mkOpt (types.listOf promTypes.dockerswarm_sd_config) '' 363 + List of Docker Swarm service discovery configurations. 364 ''; 365 366 dns_sd_configs = mkOpt (types.listOf promTypes.dns_sd_config) '' 367 List of DNS service discovery configurations. 368 ''; 369 370 + ec2_sd_configs = mkOpt (types.listOf promTypes.ec2_sd_config) '' 371 + List of EC2 service discovery configurations. 372 + ''; 373 + 374 + eureka_sd_configs = mkOpt (types.listOf promTypes.eureka_sd_config) '' 375 + List of Eureka service discovery configurations. 376 ''; 377 378 file_sd_configs = mkOpt (types.listOf promTypes.file_sd_config) '' ··· 387 relevant Prometheus configuration docs</link> for more detail. 388 ''; 389 390 + hetzner_sd_configs = mkOpt (types.listOf promTypes.hetzner_sd_config) '' 391 + List of Hetzner service discovery configurations. 392 + ''; 393 + 394 + http_sd_configs = mkOpt (types.listOf promTypes.http_sd_config) '' 395 + List of HTTP service discovery configurations. 396 + ''; 397 + 398 + kubernetes_sd_configs = mkOpt (types.listOf promTypes.kubernetes_sd_config) '' 399 + List of Kubernetes service discovery configurations. 400 + ''; 401 + 402 + kuma_sd_configs = mkOpt (types.listOf promTypes.kuma_sd_config) '' 403 + List of Kuma service discovery configurations. 404 + ''; 405 + 406 + lightsail_sd_configs = mkOpt (types.listOf promTypes.lightsail_sd_config) '' 407 + List of Lightsail service discovery configurations. 408 + ''; 409 + 410 + linode_sd_configs = mkOpt (types.listOf promTypes.linode_sd_config) '' 411 + List of Linode service discovery configurations. 412 + ''; 413 + 414 + marathon_sd_configs = mkOpt (types.listOf promTypes.marathon_sd_config) '' 415 + List of Marathon service discovery configurations. 416 + ''; 417 + 418 + nerve_sd_configs = mkOpt (types.listOf promTypes.nerve_sd_config) '' 419 + List of AirBnB's Nerve service discovery configurations. 420 + ''; 421 + 422 + openstack_sd_configs = mkOpt (types.listOf promTypes.openstack_sd_config) '' 423 + List of OpenStack service discovery configurations. 424 + ''; 425 + 426 + puppetdb_sd_configs = mkOpt (types.listOf promTypes.puppetdb_sd_config) '' 427 + List of PuppetDB service discovery configurations. 428 + ''; 429 + 430 + scaleway_sd_configs = mkOpt (types.listOf promTypes.scaleway_sd_config) '' 431 + List of Scaleway service discovery configurations. 432 + ''; 433 + 434 + serverset_sd_configs = mkOpt (types.listOf promTypes.serverset_sd_config) '' 435 + List of Zookeeper Serverset service discovery configurations. 436 + ''; 437 + 438 + triton_sd_configs = mkOpt (types.listOf promTypes.triton_sd_config) '' 439 + List of Triton Serverset service discovery configurations. 440 + ''; 441 + 442 + uyuni_sd_configs = mkOpt (types.listOf promTypes.uyuni_sd_config) '' 443 + List of Uyuni Serverset service discovery configurations. 444 + ''; 445 + 446 static_configs = mkOpt (types.listOf promTypes.static_config) '' 447 List of labeled target groups for this job. 448 ''; ··· 455 List of metric relabel configurations. 456 ''; 457 458 + body_size_limit = mkDefOpt types.str "0" '' 459 + An uncompressed response body larger than this many bytes will cause the 460 + scrape to fail. 0 means no limit. Example: 100MB. 461 + This is an experimental feature, this behaviour could 462 + change or be removed in the future. 463 + ''; 464 + 465 sample_limit = mkDefOpt types.int "0" '' 466 Per-scrape limit on number of scraped samples that will be accepted. 467 If more than this number of samples are present after metric relabelling 468 the entire scrape will be treated as failed. 0 means no limit. 469 ''; 470 + 471 + label_limit = mkDefOpt types.int "0" '' 472 + Per-scrape limit on number of labels that will be accepted for a sample. If 473 + more than this number of labels are present post metric-relabeling, the 474 + entire scrape will be treated as failed. 0 means no limit. 475 + ''; 476 + 477 + label_name_length_limit = mkDefOpt types.int "0" '' 478 + Per-scrape limit on length of labels name that will be accepted for a sample. 479 + If a label name is longer than this number post metric-relabeling, the entire 480 + scrape will be treated as failed. 0 means no limit. 481 + ''; 482 + 483 + label_value_length_limit = mkDefOpt types.int "0" '' 484 + Per-scrape limit on length of labels value that will be accepted for a sample. 485 + If a label value is longer than this number post metric-relabeling, the 486 + entire scrape will be treated as failed. 0 means no limit. 487 + ''; 488 + 489 + target_limit = mkDefOpt types.int "0" '' 490 + Per-scrape config limit on number of unique targets that will be 491 + accepted. If more than this number of targets are present after target 492 + relabeling, Prometheus will mark the targets as failed without scraping them. 493 + 0 means no limit. This is an experimental feature, this behaviour could 494 + change in the future. 495 + ''; 496 }; 497 }; 498 499 + # 500 + # Config types: service discovery 501 + # 502 + 503 + # For this one, the docs actually define all types needed to use mkSdConfigModule, but a bunch 504 + # of them are marked with 'currently not support by Azure' so we don't bother adding them in 505 + # here. 506 + promTypes.azure_sd_config = types.submodule { 507 options = { 508 + environment = mkDefOpt types.str "AzurePublicCloud" '' 509 + The Azure environment. 510 + ''; 511 + 512 + authentication_method = mkDefOpt (types.enum [ "OAuth" "ManagedIdentity" ]) "OAuth" '' 513 + The authentication method, either OAuth or ManagedIdentity. 514 + See https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview 515 + ''; 516 + 517 + subscription_id = mkOption { 518 + type = types.str; 519 description = '' 520 + The subscription ID. 521 ''; 522 }; 523 + 524 + tenant_id = mkOpt types.str '' 525 + Optional tenant ID. Only required with authentication_method OAuth. 526 + ''; 527 + 528 + client_id = mkOpt types.str '' 529 + Optional client ID. Only required with authentication_method OAuth. 530 + ''; 531 + 532 + client_secret = mkOpt types.str '' 533 + Optional client secret. Only required with authentication_method OAuth. 534 + ''; 535 + 536 + refresh_interval = mkDefOpt types.str "300s" '' 537 + Refresh interval to re-read the instance list. 538 + ''; 539 + 540 + port = mkDefOpt types.int "80" '' 541 + The port to scrape metrics from. If using the public IP 542 + address, this must instead be specified in the relabeling 543 + rule. 544 + ''; 545 + 546 + proxy_url = mkOpt types.str '' 547 + Optional proxy URL. 548 + ''; 549 + 550 + follow_redirects = mkDefOpt types.bool "true" '' 551 + Configure whether HTTP requests follow HTTP 3xx redirects. 552 + ''; 553 + 554 + tls_config = mkOpt promTypes.tls_config '' 555 + TLS configuration. 556 + ''; 557 + }; 558 + }; 559 + 560 + promTypes.consul_sd_config = mkSdConfigModule { 561 + server = mkDefOpt types.str "localhost:8500" '' 562 + Consul server to query. 563 + ''; 564 + 565 + token = mkOpt types.str "Consul token"; 566 + 567 + datacenter = mkOpt types.str "Consul datacenter"; 568 + 569 + scheme = mkDefOpt types.str "http" "Consul scheme"; 570 + 571 + username = mkOpt types.str "Consul username"; 572 + 573 + password = mkOpt types.str "Consul password"; 574 + 575 + tls_config = mkOpt promTypes.tls_config '' 576 + Configures the Consul request's TLS settings. 577 + ''; 578 + 579 + services = mkOpt (types.listOf types.str) '' 580 + A list of services for which targets are retrieved. 581 + ''; 582 + 583 + tags = mkOpt (types.listOf types.str) '' 584 + An optional list of tags used to filter nodes for a given 585 + service. Services must contain all tags in the list. 586 + ''; 587 + 588 + node_meta = mkOpt (types.attrsOf types.str) '' 589 + Node metadata used to filter nodes for a given service. 590 + ''; 591 + 592 + tag_separator = mkDefOpt types.str "," '' 593 + The string by which Consul tags are joined into the tag label. 594 + ''; 595 + 596 + allow_stale = mkOpt types.bool '' 597 + Allow stale Consul results 598 + (see <link xlink:href="https://www.consul.io/api/index.html#consistency-modes"/>). 599 + 600 + Will reduce load on Consul. 601 + ''; 602 + 603 + refresh_interval = mkDefOpt types.str "30s" '' 604 + The time after which the provided names are refreshed. 605 + 606 + On large setup it might be a good idea to increase this value 607 + because the catalog will change all the time. 608 + ''; 609 + }; 610 + 611 + promTypes.digitalocean_sd_config = mkSdConfigModule { 612 + port = mkDefOpt types.int "80" '' 613 + The port to scrape metrics from. 614 + ''; 615 + 616 + refresh_interval = mkDefOpt types.str "60s" '' 617 + The time after which the droplets are refreshed. 618 + ''; 619 + }; 620 + 621 + mkDockerSdConfigModule = extraOptions: mkSdConfigModule ({ 622 + host = mkOption { 623 + type = types.str; 624 + description = '' 625 + Address of the Docker daemon. 626 + ''; 627 + }; 628 + 629 + port = mkDefOpt types.int "80" '' 630 + The port to scrape metrics from, when `role` is nodes, and for discovered 631 + tasks and services that don't have published ports. 632 + ''; 633 + 634 + filters = mkOpt 635 + (types.listOf (types.submodule { 636 + options = { 637 + name = mkOption { 638 + type = types.str; 639 + description = '' 640 + Name of the filter. The available filters are listed in the upstream documentation: 641 + Services: <link xlink:href="https://docs.docker.com/engine/api/v1.40/#operation/ServiceList"/> 642 + Tasks: <link xlink:href="https://docs.docker.com/engine/api/v1.40/#operation/TaskList"/> 643 + Nodes: <link xlink:href="https://docs.docker.com/engine/api/v1.40/#operation/NodeList"/> 644 + ''; 645 + }; 646 + values = mkOption { 647 + type = types.str; 648 + description = '' 649 + Value for the filter. 650 + ''; 651 + }; 652 + }; 653 + })) '' 654 + Optional filters to limit the discovery process to a subset of available resources. 655 + ''; 656 + 657 + refresh_interval = mkDefOpt types.str "60s" '' 658 + The time after which the containers are refreshed. 659 + ''; 660 + } // extraOptions); 661 + 662 + promTypes.docker_sd_config = mkDockerSdConfigModule { 663 + host_networking_host = mkDefOpt types.str "localhost" '' 664 + The host to use if the container is in host networking mode. 665 + ''; 666 + }; 667 + 668 + promTypes.dockerswarm_sd_config = mkDockerSdConfigModule { 669 + role = mkOption { 670 + type = types.enum [ "services" "tasks" "nodes" ]; 671 + description = '' 672 + Role of the targets to retrieve. Must be `services`, `tasks`, or `nodes`. 673 + ''; 674 + }; 675 + }; 676 + 677 + promTypes.dns_sd_config = types.submodule { 678 + options = { 679 + names = mkOption { 680 + type = types.listOf types.str; 681 description = '' 682 + A list of DNS SRV record names to be queried. 683 ''; 684 }; 685 + 686 + type = mkDefOpt (types.enum [ "SRV" "A" "AAAA" ]) "SRV" '' 687 + The type of DNS query to perform. One of SRV, A, or AAAA. 688 + ''; 689 + 690 + port = mkOpt types.int '' 691 + The port number used if the query type is not SRV. 692 + ''; 693 + 694 + refresh_interval = mkDefOpt types.str "30s" '' 695 + The time after which the provided names are refreshed. 696 + ''; 697 }; 698 }; 699 ··· 702 region = mkOption { 703 type = types.str; 704 description = '' 705 + The AWS Region. If blank, the region from the instance metadata is used. 706 ''; 707 }; 708 endpoint = mkOpt types.str '' ··· 719 <literal>AWS_SECRET_ACCESS_KEY</literal> is used. 720 ''; 721 722 + profile = mkOpt types.str '' 723 Named AWS profile used to connect to the API. 724 ''; 725 ··· 737 rule. 738 ''; 739 740 + filters = mkOpt 741 + (types.listOf (types.submodule { 742 + options = { 743 + name = mkOption { 744 + type = types.str; 745 + description = '' 746 + See <link xlink:href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeInstances.html">this list</link> 747 + for the available filters. 748 + ''; 749 + }; 750 + 751 + values = mkOption { 752 + type = types.listOf types.str; 753 + default = [ ]; 754 + description = '' 755 + Value of the filter. 756 + ''; 757 + }; 758 + }; 759 + })) '' 760 Filters can be used optionally to filter the instance list by other criteria. 761 ''; 762 }; 763 }; 764 765 + promTypes.eureka_sd_config = mkSdConfigModule { 766 + server = mkOption { 767 + type = types.str; 768 + description = '' 769 + The URL to connect to the Eureka server. 770 + ''; 771 + }; 772 + }; 773 + 774 + promTypes.file_sd_config = types.submodule { 775 options = { 776 + files = mkOption { 777 + type = types.listOf types.str; 778 + description = '' 779 + Patterns for files from which target groups are extracted. Refer 780 + to the Prometheus documentation for permitted filename patterns 781 + and formats. 782 + ''; 783 + }; 784 + 785 + refresh_interval = mkDefOpt types.str "5m" '' 786 + Refresh interval to re-read the files. 787 + ''; 788 + }; 789 + }; 790 + 791 + promTypes.gce_sd_config = types.submodule { 792 + options = { 793 + # Use `mkOption` instead of `mkOpt` for project and zone because they are 794 + # required configuration values for `gce_sd_config`. 795 + project = mkOption { 796 type = types.str; 797 description = '' 798 + The GCP Project. 799 ''; 800 }; 801 802 + zone = mkOption { 803 + type = types.str; 804 description = '' 805 + The zone of the scrape targets. If you need multiple zones use multiple 806 + gce_sd_configs. 807 ''; 808 }; 809 + 810 + filter = mkOpt types.str '' 811 + Filter can be used optionally to filter the instance list by other 812 + criteria Syntax of this filter string is described here in the filter 813 + query parameter section: <link 814 + xlink:href="https://cloud.google.com/compute/docs/reference/latest/instances/list" 815 + />. 816 + ''; 817 + 818 + refresh_interval = mkDefOpt types.str "60s" '' 819 + Refresh interval to re-read the cloud instance list. 820 + ''; 821 + 822 + port = mkDefOpt types.port "80" '' 823 + The port to scrape metrics from. If using the public IP address, this 824 + must instead be specified in the relabeling rule. 825 + ''; 826 + 827 + tag_separator = mkDefOpt types.str "," '' 828 + The tag separator used to separate concatenated GCE instance network tags. 829 + 830 + See the GCP documentation on network tags for more information: 831 + <link xlink:href="https://cloud.google.com/vpc/docs/add-remove-network-tags" /> 832 + ''; 833 }; 834 }; 835 836 + promTypes.hetzner_sd_config = mkSdConfigModule { 837 + role = mkOption { 838 + type = types.enum [ "robot" "hcloud" ]; 839 + description = '' 840 + The Hetzner role of entities that should be discovered. 841 + One of <literal>robot</literal> or <literal>hcloud</literal>. 842 + ''; 843 + }; 844 + 845 + port = mkDefOpt types.int "80" '' 846 + The port to scrape metrics from. 847 + ''; 848 + 849 + refresh_interval = mkDefOpt types.str "60s" '' 850 + The time after which the servers are refreshed. 851 + ''; 852 + }; 853 + 854 + promTypes.http_sd_config = types.submodule { 855 options = { 856 + url = mkOption { 857 + type = types.str; 858 description = '' 859 + URL from which the targets are fetched. 860 ''; 861 }; 862 863 + refresh_interval = mkDefOpt types.str "60s" '' 864 + Refresh interval to re-query the endpoint. 865 + ''; 866 + 867 + basic_auth = mkOpt promTypes.basic_auth '' 868 + Authentication information used to authenticate to the API server. 869 + password and password_file are mutually exclusive. 870 + ''; 871 + 872 + proxy_url = mkOpt types.str '' 873 + Optional proxy URL. 874 + ''; 875 + 876 + follow_redirects = mkDefOpt types.bool "true" '' 877 + Configure whether HTTP requests follow HTTP 3xx redirects. 878 + ''; 879 + 880 + tls_config = mkOpt promTypes.tls_config '' 881 + Configures the scrape request's TLS settings. 882 ''; 883 }; 884 }; 885 886 + promTypes.kubernetes_sd_config = mkSdConfigModule { 887 + api_server = mkOpt types.str '' 888 + The API server addresses. If left empty, Prometheus is assumed to run inside 889 + of the cluster and will discover API servers automatically and use the pod's 890 + CA certificate and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/. 891 + ''; 892 + 893 + role = mkOption { 894 + type = types.enum [ "endpoints" "service" "pod" "node" "ingress" ]; 895 + description = '' 896 + The Kubernetes role of entities that should be discovered. 897 + One of endpoints, service, pod, node, or ingress. 898 ''; 899 + }; 900 901 + kubeconfig_file = mkOpt types.str '' 902 + Optional path to a kubeconfig file. 903 + Note that api_server and kube_config are mutually exclusive. 904 + ''; 905 906 + namespaces = mkOpt 907 + ( 908 + types.submodule { 909 + options = { 910 + names = mkOpt (types.listOf types.str) '' 911 + Namespace name. 912 + ''; 913 + }; 914 + } 915 + ) '' 916 + Optional namespace discovery. If omitted, all namespaces are used. 917 + ''; 918 919 + selectors = mkOpt 920 + ( 921 + types.listOf ( 922 + types.submodule { 923 + options = { 924 + role = mkOption { 925 + type = types.str; 926 + description = '' 927 + Selector role 928 + ''; 929 + }; 930 931 + label = mkOpt types.str '' 932 + Selector label 933 + ''; 934 935 + field = mkOpt types.str '' 936 + Selector field 937 + ''; 938 + }; 939 + } 940 + ) 941 + ) '' 942 + Optional label and field selectors to limit the discovery process to a subset of available resources. 943 + See https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/ 944 + and https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ to learn more about the possible 945 + filters that can be used. Endpoints role supports pod, service and endpoints selectors, other roles 946 + only support selectors matching the role itself (e.g. node role can only contain node selectors). 947 948 + Note: When making decision about using field/label selector make sure that this 949 + is the best approach - it will prevent Prometheus from reusing single list/watch 950 + for all scrape configs. This might result in a bigger load on the Kubernetes API, 951 + because per each selector combination there will be additional LIST/WATCH. On the other hand, 952 + if you just want to monitor small subset of pods in large cluster it's recommended to use selectors. 953 + Decision, if selectors should be used or not depends on the particular situation. 954 + ''; 955 + }; 956 + 957 + promTypes.kuma_sd_config = mkSdConfigModule { 958 + server = mkOption { 959 + type = types.str; 960 + description = '' 961 + Address of the Kuma Control Plane's MADS xDS server. 962 + ''; 963 + }; 964 + 965 + refresh_interval = mkDefOpt types.str "30s" '' 966 + The time to wait between polling update requests. 967 + ''; 968 + 969 + fetch_timeout = mkDefOpt types.str "2m" '' 970 + The time after which the monitoring assignments are refreshed. 971 + ''; 972 + }; 973 + 974 + promTypes.lightsail_sd_config = types.submodule { 975 + options = { 976 + region = mkOpt types.str '' 977 + The AWS region. If blank, the region from the instance metadata is used. 978 ''; 979 980 + endpoint = mkOpt types.str '' 981 + Custom endpoint to be used. 982 + ''; 983 + 984 + access_key = mkOpt types.str '' 985 + The AWS API keys. If blank, the environment variable <literal>AWS_ACCESS_KEY_ID</literal> is used. 986 ''; 987 988 + secret_key = mkOpt types.str '' 989 + The AWS API keys. If blank, the environment variable <literal>AWS_SECRET_ACCESS_KEY</literal> is used. 990 ''; 991 992 + profile = mkOpt types.str '' 993 + Named AWS profile used to connect to the API. 994 ''; 995 996 + role_arn = mkOpt types.str '' 997 + AWS Role ARN, an alternative to using AWS API keys. 998 ''; 999 1000 + refresh_interval = mkDefOpt types.str "60s" '' 1001 + Refresh interval to re-read the instance list. 1002 + ''; 1003 1004 + port = mkDefOpt types.int "80" '' 1005 + The port to scrape metrics from. If using the public IP address, this must 1006 + instead be specified in the relabeling rule. 1007 ''; 1008 + }; 1009 + }; 1010 1011 + promTypes.linode_sd_config = mkSdConfigModule { 1012 + port = mkDefOpt types.int "80" '' 1013 + The port to scrape metrics from. 1014 + ''; 1015 1016 + tag_separator = mkDefOpt types.str "," '' 1017 + The string by which Linode Instance tags are joined into the tag label. 1018 + ''; 1019 + 1020 + refresh_interval = mkDefOpt types.str "60s" '' 1021 + The time after which the linode instances are refreshed. 1022 + ''; 1023 + }; 1024 + 1025 + promTypes.marathon_sd_config = mkSdConfigModule { 1026 + servers = mkOption { 1027 + type = types.listOf types.str; 1028 + description = '' 1029 + List of URLs to be used to contact Marathon servers. You need to provide at least one server URL. 1030 ''; 1031 }; 1032 + 1033 + refresh_interval = mkDefOpt types.str "30s" '' 1034 + Polling interval. 1035 + ''; 1036 + 1037 + auth_token = mkOpt types.str '' 1038 + Optional authentication information for token-based authentication: 1039 + <link xlink:href="https://docs.mesosphere.com/1.11/security/ent/iam-api/#passing-an-authentication-token" /> 1040 + It is mutually exclusive with <literal>auth_token_file</literal> and other authentication mechanisms. 1041 + ''; 1042 + 1043 + auth_token_file = mkOpt types.str '' 1044 + Optional authentication information for token-based authentication: 1045 + <link xlink:href="https://docs.mesosphere.com/1.11/security/ent/iam-api/#passing-an-authentication-token" /> 1046 + It is mutually exclusive with <literal>auth_token</literal> and other authentication mechanisms. 1047 + ''; 1048 }; 1049 1050 + promTypes.nerve_sd_config = types.submodule { 1051 options = { 1052 + servers = mkOption { 1053 + type = types.listOf types.str; 1054 + description = '' 1055 + The Zookeeper servers. 1056 + ''; 1057 + }; 1058 + 1059 + paths = mkOption { 1060 type = types.listOf types.str; 1061 description = '' 1062 + Paths can point to a single service, or the root of a tree of services. 1063 + ''; 1064 + }; 1065 + 1066 + timeout = mkDefOpt types.str "10s" '' 1067 + Timeout value. 1068 + ''; 1069 + }; 1070 + }; 1071 + 1072 + promTypes.openstack_sd_config = types.submodule { 1073 + options = 1074 + let 1075 + userDescription = '' 1076 + username is required if using Identity V2 API. Consult with your provider's 1077 + control panel to discover your account's username. In Identity V3, either 1078 + userid or a combination of username and domain_id or domain_name are needed. 1079 + ''; 1080 + 1081 + domainDescription = '' 1082 + At most one of domain_id and domain_name must be provided if using username 1083 + with Identity V3. Otherwise, either are optional. 1084 + ''; 1085 + 1086 + projectDescription = '' 1087 + The project_id and project_name fields are optional for the Identity V2 API. 1088 + Some providers allow you to specify a project_name instead of the project_id. 1089 + Some require both. Your provider's authentication policies will determine 1090 + how these fields influence authentication. 1091 + ''; 1092 + 1093 + applicationDescription = '' 1094 + The application_credential_id or application_credential_name fields are 1095 + required if using an application credential to authenticate. Some providers 1096 + allow you to create an application credential to authenticate rather than a 1097 + password. 1098 + ''; 1099 + in 1100 + { 1101 + role = mkOption { 1102 + type = types.str; 1103 + description = '' 1104 + The OpenStack role of entities that should be discovered. 1105 + ''; 1106 + }; 1107 + 1108 + region = mkOption { 1109 + type = types.str; 1110 + description = '' 1111 + The OpenStack Region. 1112 + ''; 1113 + }; 1114 + 1115 + identity_endpoint = mkOpt types.str '' 1116 + identity_endpoint specifies the HTTP endpoint that is required to work with 1117 + the Identity API of the appropriate version. While it's ultimately needed by 1118 + all of the identity services, it will often be populated by a provider-level 1119 + function. 1120 + ''; 1121 + 1122 + username = mkOpt types.str userDescription; 1123 + userid = mkOpt types.str userDescription; 1124 + 1125 + password = mkOpt types.str '' 1126 + password for the Identity V2 and V3 APIs. Consult with your provider's 1127 + control panel to discover your account's preferred method of authentication. 1128 + ''; 1129 + 1130 + domain_name = mkOpt types.str domainDescription; 1131 + domain_id = mkOpt types.str domainDescription; 1132 + 1133 + project_name = mkOpt types.str projectDescription; 1134 + project_id = mkOpt types.str projectDescription; 1135 + 1136 + application_credential_name = mkOpt types.str applicationDescription; 1137 + application_credential_id = mkOpt types.str applicationDescription; 1138 + 1139 + application_credential_secret = mkOpt types.str '' 1140 + The application_credential_secret field is required if using an application 1141 + credential to authenticate. 1142 + ''; 1143 + 1144 + all_tenants = mkDefOpt types.bool "false" '' 1145 + Whether the service discovery should list all instances for all projects. 1146 + It is only relevant for the 'instance' role and usually requires admin permissions. 1147 + ''; 1148 + 1149 + refresh_interval = mkDefOpt types.str "60s" '' 1150 + Refresh interval to re-read the instance list. 1151 + ''; 1152 + 1153 + port = mkDefOpt types.int "80" '' 1154 + The port to scrape metrics from. If using the public IP address, this must 1155 + instead be specified in the relabeling rule. 1156 + ''; 1157 + 1158 + availability = mkDefOpt (types.enum [ "public" "admin" "internal" ]) "public" '' 1159 + The availability of the endpoint to connect to. Must be one of public, admin or internal. 1160 + ''; 1161 + 1162 + tls_config = mkOpt promTypes.tls_config '' 1163 + TLS configuration. 1164 ''; 1165 }; 1166 + }; 1167 1168 + promTypes.puppetdb_sd_config = mkSdConfigModule { 1169 + url = mkOption { 1170 + type = types.str; 1171 + description = '' 1172 + The URL of the PuppetDB root query endpoint. 1173 ''; 1174 }; 1175 + 1176 + query = mkOption { 1177 + type = types.str; 1178 + description = '' 1179 + Puppet Query Language (PQL) query. Only resources are supported. 1180 + https://puppet.com/docs/puppetdb/latest/api/query/v4/pql.html 1181 + ''; 1182 + }; 1183 + 1184 + include_parameters = mkDefOpt types.bool "false" '' 1185 + Whether to include the parameters as meta labels. 1186 + Due to the differences between parameter types and Prometheus labels, 1187 + some parameters might not be rendered. The format of the parameters might 1188 + also change in future releases. 1189 + 1190 + Note: Enabling this exposes parameters in the Prometheus UI and API. Make sure 1191 + that you don't have secrets exposed as parameters if you enable this. 1192 + ''; 1193 + 1194 + refresh_interval = mkDefOpt types.str "60s" '' 1195 + Refresh interval to re-read the resources list. 1196 + ''; 1197 + 1198 + port = mkDefOpt types.int "80" '' 1199 + The port to scrape metrics from. 1200 + ''; 1201 }; 1202 1203 + promTypes.scaleway_sd_config = types.submodule { 1204 options = { 1205 + access_key = mkOption { 1206 type = types.str; 1207 description = '' 1208 + Access key to use. https://console.scaleway.com/project/credentials 1209 ''; 1210 }; 1211 1212 + secret_key = mkOpt types.str '' 1213 + Secret key to use when listing targets. https://console.scaleway.com/project/credentials 1214 + It is mutually exclusive with `secret_key_file`. 1215 + ''; 1216 + 1217 + secret_key_file = mkOpt types.str '' 1218 + Sets the secret key with the credentials read from the configured file. 1219 + It is mutually exclusive with `secret_key`. 1220 + ''; 1221 + 1222 + project_id = mkOption { 1223 type = types.str; 1224 description = '' 1225 + Project ID of the targets. 1226 + ''; 1227 + }; 1228 + 1229 + role = mkOption { 1230 + type = types.enum [ "instance" "baremetal" ]; 1231 + description = '' 1232 + Role of the targets to retrieve. Must be `instance` or `baremetal`. 1233 ''; 1234 }; 1235 1236 + port = mkDefOpt types.int "80" '' 1237 + The port to scrape metrics from. 1238 + ''; 1239 + 1240 + api_url = mkDefOpt types.str "https://api.scaleway.com" '' 1241 + API URL to use when doing the server listing requests. 1242 + ''; 1243 + 1244 + zone = mkDefOpt types.str "fr-par-1" '' 1245 + Zone is the availability zone of your targets (e.g. fr-par-1). 1246 + ''; 1247 + 1248 + name_filter = mkOpt types.str '' 1249 + Specify a name filter (works as a LIKE) to apply on the server listing request. 1250 + ''; 1251 + 1252 + tags_filter = mkOpt (types.listOf types.str) '' 1253 + Specify a tag filter (a server needs to have all defined tags to be listed) to apply on the server listing request. 1254 ''; 1255 1256 refresh_interval = mkDefOpt types.str "60s" '' 1257 + Refresh interval to re-read the managed targets list. 1258 ''; 1259 1260 + proxy_url = mkOpt types.str '' 1261 + Optional proxy URL. 1262 ''; 1263 1264 + follow_redirects = mkDefOpt types.bool "true" '' 1265 + Configure whether HTTP requests follow HTTP 3xx redirects. 1266 + ''; 1267 1268 + tls_config = mkOpt promTypes.tls_config '' 1269 + TLS configuration. 1270 ''; 1271 }; 1272 }; 1273 1274 + # These are exactly the same. 1275 + promTypes.serverset_sd_config = promTypes.nerve_sd_config; 1276 + 1277 + promTypes.triton_sd_config = types.submodule { 1278 + options = { 1279 + account = mkOption { 1280 + type = types.str; 1281 + description = '' 1282 + The account to use for discovering new targets. 1283 + ''; 1284 + }; 1285 + 1286 + role = mkDefOpt (types.enum [ "container" "cn" ]) "container" '' 1287 + The type of targets to discover, can be set to: 1288 + - "container" to discover virtual machines (SmartOS zones, lx/KVM/bhyve branded zones) running on Triton 1289 + - "cn" to discover compute nodes (servers/global zones) making up the Triton infrastructure 1290 + ''; 1291 + 1292 + dns_suffix = mkOption { 1293 + type = types.str; 1294 + description = '' 1295 + The DNS suffix which should be applied to target. 1296 + ''; 1297 + }; 1298 + 1299 + endpoint = mkOption { 1300 + type = types.str; 1301 + description = '' 1302 + The Triton discovery endpoint (e.g. <literal>cmon.us-east-3b.triton.zone</literal>). This is 1303 + often the same value as dns_suffix. 1304 + ''; 1305 + }; 1306 + 1307 + groups = mkOpt (types.listOf types.str) '' 1308 + A list of groups for which targets are retrieved, only supported when targeting the <literal>container</literal> role. 1309 + If omitted all containers owned by the requesting account are scraped. 1310 + ''; 1311 + 1312 + port = mkDefOpt types.int "9163" '' 1313 + The port to use for discovery and metric scraping. 1314 + ''; 1315 + 1316 + refresh_interval = mkDefOpt types.str "60s" '' 1317 + The interval which should be used for refreshing targets. 1318 + ''; 1319 + 1320 + version = mkDefOpt types.int "1" '' 1321 + The Triton discovery API version. 1322 + ''; 1323 + 1324 + tls_config = mkOpt promTypes.tls_config '' 1325 + TLS configuration. 1326 + ''; 1327 + }; 1328 + }; 1329 + 1330 + promTypes.uyuni_sd_config = mkSdConfigModule { 1331 + server = mkOption { 1332 + type = types.str; 1333 + description = '' 1334 + The URL to connect to the Uyuni server. 1335 + ''; 1336 + }; 1337 + 1338 + username = mkOption { 1339 + type = types.str; 1340 + description = '' 1341 + Credentials are used to authenticate the requests to Uyuni API. 1342 + ''; 1343 + }; 1344 + 1345 + password = mkOption { 1346 + type = types.str; 1347 + description = '' 1348 + Credentials are used to authenticate the requests to Uyuni API. 1349 + ''; 1350 + }; 1351 + 1352 + entitlement = mkDefOpt types.str "monitoring_entitled" '' 1353 + The entitlement string to filter eligible systems. 1354 + ''; 1355 + 1356 + separator = mkDefOpt types.str "," '' 1357 + The string by which Uyuni group names are joined into the groups label 1358 + ''; 1359 + 1360 + refresh_interval = mkDefOpt types.str "60s" '' 1361 + Refresh interval to re-read the managed targets list. 1362 + ''; 1363 + }; 1364 + 1365 + promTypes.static_config = types.submodule { 1366 + options = { 1367 + targets = mkOption { 1368 + type = types.listOf types.str; 1369 + description = '' 1370 + The targets specified by the target group. 1371 + ''; 1372 + }; 1373 + labels = mkOption { 1374 + type = types.attrsOf types.str; 1375 + default = { }; 1376 + description = '' 1377 + Labels assigned to all metrics scraped from the targets. 1378 + ''; 1379 + }; 1380 + }; 1381 + }; 1382 + 1383 + # 1384 + # Config types: relabling 1385 + # 1386 + 1387 promTypes.relabel_config = types.submodule { 1388 options = { 1389 source_labels = mkOpt (types.listOf types.str) '' ··· 1415 ''; 1416 1417 action = 1418 + mkDefOpt (types.enum [ "replace" "keep" "drop" "hashmod" "labelmap" "labeldrop" "labelkeep" ]) "replace" '' 1419 + Action to perform based on regex matching. 1420 + ''; 1421 + }; 1422 + }; 1423 + 1424 + # 1425 + # Config types : remote read / write 1426 + # 1427 + 1428 + promTypes.remote_write = types.submodule { 1429 + options = { 1430 + url = mkOption { 1431 + type = types.str; 1432 + description = '' 1433 + ServerName extension to indicate the name of the server. 1434 + http://tools.ietf.org/html/rfc4366#section-3.1 1435 + ''; 1436 + }; 1437 + remote_timeout = mkOpt types.str '' 1438 + Timeout for requests to the remote write endpoint. 1439 + ''; 1440 + write_relabel_configs = mkOpt (types.listOf promTypes.relabel_config) '' 1441 + List of remote write relabel configurations. 1442 + ''; 1443 + name = mkOpt types.str '' 1444 + Name of the remote write config, which if specified must be unique among remote write configs. 1445 + The name will be used in metrics and logging in place of a generated value to help users distinguish between 1446 + remote write configs. 1447 + ''; 1448 + basic_auth = mkOpt promTypes.basic_auth '' 1449 + Sets the `Authorization` header on every remote write request with the 1450 + configured username and password. 1451 + password and password_file are mutually exclusive. 1452 + ''; 1453 + bearer_token = mkOpt types.str '' 1454 + Sets the `Authorization` header on every remote write request with 1455 + the configured bearer token. It is mutually exclusive with `bearer_token_file`. 1456 + ''; 1457 + bearer_token_file = mkOpt types.str '' 1458 + Sets the `Authorization` header on every remote write request with the bearer token 1459 + read from the configured file. It is mutually exclusive with `bearer_token`. 1460 + ''; 1461 + tls_config = mkOpt promTypes.tls_config '' 1462 + Configures the remote write request's TLS settings. 1463 + ''; 1464 + proxy_url = mkOpt types.str "Optional Proxy URL."; 1465 + queue_config = mkOpt 1466 + (types.submodule { 1467 + options = { 1468 + capacity = mkOpt types.int '' 1469 + Number of samples to buffer per shard before we block reading of more 1470 + samples from the WAL. It is recommended to have enough capacity in each 1471 + shard to buffer several requests to keep throughput up while processing 1472 + occasional slow remote requests. 1473 + ''; 1474 + max_shards = mkOpt types.int '' 1475 + Maximum number of shards, i.e. amount of concurrency. 1476 + ''; 1477 + min_shards = mkOpt types.int '' 1478 + Minimum number of shards, i.e. amount of concurrency. 1479 + ''; 1480 + max_samples_per_send = mkOpt types.int '' 1481 + Maximum number of samples per send. 1482 + ''; 1483 + batch_send_deadline = mkOpt types.str '' 1484 + Maximum time a sample will wait in buffer. 1485 + ''; 1486 + min_backoff = mkOpt types.str '' 1487 + Initial retry delay. Gets doubled for every retry. 1488 + ''; 1489 + max_backoff = mkOpt types.str '' 1490 + Maximum retry delay. 1491 + ''; 1492 + }; 1493 + }) '' 1494 + Configures the queue used to write to remote storage. 1495 + ''; 1496 + metadata_config = mkOpt 1497 + (types.submodule { 1498 + options = { 1499 + send = mkOpt types.bool '' 1500 + Whether metric metadata is sent to remote storage or not. 1501 + ''; 1502 + send_interval = mkOpt types.str '' 1503 + How frequently metric metadata is sent to remote storage. 1504 + ''; 1505 + }; 1506 + }) '' 1507 + Configures the sending of series metadata to remote storage. 1508 + Metadata configuration is subject to change at any point 1509 + or be removed in future releases. 1510 ''; 1511 }; 1512 }; 1513 1514 + promTypes.remote_read = types.submodule { 1515 options = { 1516 + url = mkOption { 1517 + type = types.str; 1518 + description = '' 1519 + ServerName extension to indicate the name of the server. 1520 + http://tools.ietf.org/html/rfc4366#section-3.1 1521 + ''; 1522 + }; 1523 + name = mkOpt types.str '' 1524 + Name of the remote read config, which if specified must be unique among remote read configs. 1525 + The name will be used in metrics and logging in place of a generated value to help users distinguish between 1526 + remote read configs. 1527 ''; 1528 + required_matchers = mkOpt (types.attrsOf types.str) '' 1529 + An optional list of equality matchers which have to be 1530 + present in a selector to query the remote read endpoint. 1531 ''; 1532 + remote_timeout = mkOpt types.str '' 1533 + Timeout for requests to the remote read endpoint. 1534 ''; 1535 + read_recent = mkOpt types.bool '' 1536 + Whether reads should be made for queries for time ranges that 1537 + the local storage should have complete data for. 1538 ''; 1539 + basic_auth = mkOpt promTypes.basic_auth '' 1540 + Sets the `Authorization` header on every remote read request with the 1541 + configured username and password. 1542 + password and password_file are mutually exclusive. 1543 ''; 1544 + bearer_token = mkOpt types.str '' 1545 + Sets the `Authorization` header on every remote read request with 1546 + the configured bearer token. It is mutually exclusive with `bearer_token_file`. 1547 + ''; 1548 + bearer_token_file = mkOpt types.str '' 1549 + Sets the `Authorization` header on every remote read request with the bearer token 1550 + read from the configured file. It is mutually exclusive with `bearer_token`. 1551 + ''; 1552 + tls_config = mkOpt promTypes.tls_config '' 1553 + Configures the remote read request's TLS settings. 1554 + ''; 1555 + proxy_url = mkOpt types.str "Optional Proxy URL."; 1556 }; 1557 }; 1558 1559 + in 1560 + { 1561 1562 imports = [ 1563 (mkRenamedOptionModule [ "services" "prometheus2" ] [ "services" "prometheus" ]) ··· 1609 1610 extraFlags = mkOption { 1611 type = types.listOf types.str; 1612 + default = [ ]; 1613 description = '' 1614 Extra commandline options when launching Prometheus. 1615 ''; ··· 1685 1686 globalConfig = mkOption { 1687 type = promTypes.globalConfig; 1688 + default = { }; 1689 description = '' 1690 Parameters that are valid in all configuration contexts. They 1691 also serve as defaults for other configuration sections ··· 1694 1695 remoteRead = mkOption { 1696 type = types.listOf promTypes.remote_read; 1697 + default = [ ]; 1698 description = '' 1699 Parameters of the endpoints to query from. 1700 See <link xlink:href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_read">the official documentation</link> for more information. ··· 1703 1704 remoteWrite = mkOption { 1705 type = types.listOf promTypes.remote_write; 1706 + default = [ ]; 1707 description = '' 1708 Parameters of the endpoints to send samples to. 1709 See <link xlink:href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write">the official documentation</link> for more information. ··· 1712 1713 rules = mkOption { 1714 type = types.listOf types.str; 1715 + default = [ ]; 1716 description = '' 1717 Alerting and/or Recording rules to evaluate at runtime. 1718 ''; ··· 1720 1721 ruleFiles = mkOption { 1722 type = types.listOf types.path; 1723 + default = [ ]; 1724 description = '' 1725 Any additional rules files to include in this configuration. 1726 ''; ··· 1728 1729 scrapeConfigs = mkOption { 1730 type = types.listOf promTypes.scrape_config; 1731 + default = [ ]; 1732 description = '' 1733 A list of scrape configurations. 1734 ''; ··· 1747 } ]; 1748 } ] 1749 ''; 1750 + default = [ ]; 1751 description = '' 1752 A list of alertmanagers to send alerts to. 1753 See <link xlink:href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#alertmanager_config">the official documentation</link> for more information. ··· 1806 1807 config = mkIf cfg.enable { 1808 assertions = [ 1809 + ( 1810 + let 1811 # Match something with dots (an IPv4 address) or something ending in 1812 # a square bracket (an IPv6 addresses) followed by a port number. 1813 legacy = builtins.match "(.*\\..*|.*]):([[:digit:]]+)" cfg.listenAddress; 1814 + in 1815 + { 1816 assertion = legacy == null; 1817 message = '' 1818 Do not specify the port for Prometheus to listen on in the ··· 1832 }; 1833 systemd.services.prometheus = { 1834 wantedBy = [ "multi-user.target" ]; 1835 + after = [ "network.target" ]; 1836 preStart = mkIf (!cfg.enableReload) '' 1837 + ${lib.getBin pkgs.envsubst}/bin/envsubst -o "/run/prometheus/prometheus-substituted.yaml" \ 1838 + -i "${prometheusYml}" 1839 ''; 1840 serviceConfig = { 1841 ExecStart = "${cfg.package}/bin/prometheus" + ··· 1843 concatStringsSep " \\\n " cmdlineArgs); 1844 ExecReload = mkIf cfg.enableReload "+${reload}/bin/reload-prometheus"; 1845 User = "prometheus"; 1846 + Restart = "always"; 1847 EnvironmentFile = mkIf (cfg.environmentFile != null && !cfg.enableReload) [ cfg.environmentFile ]; 1848 RuntimeDirectory = "prometheus"; 1849 RuntimeDirectoryMode = "0700";