ballerina 学习二十四 监控ballerina

ballerina 服务的监控还是比较方便的,以及集成了Prometheus Grafana Jaeger Elastic Stack

监控服务监控的集成

  • 主要包含以下几个步骤
a.  安装docker  Prometheus  Grafana Jaeger Elastic Stack 
b.  创建简单ballerian 服务
c.  监控ballerina 服务(--observe 选项,启动之后,默认会使用使用http endpoint 发送监控指标,同时也可以使用配置文件 ballerian.conf 配置
      ballerina run --config <path-to-conf>/ballerina.conf ballerinaservice
d.  发送一些请求  http://localhost:9090/hello/sayHello
e.  通过dashboard 查看指标信息

Jaeger via http://localhost:16686/ 
Grafana dashboard on http://localhost:3000/
Kibana via http://localhost:5601
  • 参考代码
import ballerina/http;
import ballerina/log;

service<http:Service> hello bind { port:9090 } {

    sayHello (endpoint caller, http:Request req) {
        log:printInfo("This is a test Info log");
        log:printError("This is a test Error log");
        log:printWarn("This is a test Warn log");
        http:Response res = new;
        res.setPayload("Hello, World!");
        _ = caller -> respond(res);
    }
}

修改默认配置参考文档

Configuration KeyDescriptionDefault ValuePossible Values
b7a.observability.metrics. enabled Whether metrics monitoring is enabled (true) or disabled (false) false true or false
b7a.observability.metrics. provider Provider name which implements Metrics interface. This is only required to be modified if a custom provider is implemented and needs to be used. micrometer micrometer or if any custom implementation, then name of the provider.
b7a.observability.metrics. micrometer.registry.name Name of the registry used in micrometer prometheus prometheus
b7a.observability.metrics. prometheus.port The value of the port in which the service '/metrics' will be bind to. This service will be used by Prometheus to scrape the information of the Ballerina service. 9797 Any suitable value for port 0 - 0 - 65535. However, within that range, ports 0 - 1023 are generally reserved for specific purposes, therefore it is advisable to select a port without that range.
b7a.observability.metrics. prometheus.hostname The hostname in which the service '/metrics' will be bind to. This service will be used by Prometheus to scrape the information of the Ballerina service. 0.0.0.0 IP or Hostname or 0.0.0.0 of the node in which the Ballerina service is running.
b7a.observability.metrics. prometheus.descriptions This flag indicates whether meter descriptions should be sent to Prometheus. Turn this off to minimize the amount of data sent on each scrape. false true or false
b7a.observability.metrics. prometheus.step The step size to use in computing windowed statistics like max. To get the most out of these statistics, align the step interval to be close to your scrape interval. PT1M (1 minute) The formats accepted are based on the ISO-8601 duration format PnDTnHnMn.nS with days considered to be exactly 24 hours.

参考文档

https://ballerina.io/learn/how-to-observe-ballerina-code/

posted on   荣锋亮  阅读(259)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-06-02 drill 数据库查询方式简单说明

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示