y4h2 / personal-notes

my personal notes
0 stars 0 forks source link

Promethues #2

Open y4h2 opened 2 years ago

y4h2 commented 2 years ago

working prometheus with connection to google monitoring with istio injection.

YAML detail ```yaml # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. apiVersion: v1 kind: Service apiVersion: v1 metadata: labels: name: prometheus name: prometheus spec: selector: app: prometheus type: ClusterIP ports: - name: prometheus protocol: TCP port: 9090 --- apiVersion: v1 kind: Deployment apiVersion: apps/v1 metadata: labels: app: prometheus name: prometheus spec: replicas: 1 selector: matchLabels: app: prometheus template: metadata: name: prometheus labels: app: prometheus annotations: prometheus.io/scrape: 'true' spec: # Needed when using unmodified rbac-setup.yml serviceAccountName: prometheus containers: - name: prometheus image: gcr.io/stackdriver-prometheus/stackdriver-prometheus:release-0.4.1 # Uncomment this to enable debug logs. Can be very verbose. #args: ["--config.file=/etc/prometheus/prometheus.yml", "--log.level=debug"] # Helps during development, when reusing the tag. imagePullPolicy: Always ports: - name: web containerPort: 9090 volumeMounts: - name: config-volume mountPath: /etc/prometheus volumes: - name: config-volume configMap: name: prometheus --- apiVersion: v1 kind: ConfigMap apiVersion: v1 data: prometheus.yml: | # Source: https://github.com/stackdriver/prometheus/blob/master/documentation/examples/prometheus.yml global: external_labels: _stackdriver_project_id: 'kbxplay1' _kubernetes_cluster_name: 'dev4' _kubernetes_location: 'us-central1' # Scrape config for nodes (kubelet). # # Rather than connecting directly to the node, the scrape is proxied though the # Kubernetes apiserver. This means it will work if Prometheus is running out of # cluster, or can't connect to nodes for some other reason (e.g. because of # firewalling). scrape_configs: - job_name: 'kubernetes-nodes' # Default to scraping over https. If required, just disable this or change to # `http`. scheme: https # This TLS & bearer token file config is used to connect to the actual scrape # endpoints for cluster components. This is separate to discovery auth # configuration because discovery & scraping are two separate concerns in # Prometheus. The discovery auth config is automatic if Prometheus runs inside # the cluster. Otherwise, more config options have to be provided within the # . tls_config: ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token kubernetes_sd_configs: - role: node relabel_configs: - target_label: __address__ replacement: kubernetes.default.svc:443 - source_labels: [__meta_kubernetes_node_name] regex: (.+) target_label: __metrics_path__ replacement: /api/v1/nodes/${1}/proxy/metrics # Example scrape config for pods # # The relabeling allows the actual pod scrape endpoint to be configured via the # following annotations: # # * `prometheus.io/scrape`: Only scrape pods that have a value of `true` # * `prometheus.io/path`: If the metrics path is not `/metrics` override this. # * `prometheus.io/port`: Scrape the pod on the indicated port instead of the # pod's declared ports (default is a port-free target if none are declared). - job_name: 'kubernetes-pods-containers' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] action: keep regex: true - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path] action: replace target_label: __metrics_path__ regex: (.+) - source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port] action: replace regex: ([^:]+)(?::\d+)?;(\d+) replacement: $1:$2 target_label: __address__ # Scrape config for service endpoints. # # The relabeling allows the actual service scrape endpoint to be configured # via the following annotations: # # * `prometheus.io/scrape`: Only scrape services that have a value of `true` # * `prometheus.io/scheme`: If the metrics endpoint is secured then you will need # to set this to `https` & most likely set the `tls_config` of the scrape config. # * `prometheus.io/path`: If the metrics path is not `/metrics` override this. # * `prometheus.io/port`: If the metrics are exposed on a different port to the # service then set this appropriately. - job_name: 'kubernetes-service-endpoints' kubernetes_sd_configs: - role: endpoints relabel_configs: - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape] action: keep regex: true - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme] action: replace target_label: __scheme__ regex: (https?) - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path] action: replace target_label: __metrics_path__ regex: (.+) - source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port] action: replace target_label: __address__ regex: ([^:]+)(?::\d+)?;(\d+) replacement: $1:$2 remote_write: - url: "https://monitoring.googleapis.com:443/" queue_config: # Capacity should be 2*max_samples_per_send. capacity: 400 max_samples_per_send: 200 max_shards: 10000 write_relabel_configs: # These labels are generally redundant with the Stackdriver monitored resource labels. - source_labels: [job] target_label: job replacement: "" - source_labels: [instance] target_label: instance replacement: "" metadata: name: prometheus ```
y4h2 commented 2 years ago
# The relabeling allows the actual pod scrape endpoint to be configured via the
    # following annotations:
    #
    # * `prometheus.io/scrape`: Only scrape pods that have a value of `true`
    # * `prometheus.io/path`: If the metrics path is not `/metrics` override this.
    # * `prometheus.io/port`: Scrape the pod on the indicated port instead of the
y4h2 commented 2 years ago

Storage

Local storage

prometheus本身也是一个time series database

配置项

Remote storage

Remote Storage integrations image