阿里雲日誌服務SLS

  • 2020 年 8 月 13 日
  • 筆記

前言:

  剛入職實習了幾天,我發現我的任務就是學習阿里雲日誌服務這塊業務內容,這個功能和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的理解有稍微的加深,我覺得這可以當作一門語言來學。。。