首页 文章 精选 留言 我的

精选列表

搜索[安全事件管理],共10000篇文章
优秀的个人博客,低调大师

阿里云容器Kubernetes监控(九) - Kubernetes事件离线工具kube-eventer正式开源

前言 监控是保障系统稳定性的重要组成部分,在Kubernetes开源生态中,资源类的监控工具与组件百花齐放。除了社区自己孵化的metrics-server,还有从CNCF毕业的Prometheus等等,开发者可选的方案有很多。但是,只有资源类的监控是远远不够的,因为资源监控存在如下两个主要的缺欠: 监控的实时性与准确性不足 大部分资源监控都是基于推或者拉的模式进行数据离线,因此通常数据是每隔一段时间采集一次,如果在时间间隔内出现一些毛刺或者异常,而在下一个采集点到达时恢复,大部分的采集系统会吞掉这个异常。而针对毛刺的场景,阶段的采集会自动削峰,从而造成准确性的降低。 监控的场景覆盖范围不足 部分监控场景是无法通过资源表述的,比如Pod的启动停止,是无法简单的用资源的利用率来计量的,因为当资源为0的时候,我们是不能区分这个状态产生的真实原因。

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

iOS:使用block代码块实现事件处理过程中的回调

block是什么,这里就不多加强调了,它的优点: 第一:执行效率高,速度快 第二:使用起来比代理简单,省却不少代码,增强代码美感 有一些小的知识点要强调一下: 第一点:它类似于一个匿名函数,也跟java中的匿名内部类相似,但是,记住,它是一种数据类型,因为它内部是一个结构体,有方法有属性,所以它具有对象的特征; 第二点:在类中声明block为属性时,如果使用assgin修饰,那么它被放到了栈中,方法已过就会被销毁,所以,尽量使用copy作为修饰词,这样一来block就被存放到了堆中,生命周期就会延长,保证block不会被立即销毁; 第三点:要防止循环引用,造成线程死锁,所以,有时需要加上__weak修饰。 第四点:为什么多用copy修饰,而不用strong修饰,这是MRC时期遗留下来的写法习惯,其实用strong也可以修饰,但是尽量用copy。 block既可以作为属性,单独赋值然后回调;也可以作为一个方法的参数使用,再进行回调,举例如下,直接代码演示: 我的例子过程大概是:首先用户浏览题库时,点击收藏按钮,弹出收藏界面,用户选择完某一个文件夹后,隐藏收藏界面,提示收藏成功! 例子一:block使用属性单独赋值后回调 这是收藏界面类的回调代码 #import <UIKit/UIKit.h> //声明block,用作选择收藏文件后的回调处理 typedef void (^CollectionBlock)(); //选择文件夹 typedef void (^CompleteHandleBlock)(); //选完之后的处理 @interface KJCollectionView : UITableView @property (copy,nonatomic)CollectionBlock collectionBlock; @property (copy,nonatomic)CompleteHandleBlock completeBlock; -(instancetype)initWithFrame:(CGRect)frame withFiles:(NSArray *)files; @end #import "KJCollectionView.h" #import "KJMyQueBankFile.h" @interface KJCollectionView()<UITableViewDataSource,UITableViewDelegate> @property (strong,nonatomic)NSArray *allFiles; @end @implementation KJCollectionView -(instancetype)initWithFrame:(CGRect)frame withFiles:(NSArray *)files { self = [super initWithFrame:frame]; if (self) { self.dataSource = self; self.delegate = self; self.tableHeaderView = [UILabel createLabel:CGRectMake(0, 0, SCREEN_WIDTH, 50) title:@"请选择收藏位置" titleColor:HMColor(13, 195, 176) alignmentType:NSTextAlignmentCenter size:16]; self.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; self.allFiles = [NSArray arrayWithArray:files]; MoveUnderLine(self); } return self; } #pragma mark - block回调,为block属性赋值 -(void)setCollectionBlock:(CollectionBlock)collectionBlock{ if (_collectionBlock != collectionBlock) { _collectionBlock = collectionBlock; } } -(void)setCompleteBlock:(CompleteHandleBlock)completeBlock{ if (_completeBlock != completeBlock) { _completeBlock = completeBlock; } } #pragma mark - UITableViewDataSource #pragma mark - Required -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.allFiles.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuseIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [[UITableViewCell alloc]init]; } cell.accessoryView = [UIButton createButton:CGRectMake(0, 0, 30, 30) imageName:@"default_true" target:self Done:@selector(chooseFileDone:)]; cell.imageView.image = [UIImage imageNamed:[self.allFiles[indexPath.row] file_image]]; cell.textLabel.text = [self.allFiles[indexPath.row] file_Name]; return cell; } #pragma mark - Optional - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 50; } #pragma mark - UITableViewDelegate #pragma mark - Optional - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryView = [UIButton createButton:CGRectMake(0, 0, 30, 30) imageName:@"selected_ture" target:nil Done:nil]; //回调处理 _collectionBlock(); _completeBlock(); } #pragma mark - 按钮选择文件夹 -(void)chooseFileDone:(UIButton *)btn{ UITableViewCell *cell = (UITableViewCell *)btn.superview; cell.accessoryView = [UIButton createButton:CGRectMake(0, 0, 30, 30) imageName:@"selected_ture" target:nil Done:nil]; //回调处理 _collectionBlock(); _completeBlock(); } @end 这是在题库类中给block传递回调处理的代码:直接通过属性赋值 #pragma mark - 点击收藏按钮时的代理方法 /** * 收藏作业 * @param indexPath 当前cell中选择按钮选中后的cell * @param btn 收藏按钮 * @param collectionTag 当前cell中收藏按钮的tag */ -(void)finishedClickedCollectionFileIndexPath:(NSIndexPath *)indexPath CollectionBtn:(UIButton *)btn{ //创建收藏文件夹视图和蒙版视图 self.collectionView = [[KJCollectionView alloc]initWithFrame:CGRectMake(0, 0, 260, 200) withFiles:self.filesArrayM]; self.collectionView.layer.cornerRadius = 3.0; self.collectionView.layer.masksToBounds = YES; self.collectionView.center = [UIApplication sharedApplication].keyWindow.center; self.coverView = [[UIView alloc]initWithFrame:self.view.bounds]; self.coverView.backgroundColor = HMColorRGBA(51, 51, 51, 0.3); [self.view addSubview:self.collectionView]; [self.view addSubview:self.coverView]; [self.view insertSubview:self.collectionView aboveSubview:self.coverView]; __weak typeof(self) weakSelf = self; //为选择文件的block赋值 self.collectionView.collectionBlock = ^(){ //取出收藏字典 KJChooseHomeworkDicM *checkBtnDicManager = [KJChooseHomeworkDicM sharedCheckBtnDicMManager]; [checkBtnDicManager.collectionDicM setObject:indexPath forKey:indexPath]; [btn setSelected:YES]; //获取作业模型 KJLog(@"clickedCollection:%@",[weakSelf.homeworkCellFrames[indexPath.row] defaultFH]); }; //为选完文件后的block赋值 self.collectionView.completeBlock = ^(){ [MBProgressHUD showSuccess:@"收藏成功"]; //移除收藏文件夹视图和蒙版视图 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.collectionView removeFromSuperview]; [weakSelf.coverView removeFromSuperview]; [weakSelf setCollectionView:nil]; [weakSelf setCoverView:nil]; }); }; } 例子二:block作为方法的参数赋值后再进行回调 这是收藏界面类的回调代码 #import <UIKit/UIKit.h> //声明block,用作选择收藏文件后的回调处理 typedef void (^CollectionBlock)(); //选择文件夹 typedef void (^CompleteHandleBlock)(); //选完之后的处理 @interface KJCollectionView : UITableView @property (copy,nonatomic)CollectionBlock collectionBlock; @property (copy,nonatomic)CompleteHandleBlock completeBlock; -(instancetype)initWithFrame:(CGRect)frame withFiles:(NSArray *)files; //声明一个方法 -(void)chooseFile:(CollectionBlock )collectionBlock compeleteChooseBlock:(CompleteHandleBlock)completeBlock; @end // Created by mac on 16/5/20. // Copyright © 2016年 mac. All rights reserved. #import "KJCollectionView.h" #import "KJMyQueBankFile.h" @interface KJCollectionView()<UITableViewDataSource,UITableViewDelegate> @property (strong,nonatomic)NSArray *allFiles; @end @implementation KJCollectionView -(instancetype)initWithFrame:(CGRect)frame withFiles:(NSArray *)files { self = [super initWithFrame:frame]; if (self) { self.dataSource = self; self.delegate = self; self.tableHeaderView = [UILabel createLabel:CGRectMake(0, 0, SCREEN_WIDTH, 50) title:@"请选择收藏位置" titleColor:HMColor(13, 195, 176) alignmentType:NSTextAlignmentCenter size:16]; self.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; self.allFiles = [NSArray arrayWithArray:files]; MoveUnderLine(self); } return self; } #pragma mark - block回调,通过方法为block属性赋值 -(void)chooseFile:(CollectionBlock )collectionBlock compeleteChooseBlock:(CompleteHandleBlock)completeBlock{ if (_collectionBlock != collectionBlock) { _collectionBlock = collectionBlock; } if (_completeBlock != completeBlock) { _completeBlock = completeBlock; } } #pragma mark - UITableViewDataSource #pragma mark - Required -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.allFiles.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *reuseIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier]; if (!cell) { cell = [[UITableViewCell alloc]init]; } cell.accessoryView = [UIButton createButton:CGRectMake(0, 0, 30, 30) imageName:@"default_true" target:self Done:@selector(chooseFileDone:)]; cell.imageView.image = [UIImage imageNamed:[self.allFiles[indexPath.row] file_image]]; cell.textLabel.text = [self.allFiles[indexPath.row] file_Name]; return cell; } #pragma mark - Optional - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 50; } #pragma mark - UITableViewDelegate #pragma mark - Optional - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.accessoryView = [UIButton createButton:CGRectMake(0, 0, 30, 30) imageName:@"selected_ture" target:nil Done:nil]; //回调处理 _collectionBlock(); _completeBlock(); } #pragma mark - 按钮选择文件夹 -(void)chooseFileDone:(UIButton *)btn{ UITableViewCell *cell = (UITableViewCell *)btn.superview; cell.accessoryView = [UIButton createButton:CGRectMake(0, 0, 30, 30) imageName:@"selected_ture" target:nil Done:nil]; //回调处理 _collectionBlock(); _completeBlock(); } @end 这是在题库类中给block传递回调处理的代码:直接将要赋值的block写入到方法中 #pragma mark - 点击收藏按钮时的代理方法 /** * 收藏作业 * @param indexPath 当前cell中选择按钮选中后的cell * @param btn 收藏按钮 * @param collectionTag 当前cell中收藏按钮的tag */ -(void)finishedClickedCollectionFileIndexPath:(NSIndexPath *)indexPath CollectionBtn:(UIButton *)btn{ //创建收藏文件夹视图和蒙版视图 self.collectionView = [[KJCollectionView alloc]initWithFrame:CGRectMake(0, 0, 260, 200) withFiles:self.filesArrayM]; self.collectionView.layer.cornerRadius = 3.0; self.collectionView.layer.masksToBounds = YES; self.collectionView.center = [UIApplication sharedApplication].keyWindow.center; self.coverView = [[UIView alloc]initWithFrame:self.view.bounds]; self.coverView.backgroundColor = HMColorRGBA(51, 51, 51, 0.3); [self.view addSubview:self.collectionView]; [self.view addSubview:self.coverView]; [self.view insertSubview:self.collectionView aboveSubview:self.coverView]; __weak typeof(self) weakSelf = self; //把block放入方法中 [self.collectionView chooseFile:^{ //取出收藏字典 KJChooseHomeworkDicM *checkBtnDicManager = [KJChooseHomeworkDicM sharedCheckBtnDicMManager]; [checkBtnDicManager.collectionDicM setObject:indexPath forKey:indexPath]; [btn setSelected:YES]; [MBProgressHUD showSuccess:@"收藏成功"]; //获取作业模型 KJLog(@"clickedCollection:%@",[weakSelf.homeworkCellFrames[indexPath.row] defaultFH]); } compeleteChooseBlock:^{ //移除收藏文件夹视图和蒙版视图 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [MBProgressHUD hideHUD]; [weakSelf.collectionView removeFromSuperview]; [weakSelf.coverView removeFromSuperview]; [weakSelf setCollectionView:nil]; [weakSelf setCoverView:nil]; }); }]; } 上面两种演示截图达到的效果是一样的: 点击题库中的收藏 选择文件夹收藏 显示收藏成功 移除文件夹视图 本人原创,转载须注明出处,谢谢! 程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式! 本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/5512618.html ,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

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

Rocky Linux

Rocky Linux

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

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册