From 16bd0e17057df5616706ff9fa3ac706587364192 Mon Sep 17 00:00:00 2001 From: wxr <464027401@qq.com> Date: 星期二, 18 七月 2023 14:55:59 +0800 Subject: [PATCH] 告警推送,加密逻辑判断优化 --- Crabtree/ON/Aliyu/AliyuLogProducerClient.cs | 133 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 133 insertions(+), 0 deletions(-) diff --git a/Crabtree/ON/Aliyu/AliyuLogProducerClient.cs b/Crabtree/ON/Aliyu/AliyuLogProducerClient.cs new file mode 100644 index 0000000..2aa9a47 --- /dev/null +++ b/Crabtree/ON/Aliyu/AliyuLogProducerClient.cs @@ -0,0 +1,133 @@ +锘縰sing System; +using Android.Content; +using Com.Aliyun.Sls.Android.Producer; +using Java.IO; + +namespace HDL_ON_Android.Aliyu +{ + public class AliyuLogProducerClient : Java.Lang.Object, ILogProducerCallback + { + private static string TAG = "ProducerClient"; + LogProducerClient client = null; + private Context context; + protected string endpoint; + protected string logProject; + protected string logStore; + protected string accessKeyId; + protected string accessKeySecret; + protected string accessKeyToken; + protected string pluginAppId; + + public AliyuLogProducerClient(Context context, string endpoint, string logProject, string logStore, string accessKeyId, string accessKeySecret, string accessKeyToken, string pluginAppId) + { + this.context = context; + this.endpoint = endpoint; + this.logProject = logProject; + this.logStore = logStore; + this.accessKeyId = accessKeyId; + this.accessKeySecret = accessKeySecret; + this.accessKeyToken = accessKeyToken; + this.pluginAppId = pluginAppId; + } + + + public void initProducer() + { + try + { + // endpoint 蹇呴』鏄互 https:// 鎴� http:// 寮�澶寸殑閾炬帴 + string endpoint = this.endpoint; + string project = this.logProject; + string logstore = this.logStore; + string accessKeyId = this.accessKeyId; + string accessKeySecret = this.accessKeySecret; + string accessKeyToken = this.accessKeyToken; + + LogProducerConfig config = new LogProducerConfig(context, endpoint, project, logstore, accessKeyId, accessKeySecret, accessKeyToken); + // 璁剧疆涓婚 + config.SetTopic("test_topic"); + // 璁剧疆tag淇℃伅锛屾tag浼氶檮鍔犲湪姣忔潯鏃ュ織涓� + config.AddTag("test", "test_tag"); + // 姣忎釜缂撳瓨鐨勬棩蹇楀寘鐨勫ぇ灏忎笂闄愶紝鍙栧�间负1~5242880锛屽崟浣嶄负瀛楄妭銆傞粯璁や负1024 * 1024 + config.SetPacketLogBytes(1024 * 1024); + // 姣忎釜缂撳瓨鐨勬棩蹇楀寘涓寘鍚棩蹇楁暟閲忕殑鏈�澶у�硷紝鍙栧�间负1~4096锛岄粯璁や负1024 + config.SetPacketLogCount(1024); + // 琚紦瀛樻棩蹇楃殑鍙戦�佽秴鏃舵椂闂达紝濡傛灉缂撳瓨瓒呮椂锛屽垯浼氳绔嬪嵆鍙戦�侊紝鍗曚綅涓烘绉掞紝榛樿涓�3000 + config.SetPacketTimeout(3000); + // 鍗曚釜Producer Client瀹炰緥鍙互浣跨敤鐨勫唴瀛樼殑涓婇檺锛岃秴鍑虹紦瀛樻椂add_log鎺ュ彛浼氱珛鍗宠繑鍥炲け璐� + // 榛樿涓�64 * 1024 * 1024 + config.SetMaxBufferLimit(64 * 1024 * 1024); + // 鍙戦�佺嚎绋嬫暟锛岄粯璁や负1 + config.SetSendThreadCount(1); + + //缃戠粶杩炴帴瓒呮椂鏃堕棿锛屾暣鏁帮紝鍗曚綅绉掞紝榛樿涓�10 + config.SetConnectTimeoutSec(10); + //鏃ュ織鍙戦�佽秴鏃舵椂闂达紝鏁存暟锛屽崟浣嶇锛岄粯璁や负15 + config.SetSendTimeoutSec(10); + //flusher绾跨▼閿�姣佹渶澶х瓑寰呮椂闂达紝鏁存暟锛屽崟浣嶇锛岄粯璁や负1 + config.SetDestroyFlusherWaitSec(2); + //sender绾跨▼姹犻攢姣佹渶澶х瓑寰呮椂闂达紝鏁存暟锛屽崟浣嶇锛岄粯璁や负1 + config.SetDestroySenderWaitSec(2); + //鏁版嵁涓婁紶鏃剁殑鍘嬬缉绫诲瀷锛岄粯璁や负LZ4鍘嬬缉锛�0 涓嶅帇缂╋紝1 LZ4鍘嬬缉锛岄粯璁や负1 + config.SetCompressType(1); + //璁惧鏃堕棿涓庢爣鍑嗘椂闂翠箣宸紝鍊间负鏍囧噯鏃堕棿-璁惧鏃堕棿锛屼竴鑸绉嶆儏鍐电敤鎴峰鎴风璁惧鏃堕棿涓嶅悓姝ョ殑鍦烘櫙 + //鏁存暟锛屽崟浣嶇锛岄粯璁や负0锛涙瘮濡傚綋鍓嶈澶囨椂闂翠负1607064208, 鏍囧噯鏃堕棿涓�1607064308锛屽垯鍊艰缃负 1607064308 - 1607064208 = 10 + config.SetNtpTimeOffset(3); + //鏃ュ織鏃堕棿涓庢湰鏈烘椂闂翠箣宸紝瓒呰繃璇ュぇ灏忓悗浼氭牴鎹� `drop_delay_log` 閫夐」杩涜澶勭悊銆� + //涓�鑸绉嶆儏鍐靛彧浼氬湪璁剧疆persistent鐨勬儏鍐典笅鍑虹幇锛屽嵆璁惧涓嬬嚎鍚庯紝瓒呰繃鍑犲ぉ/鏁版湀鍚姩锛屽彂閫侀��鍑哄墠鏈彂鍑虹殑鏃ュ織 + //鏁存暟锛屽崟浣嶇锛岄粯璁や负7*24*3600锛屽嵆7澶� + config.SetMaxLogDelayTime(7 * 24 * 3600); + //瀵逛簬瓒呰繃 `max_log_delay_time` 鏃ュ織鐨勫鐞嗙瓥鐣� + //0 涓嶄涪寮冿紝鎶婃棩蹇楁椂闂翠慨鏀逛负褰撳墠鏃堕棿; 1 涓㈠純锛岄粯璁や负 1 锛堜涪寮冿級 + config.SetDropDelayLog(0); + //鏄惁涓㈠純閴存潈澶辫触鐨勬棩蹇楋紝0 涓嶄涪寮冿紝1涓㈠純 + //榛樿涓� 0锛屽嵆涓嶄涪寮� + config.SetDropUnauthorizedLog(0); + // 鏄惁浣跨敤涓荤嚎绋嬪洖璋� + // false: 浣跨敤涓荤嚎绋嬪洖璋冦�傚洖璋冧細鍦ㄤ富绾跨▼涓婃墽琛岋紝涓旀瘡涓� client 閮芥湁鑷繁鍗曠嫭鐨勫洖璋冦�� + // true: 浣跨敤 sender 绾跨▼鍥炶皟銆傚洖璋冧細鍦� sender 鐜板憟涓婃墽琛岋紝姣忔鎵ц鍥炶皟鏃堕兘浼� attach 涓�涓柊鐨� java 绾跨▼锛屾墍鏈� client 鍏辩敤涓�涓洖璋冦�� + // 娉ㄦ剰锛氶粯璁や娇鐢� sender 绾跨▼鍥炶皟銆� + config.SetCallbackFromSenderThread(false); + + /** + * 浠ヤ笅涓哄紑鍚柇鐐圭画浼犵殑閰嶇疆, 鎸夌収濡備笅閰嶇疆寮�鍚柇鐐圭画浼犲姛鑳藉悗, 鏃ュ織浼氬厛缂撳瓨鍒版湰鍦� + */ + // 1 寮�鍚柇鐐圭画浼犲姛鑳斤紝 0 鍏抽棴 + // 姣忔鍙戦�佸墠浼氭妸鏃ュ織淇濆瓨鍒版湰鍦扮殑binlog鏂囦欢锛屽彧鏈夊彂閫佹垚鍔熸墠浼氬垹闄わ紝淇濊瘉鏃ュ織涓婁紶At Least Once + config.SetPersistent(1); + // 鎸佷箙鍖栫殑鏂囦欢鍚嶏紝闇�瑕佷繚璇佹枃浠舵墍鍦ㄧ殑鏂囦欢澶瑰凡鍒涘缓銆� + // !!!!!!!!!!!!!!!!!!!娉ㄦ剰!!!!!!!!!!!!!!!!!!! + // 閰嶇疆澶氫釜瀹㈡埛绔椂锛屼笉搴旇缃浉鍚屾枃浠� + config.SetPersistentFilePath(context.FilesDir + string.Format("%slog_data.dat", File.Separator)); + // 鏄惁姣忔AddLog寮哄埗鍒锋柊锛岄珮鍙潬鎬у満鏅缓璁墦寮� + config.SetPersistentForceFlush(0); + // 鎸佷箙鍖栨枃浠舵粴鍔ㄤ釜鏁帮紝寤鸿璁剧疆鎴�10銆� + config.SetPersistentMaxFileCount(10); + // 姣忎釜鎸佷箙鍖栨枃浠剁殑澶у皬锛屽缓璁缃垚1-10M + config.SetPersistentMaxFileSize(1024 * 1024); + // 鏈湴鏈�澶氱紦瀛樼殑鏃ュ織鏁帮紝涓嶅缓璁秴杩�1M锛岄�氬父璁剧疆涓�65536鍗冲彲 + config.SetPersistentMaxLogCount(65536); + + client = new LogProducerClient(config, this); + } + catch (LogProducerException e) + { + + } + + } + public void sendLog(Log log) + { + LogProducerResult result = client.AddLog(log); + } + //callback涓哄彲閫夐厤缃�, 濡傛灉涓嶉渶瑕佸叧娉ㄦ棩蹇楃殑鍙戦�佹垚鍔熸垨澶辫触鐘舵��, 鍙互涓嶆敞鍐� callback + public void OnCall(int resultCode, string reqId, string errorMessage, int logBytes, int compressedBytes) + { + // // resultCode: 鐘舵�佺爜, 璇﹁ LogProducerResult + // // reqId: 璇锋眰Id, 宸茬粡搴熷純 + // // errorMessage: 澶辫触淇℃伅 + // // logBytes: 鏃ュ織鍘熷瀛楄妭鏁� + // // compressedBytes: 鏃ュ織鍘嬬缉瀛楄妭鏁� + } + } +} \ No newline at end of file -- Gitblit v1.8.0