首页 文章 精选 留言 我的

精选列表

搜索[异常],共10000篇文章
优秀的个人博客,低调大师

Jni 读写sd卡报异常错误Permission denied

场景 红米Android5.0系统测试结果发现不支持写sd卡,因此通过Jni的方式访问sd卡的内容,在写数据的时候会出错。暂时没有解决方案,不过却可以在存储卡中进行读写。测试代码 #include <errno.h> #include <stdlib.h> #include <string.h> errno = 0; char szFileName[256] = "/storage/sdcard1/android/data/test.txt"; FILE* fileHandle= fopen(szFileName, "rb+"); if (NULL == fileHandle) { char* errMsg = NULL; if (errno !=0) { errMsg = strerror(errno); } } else { fseek(fileHandle,0L,SEEK_END); int flen=ftell(fileHandle); } 本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1601648,如需转载请自行联系原作者

优秀的个人博客,低调大师

异常检测之指数平滑(利用elasticsearch来实现)

打开微信扫一扫,关注微信公众号【数据与算法联盟】 转载请注明出处: http://blog.csdn.net/gamer_gyt 博主微博: http://weibo.com/234654758 Github: https://github.com/thinkgamer 指数平滑法是一种特殊的加权平均法,加权的特点是对离预测值较近的历史数据给予较大的权数,对离预测期较远的历史数据给予较小的权数,权数由近到远按指数规律递减,所以,这种预测方法被称为指数平滑法。它可分为一次指数平滑法、二次指数平滑法及更高次指数平滑法。 关于指数平滑的得相关资料: ES API接口: https://github.com/IBBD/IBBD.github.io/blob/master/elk/aggregations-pipeline.md https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movavg-aggregation.html 理论概念 http://blog.sina.com.cn/s/blog_4b9acb5201016nkd.html ES移动平均聚合:Moving Average的四种模型 simple 就是使用窗口内的值的和除于窗口值,通常窗口值越大,最后的结果越平滑: (a1 + a2 + … + an) / n curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg":{ "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "simple" } } } } } } ' 线性模型:Linear 对窗口内的值先做线性变换处理,再求平均:(a1 * 1 + a2 * 2 + … + an * n) / (1 + 2 + … + n) curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg": { "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "linear" } } } } } } ' 指数平滑模型 指数模型:EWMA (Exponentially Weighted) 即: 一次指数平滑模型 EWMA模型通常也成为单指数模型(single-exponential), 和线性模型的思路类似,离当前点越远的点,重要性越低,具体化为数值的指数下降,对应的参数是alpha。 alpha值越小,下降越慢。(估计是用1 - alpha去计算的)默认的alpha=0.3 计算模型:s2 = α * x2 + (1 - α) * s1 其中α是平滑系数,si是之前i个数据的平滑值,α取值为[0,1],越接近1,平滑后的值越接近当前时间的数据值,数据越不平滑,α越接近0,平滑后的值越接近前i个数据的平滑值,数据越平滑,α的值通常可以多尝试几次以达到最佳效果。 一次指数平滑算法进行预测的公式为:xi+h=si,其中i为当前最后的一个数据记录的坐标,亦即预测的时间序列为一条直线,不能反映时间序列的趋势和季节性。 curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg": { "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "ewma", "settings" : { "alpha" : 0.5 } } } } } } } ' 二次指数平滑模型: Holt-Linear 计算模型: s2 = α * x2 + (1 - α) * (s1 + t1) t2 = ß * (s2 - s1) + (1 - ß) * t1 默认alpha = 0.3 and beta = 0.1 二次指数平滑保留了趋势的信息,使得预测的时间序列可以包含之前数据的趋势。二次指数平滑的预测公式为 xi+h=si+hti 二次指数平滑的预测结果是一条斜的直线。 curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg": { "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "holt", "settings" : { "alpha" : 0.5, "beta" : 0.5 } } } } } } } ' 三次指数平滑模型:Holt-Winters无季节模型 三次指数平滑在二次指数平滑的基础上保留了季节性的信息,使得其可以预测带有季节性的时间序列。三次指数平滑添加了一个新的参数p来表示平滑后的趋势。 1: Additive Holt-Winters:Holt-Winters加法模型 下面是累加的三次指数平滑 si=α(xi-pi-k)+(1-α)(si-1+ti-1) ti=ß(si-si-1)+(1-ß)ti-1 pi=γ(xi-si)+(1-γ)pi-k 其中k为周期 累加三次指数平滑的预测公式为: xi+h=si+hti+pi-k+(h mod k) curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg": { "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "holt_winters", "settings" : { "type" : "add", "alpha" : 0.5, "beta" : 0.5, "gamma" : 0.5, "period" : 7 } } } } } } } ' 2: Multiplicative Holt-Winters:Holt-Winters乘法模型 下式为累乘的三次指数平滑: si=αxi/pi-k+(1-α)(si-1+ti-1) ti=ß(si-si-1)+(1-ß)ti-1 pi=γxi/si+(1-γ)pi-k 其中k为周期 累乘三次指数平滑的预测公式为: xi+h=(si+hti)pi-k+(h mod k) α,ß,γ的值都位于[0,1]之间,可以多试验几次以达到最佳效果。 s,t,p初始值的选取对于算法整体的影响不是特别大,通常的取值为s0=x0,t0=x1-x0,累加时p=0,累乘时p=1. curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg": { "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "holt_winters", "settings" : { "type" : "mult", "alpha" : 0.5, "beta" : 0.5, "gamma" : 0.5, "period" : 7, "pad" : true } } } } } } } ' 预测模型:Prediction 使用当前值减去前一个值,其实就是环比增长 curl -XPOST 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "aggs": { "my_date_histo":{ "date_histogram":{ "field":"date", "interval":"1M" }, "aggs":{ "the_sum":{ "sum":{ "field": "price" } }, "the_movavg": { "moving_avg":{ "buckets_path": "the_sum", "window" : 30, "model" : "simple", "predict" : 10 } } } } } } ' 最小化:Minimization 某些模型(EWMA,Holt-Linear,Holt-Winters)需要配置一个或多个参数。参数选择可能会非常棘手,有时不直观。此外,这些参数的小偏差有时会对输出移动平均线产生剧烈的影响。 出于这个原因,三个“可调”模型可以在算法上最小化。最小化是一个参数调整的过程,直到模型生成的预测与输出数据紧密匹配为止。最小化并不是完全防护的,并且可能容易过度配合,但是它往往比手动调整有更好的结果。 ewma和holt_linear默认情况下禁用最小化,而holt_winters默认启用最小化。 Holt-Winters最小化是最有用的,因为它有助于提高预测的准确性。 EWMA和Holt-Linear不是很好的预测指标,主要用于平滑数据,所以最小化对于这些模型来说不太有用。 通过最小化参数启用/禁用最小化:”minimize” : true 原始数据 数据为SSH login数据其中 IP/user已处理 { "_index": "logstash-sshlogin-others-success-2017-10", "_type": "sshlogin", "_id": "AV-weLF8c2nHCDojUbat", "_version": 2, "_score": 1, "_source": { "srcip": "222.221.238.162", "dstport": "", "pid": "20604", "program": "sshd", "message": "dwasw-ibb01:Oct 19 23:38:02 176.231.228.130 sshd[20604]: Accepted publickey for nmuser from 222.221.238.162 port 49484 ssh2", "type": "zsh-sshlogin", "ssh_type": "ssh_successful_login", "forwarded": "false", "manufacturer": "others", "IndexTime": "2017-10", "path": "/home/logstash/log/logstash_data/aaa/sshlogin/11.txt", "number": 1, "hostname": "116.241.218.120", "protocol": "ssh2", "@timestamp": "2017-10-19T15:38:02.000Z", "ssh_method": "publickey", "_hostname": "wq-ibb01", "@version": "1", "host": "localhost", "srcport": "49484", "dstip": "", "category": "sshlogin", "user": "nmuwser" } } 利用ES API接口去调用查询数据 “interval”: “hour”: hour为单位,这里可以是分钟,小时,天,周,月 “format”: “yyyy-MM-dd HH”: 聚合结果得日期格式 "the_sum": { "sum": { "field": "number" } } number为要聚合得字段 curl -POST 'localhost:9200/logstash-sshlogin-others-success-2017-10/sshlogin/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0, "query": { "term": { "ssh_type": "ssh_successful_login" } }, "aggs": { "hour_sum": { "date_histogram": { "field": "@timestamp", "interval": "hour", "format": "yyyy-MM-dd HH" }, "aggs": { "the_sum": { "sum": { "field": "number" } }, "the_movavg": { "moving_avg": { "buckets_path": "the_sum", "window": 30, "model": "holt", "settings": { "alpha": 0.5, "beta": 0.7 } } } } } } }' 得到的结果形式为: { "took" : 35, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "failed" : 0 }, "hits" : { "total" : 206821, "max_score" : 0.0, "hits" : [ ] }, "aggregations" : { "hour_sum" : { "buckets" : [ { "key_as_string" : "2017-09-30 16", "key" : 1506787200000, "doc_count" : 227, "the_sum" : { "value" : 227.0 } }, { "key_as_string" : "2017-09-30 17", "key" : 1506790800000, "doc_count" : 210, "the_sum" : { "value" : 210.0 }, "the_movavg" : { "value" : 113.5 } }, { "key_as_string" : "2017-09-30 18", "key" : 1506794400000, "doc_count" : 365, "the_sum" : { "value" : 365.0 }, "the_movavg" : { "value" : 210.0 } }, ... } } 对应得python代码(查询数据到画图) # coding: utf-8 from elasticsearch import Elasticsearch import matplotlib.pyplot as plt from matplotlib.font_manager import FontManager, FontProperties class Smooth: def __init__(self,index): self.es = Elasticsearch(['localhost:9200']) self.index = index # 处理mac中文编码错误 def getChineseFont(self): return FontProperties(fname='/System/Library/Fonts/PingFang.ttc') # 对index进行聚合 def agg(self): # "format": "yyyy-MM-dd HH:mm:SS" dsl = ''' { "size": 0, "query": { "term": { "ssh_type": "ssh_successful_login" } }, "aggs": { "hour_sum": { "date_histogram": { "field": "@timestamp", "interval": "day", "format": "dd" }, "aggs": { "the_sum": { "sum": { "field": "number" } }, "the_movavg": { "moving_avg": { "buckets_path": "the_sum", "window": 30, "model": "holt_winters", "settings": { "alpha": 0.5, "beta": 0.7 } } } } } } } ''' res = self.es.search(index=self.index, body=dsl) return res['aggregations']['hour_sum']['buckets'] # 画图 def draw(self): x,y_true,y_pred = [],[],[] for one in self.agg(): x.append(one['key_as_string']) y_true.append(one['the_sum']['value']) if 'the_movavg' in one.keys(): # 前几条数据没有 the_movavg 字段,故将真实值赋值给pred值 y_pred.append(one['the_movavg']['value']) else: y_pred.append(one['the_sum']['value']) x_line = range(len(x)) plt.figure(figsize=(10,5)) plt.plot(x_line,y_true,color="r") plt.plot(x_line,y_pred,color="g") plt.xlabel(u"每单位时间",fontproperties=self.getChineseFont()) #X轴标签 plt.xticks(range(len(x)), x) plt.ylabel(u"聚合结果",fontproperties=self.getChineseFont()) #Y轴标签 plt.title(u"10月份 SSH 主机登录成功聚合图",fontproperties=self.getChineseFont()) # 标题 plt.legend([u"True value",u"Predict value"]) plt.show() smooth = Smooth("logstash-sshlogin-others-success-2017-10") print smooth.draw() 结果图示为:

优秀的个人博客,低调大师

NDK 函数调用异常获取错误信息

场景说明: Android平台NDK调用iconv_open函数,实现UTF-8转GBK编码,没有达到预期的效果。尝试获取iconv_open函数失败的错误码。因为NDK的运行环境是Linux系统,所以尝试使用Linux获取错误码的机制,查看错误信息。 解决方案: 1)包含的头文件: #include <errno.h> #include <stdlib.h> #include <string.h> #include <stdio.h> 2)调用的情况: errno = 0;//避免其他的错误影响到本次函数执行结果的判断 iconv_t cd = iconv_open("GBK", "UTF-8"); char* message = NULL; if (errno != 0) { message = strerror(errno); } 基本原理:errno作为一个系统全局的变量,定义在errno.h文件中,会在函数调用出错的情况下设置,通过strerror函数返回错误的具体信息,当前测试的结果,错误码是22,错误信息:Invalid argument,如果errno等于0,消息是:success 参考网址:http://www.2cto.com/kf/201504/393638.html 本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1586412,如需转载请自行联系原作者

优秀的个人博客,低调大师

阿里云ECS发送邮件出现异常问题

org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.mxhichina.com:25 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1138) at org.apache.commons.mail.Email.send(Email.java:1163) ...... Caused by: javax.mail.MessagingException: 500 Error: bad syntax at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1363) at com.sun.mail.smtp.SMTPTransport.helo(SMTPTransport.java:838) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:375) at javax.mail.Service.connect(Service.java:297) at javax.mail.Service.connect(Service.java:156) at javax.mail.Service.connect(Service.java:105) at javax.mail.Transport.send0(Transport.java:168) at javax.mail.Transport.send(Transport.java:98) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1128) ... 46 more 原因 阿里云服务没有配置正确的host。执行命令: hostname -i 结果如果不是127.0.0.1 。如果不是那么, 解决办法: 首先在Linux命令行中查看 hostname #hostname xxxxxxxx //hostname 然后在/etc/hosts中添加一行 127.0.0.1 xxxxxxxx 即可解决问题。

优秀的个人博客,低调大师

异常message:There is no database named cloudera_manager_metastore_canary...

NoSuchObjectException(message:There is no database named cloudera_manager_metastore_canary_test_db_hive_hivemetastore_df61080e04cd7eb36c4336f71b5a8bc4) at org.apache.hadoop.hive.metastore.ObjectStore.getMDatabase(ObjectStore.java:495) at org.apache.hadoop.hive.metastore.ObjectStore.getDatabase(ObjectStore.java:506) at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.hadoop.hive.metastore.RawStoreProxy.invoke(RawStoreProxy.java:108) at com.sun.proxy.$Proxy0.getDatabase(Unknown Source) at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.get_database(HiveMetaStore.java:805) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:106) at com.sun.proxy.$Proxy5.get_database(Unknown Source) at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Processor$get_database.getResult(ThriftHiveMetastore.java:7696) at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Processor$get_database.getResult(ThriftHiveMetastore.java:7680) at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39) at org.apache.hadoop.hive.metastore.TUGIBasedProcessor$1.run(TUGIBasedProcessor.java:110) at org.apache.hadoop.hive.metastore.TUGIBasedProcessor$1.run(TUGIBasedProcessor.java:107) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1642) at org.apache.hadoop.hive.shims.HadoopShimsSecure.doAs(HadoopShimsSecure.java:502) at org.apache.hadoop.hive.metastore.TUGIBasedProcessor.process(TUGIBasedProcessor.java:118) at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:244) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) 原因: clouderamanager有一个对hive的健康检查叫 Hive Metastore Canary Health Test 引用资料: There is a known bug with the hive canary that may cause it to fail constantly - the client-configs we are using to connect to the hive metastore are partial. This may be the root cause of this failure. Do you have security enabled on the cluster? Did you change the hadoop.rpc.protection configuration option? A fix is going to be available very soon with the next release of cloudera manager (5.1,5.2,5.3) and hopefully it will solve the problem. In the meantime you can disable the hive metastore canary. 禁用 hive metastore canary. CM GUI --> Hive --> Configuration --> search for"metastore_canary_health_enabled" and uncheck(disabled). Save the setting and restart Hue,Oozie and Hive. 参考:https://groups.google.com/a/cloudera.org/forum/#!topic/scm-users/Ldt_GghQ7Rw

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册
修改密码
忘记密码