其他分享
首页 > 其他分享> > 阿里云日志服务SLS

阿里云日志服务SLS

作者:互联网

前言:

  刚入职实习了几天,我发现我的任务就是学习阿里云日志服务这块业务内容,这个功能和mysql一样,但是速度和视觉却是甩mysql这类数据库几条街。

  当得知公司没人会这项技术后(在这之前我也没听过,我觉得算是小众技术吧目前),我觉得我机会来了,可以考这项技术先站稳脚跟。。。

废话不多说,开始聊聊我这几天对这sls的感受。

 

SLS简介:

  日志服务:简称LOG,是针对日志类数据的一站式服务,在阿里巴巴集团经过大量大数据场景形成的,您无需开发就能快捷完成日志数据采集、消费、投递以及查询分析等功能,提升运维、运营效率,建立DT时代海量日志处理能力。

 

功能: 实时采集和消费。

    投递数仓。

    查询与实时分析。

 

案例详情:

  1、账单平均每天消费查询。

      查看平均每日的总消费,先用date_trunc 函数计算出每天的消费数,再用geometric_mean 函数得出平均每天的消费。

      

* | 
select 
  geometric_mean(total) as "每日平均消费日消费(元)" 
from 
  (
    select 
      date_trunc('day', __time__) as day, 
      sum(PretaxAmount) as total 
    from 
      log 
    group by 
      day 
    order by 
      day
  )

 

 

 2、访问前十地址。

* |
select
  count(1) as pv,
  split_part(request_uri, '?', 1) as path
group by
  path
order by
  pv desc
limit
  10

 

 

 3、tomcat错误请求数。

status >= 400 |
SELECT
  diff [1] AS c1,
  diff [2] AS c2,
  round(diff [1] * 100.0 / diff [2] - 100.0, 2) AS c3
FROM
  (
    select
      compare(c, 3600) AS diff
    from
      (
        select
          count(1) as c
        from
          log
      )
  )

 

 

 

                         4、top用户代理
* |
select
  http_user_agent as "用户代理",
  count(*) as pv,
  round(sum(request_length) / 1024.0 / 1024, 2) as "请求报文流量(MB)",
  round(sum(body_bytes_sent) / 1024.0 / 1024, 2) as "返回客户端流量(MB)",
  round(
    sum(
      case
        when status >= 200
        and status < 300 then 1
        else 0
      end
    ) * 100.0 / count(1),
    6
  ) as "2xx比例(%)",
  round(
    sum(
      case
        when status >= 300
        and status < 400 then 1
        else 0
      end
    ) * 100.0 / count(1),
    6
  ) as "3xx比例(%)",
  round(
    sum(
      case
        when status >= 400
        and status < 500 then 1
        else 0
      end
    ) * 100.0 / count(1),
    6
  ) as "4xx比例(%)",
  round(
    sum(
      case
        when status >= 500
        and status < 600 then 1
        else 0
      end
    ) * 100.0 / count(1),
    6
  ) as "5xx比例(%)"
group by
  "用户代理"
order by
  pv desc
limit
  100

 

 经过几个案例,其实sls的理解有稍微的加深,我觉得这可以当作一门语言来学。。。

标签:status,count,sum,SLS,100.0,阿里,日志,round,select
来源: https://www.cnblogs.com/loliconinvincible/p/13497650.html