8

真香!白嫖阿里云日志服务

 3 years ago
source link: https://blog.52itstyle.vip/archives/5537/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

真香!白嫖阿里云日志服务

作者:小柒

发表于 2021-01-04 

  |   分类于

程序人生

2622287025.png

日志服务是针对实时数据一站式服务,在阿里集团经历大量大数据场景锤炼而成。提供日志类数据采集、消费、投递及查询分析功能,全面提升海量日志处理/分析能力。

最近在做支付服务的日志监控,日志太多不想入库,又不想自己搭建日志服务,即使是 ELK 最简单的组合,对于个人用户来说也是重重的,主要是浪费服务器资源了。还好有小伙伴推荐阿里云的日志服务,撸主看了一眼,基本上来说就是白嫖了,在这里墙裂推荐给各位小伙伴。

每个月有 500MB 的免费额度,相信对于绝大部分个人项目,日志输出应该是绰绰有余了!

2607384554.png

阿里云的日志服务支持多种方式,给大家截个图,这也仅仅是其中一部分而已。

49349130.png

由于项目中使用了 LogBack,这里我们就使用 LogBack-SDk 的的方式,代码无入侵,只需要配置下xml配置文件即可。

<!--为了防止进程退出时,内存中的数据丢失,请加上此选项-->
<shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
<!--阿里云日志写入 https://pay.cloudbed.vip -->
<appender name="aliyun" class="com.aliyun.openservices.log.logback.LoghubAppender">
    <!--公网域名 https://pay.cloudbed.vip-->
    <endpoint>cn-qingdao.log.aliyuncs.com</endpoint>
    <!--申请地址:https://ram.console.aliyun.com/manage/ak -->
    <accessKeyId>******</accessKeyId>
    <accessKeySecret>>******</accessKeySecret>
    <!--项目名称-->
    <project>>******</project>
    <!--logStore名称-->
    <logStore>>******</logStore>
    <totalSizeInBytes>104857600</totalSizeInBytes>
    <maxBlockMs>60000</maxBlockMs>
    <ioThreadCount>8</ioThreadCount>
    <batchSizeThresholdInBytes>524288</batchSizeThresholdInBytes>
    <batchCountThreshold>4096</batchCountThreshold>
    <lingerMs>2000</lingerMs>
    <retries>10</retries>
    <baseRetryBackoffMs>100</baseRetryBackoffMs>
    <maxRetryBackoffMs>100</maxRetryBackoffMs>
    <encoder>
        <pattern>%d %-5level [%thread] %logger{0}: %msg</pattern>
    </encoder>
    <timeFormat>yyyy-MM-dd'T'HH:mmZ</timeFormat>
    <timeZone>UTC</timeZone>
</appender>

配置文件 pom.xml 引入:

<!--接入阿里云日志 https://pay.cloudbed.vip-->
<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>com.aliyun.openservices</groupId>
    <artifactId>aliyun-log-logback-appender</artifactId>
    <version>0.1.18</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.13</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpcore</artifactId>
    <version>4.4.14</version>
</dependency>

364010638.png

还可以进行模糊搜索:

638769694.png

2067976770.png

源码:https://gitee.com/52itstyle/easy-pay

地址:https://pay.cloudbed.vip

爪哇笔记
6359488940289160158582279.gif

作者: 小柒

出处: https://blog.52itstyle.vip

分享是快乐的,也见证了个人成长历程,文章大多都是工作经验总结以及平时学习积累,基于自身认知不足之处在所难免,也请大家指正,共同进步。

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 如有问题, 可邮件([email protected])咨询。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK