zoukankan      html  css  js  c++  java
  • 在Openshift用Prometheus和Grafana搭建监控应用的实践

    参考地址: https://labs.consol.de/development/2018/01/19/openshift_application_monitoring.html

    部署应用

     只要代码如下

    @Component
    @Path("/")
    public class Metrics {
    
        private final Logger logger = LogManager.getLogger(Metrics.class);
    
        private final Counter promRequestsTotal = Counter.build()
                        .name("requests_total")
                        .help("Total number of requests.")
                        .register();
    
      {
        DefaultExports.initialize();
      }
    
      @GET()
      @Path("/hello-world")
      @Produces(MediaType.TEXT_PLAIN)
      public String sayHello() {
        promRequestsTotal.inc();
        return "hello, world";
      }
    
      @GET()
      @Path("/metrics")
      @Produces(MediaType.TEXT_PLAIN)
      public StreamingOutput metrics() {
        logger.info("Starting service for metrics");
        return output -> {
          try (Writer writer = new OutputStreamWriter(output)) {
            TextFormat.write004(writer, CollectorRegistry.defaultRegistry.metricFamilySamples());
          }
        };
      }
    }

    部署

    oc new-project demoapplication

    oc new-app -f https://raw.githubusercontent.com/ConSol/springboot-monitoring-example/master/templates/restservice_template.yaml -n demoapplication


    部署Prometheus

    oc new-project prometheus


    oc new-app -f https://raw.githubusercontent.com/ConSol/springboot-monitoring-example/master/templates/prometheus3.7_with_clusterrole.yaml -p NAMESPACE=prometheus

     

    或者

    oc new-app -f https://raw.githubusercontent.com/ConSol/springboot-monitoring-example/master/templates/prometheus3.7_without_clusterrole.yaml -p NAMESPACE=prometheus

     

    部署Grafana

    oc new-project grafana


    oc new-app -f https://raw.githubusercontent.com/ConSol/springboot-monitoring-example/master/templates/grafana.yaml -p NAMESPACE=grafana

     

    oc policy add-role-to-user view system:serviceaccount:grafana:grafana-ocp -n prometheus



    oc get route prometheus -n prometheus

    oc sa get-token grafana-ocp

    更新Prometheus的配置

    scrape_configs:
    - job_name: 'kubernetes-pods'
    
      kubernetes_sd_configs:
      - role: pod
        namespaces:
          names:
          - prometheus
          - demoapplication



      kubernetes_sd_configs:
      - role: endpoints
        namespaces:
          names:
          - prometheus
          - demoapplication


    - source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
        action: drop
        regex: false


    oc exec prometheus-0 -c prometheus -- curl -X POST http://localhost:9090/-/reload








    部署新的应用


    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: ashe-service
    annotations:
    prometheus.io/scrape: "true"
    prometheus.io/scheme: http
    prometheus.io/port: "8080"
    prometheus.io/path: /metrics
    spec:
    type: LoadBalancer
    ports:
    - port: 8080
    protocol: TCP
    targetPort: 8080
    selector:
    app: ashe
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: ashe-app
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: ashe
    template:
    metadata:
    labels:
    app: ashe
    spec:
    containers:
    - name: ashe
    image: docker.artron.net/zed/ashe:v1
    ports:
    - containerPort: 8080

    oc apply -f app.yaml -n demoapplication
     
  • 相关阅读:
    处理视频流时可能出现的重复帧问题及解决办法
    shell脚本中cd命令无效
    C++教程之初识编程
    若干排序算法的Python实现方法及原理
    C/C++反三角函数使用注意
    ubuntu下安装pip install mysqlclient 报错 command "python setup.py egg_info" failed with error.....解决方案
    使用scrapy框架的monkey出现monkeypatchwarning: monkey-patching ssl after ssl...的解决办法
    机器学习之利用KNN近邻算法预测数据
    python数据分析的工具环境
    python代码实现经典排序算法
  • 原文地址:https://www.cnblogs.com/restful/p/12160363.html
Copyright © 2011-2022 走看看