概述
freeswitch是一款简单好用的VOIP开源软交换平台。
如果对cdr话单要求不高,可以直接使用fs的原始话单文件,使用脚本做一些简单的统计。
环境
CentOS 7.9
freeswitch 1.10.7
docker
话单配置
修改conf/autoload_configs/cdr_csv.conf.xml文件如下。
<param name="legs" value="ab"/>
...
<template name="example">"${caller_id_name}","${caller_id_number}","${destination_number}","${context}","${start_stamp}","${progress_media_stamp}","${progress_stamp}","${answer_stamp}","${bridge_stamp}","${end_stamp}","${duration}","${billsec}","${hangup_cause}","${uuid}","${bleg_uuid}","${accountcode}","${read_codec}","${write_codec}","${direction}","${hangup_cause_q850}","${sip_hangup_disposition}","${proto_specific_hangup_cause}","${network_addr}","${rtp_audio_in_mos}","${180withsdp}","${sip_network_ip}","${sip_network_port}","${sip_local_network_addr}","${sofia_profile_name}"</template>
统计脚本
脚本文件直接放在cdr目录中log/cdr-csv/目录下。
脚本calculate_minutes.sh内容如下。
#!/bin/bash
# 输入文件路径
input_file="./cdr202408-answer-billsec-B.csv"
# 使用 awk 处理 CDR 文件
awk -F, 'BEGIN {total_cdr=0; total_minutes=0; total_6second=0} {
# 将 billsec 转换为计费分钟数
gsub(/"/, "", $12)
billsec = $12
fee_minutes = int((billsec + 59) / 60)
fee_6sec = int((billsec + 5) / 6)
# 累加所有行的分钟数
total_cdr += 1
total_minutes += fee_minutes
total_6second += fee_6sec
} END {print "Total cdr:", total_cdr, "\nTotal billed minutes:", total_minutes, "\nTotal 6 second:", total_6second}' "$input_file"
使用时修改input_file参数即可。
简单统计
进入log/cdr-csv/目录。
月度全量话单。
cat Master.csv.2024-08-* > cdr202408.csv
月度的接通话单。
awk -F, '($8 != "\"\"") {print}' cdr202408.csv > cdr202408-answer.csv
检查billsec为0的接通话单。
awk -F, '($8 != "\"\"" && $12 == "\"0\"") {print}' cdr202408-answer.csv
对billsec为0的接通话单修正为1。
awk -F, 'BEGIN {OFS=FS} {if ($12 == "\"0\"") $12 = "\"1\""; print}' cdr202408-answer.csv > cdr202408-answer-billsec.csv
过滤B路话单。
grep "outbound" cdr202408-answer-billsec.csv > cdr202408-answer-billsec-B.csv
统计计费分钟数,统计计费6秒数。
bash calculate_minutes.sh
Total cdr: 31119
Total billed minutes: 33403
Total 6 second: 90851
总结
fs暂时没发现有内置的话单统计和报表模块。自己实现吧。
空空如常
求真得真
标签:话单,total,处理,cdr202408,的话,cdr,freeswitch,billsec,csv From: https://www.cnblogs.com/qiuzhendezhen/p/18502983