企业级的 UI 设计语言和 React 实现 Ant Design
授权协议: MIT 开发语言: JavaScript HTML/CSS 操作系统: 跨平台 开发厂商:阿里巴巴 收录时间: 2015-07-27 提 交 者:叶秀兰 Ant Design 是蚂蚁金服开发和正在使用的一套企业级的前端设计语言和基于 React 的前端框架实现。 特性 企业级金融产品的交互语言和视觉体系。 丰富实用的 React UI 组件。 基于 React 的组件化开发模式。 背靠 npm 生态圈。 基于 webpack 的调试构建方案,支持 ES6。 示例
|
1 2 3 4 |
<span class="hljs-keyword">var</span> antd = <span class="hljs-built_in">require</span>(<span class="hljs-string">'antd'</span>); <span class="hljs-keyword">var</span> Datepicker = antd.Datepicker; React.render(<span class="xml"><span class="hljs-tag"><<span class="hljs-name">Datepicker</span> /></span>, mountNode);</span> |
开发说明 本地调试
|
1 |
<span class="hljs-meta">$</span><span class="bash"> npm start</span> |
然后访问 http://127.0.0.1:8000 。 网站部署
|
1 |
<span class="hljs-meta">$</span><span class="bash"> npm run deploy</span> |
版本构建
|
1 |
<span class="hljs-meta">$</span><span class="bash"> npm run release</span> |
from:https://www.oschina.net/p/ant-design
View Details8分钟学会使用AutoMapper
一.什么是AutoMapper与为什么用它。 它是一种对象与对象之间的映射器,让AutoMapper有意思的就是在于它提供了一些将类型A映射到类型B这种无聊的实例,只要B遵循AutoMapper已经建立的惯例,那么大多数情况下就可以进行相互映射了。 二.如何使用? 直接nuget install-package automapper 简单到不能再简单了。 三.入门 定义了连个简单的Model:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Destination { public string name { get; set; } public string InfoUrl { get; set; } } public class Source { public string name { get; set; } public string InfoUrl { get; set; } public string aa { get; set; } } |
|
1 2 3 4 5 6 7 8 9 10 11 |
static void Main(string[] args) { Destination des = new Destination() { InfoUrl = "www.cnblogs.com/zaranet", name = "张子浩" }; Mapper.Initialize(x => x.CreateMap<Destination, Source>()); Source source = AutoMapper.Mapper.Map<Source>(des); Console.WriteLine(source.InfoUrl); } |
Initialize方法是Mapper的初始化,里面可以写上CreateMap表达式,具体是谁和谁进行匹配。在之后就可以直接进行一个获取值的过程了,非常的简单。 四.映射前后操作 偶尔有的时候你可能需要在映射的过程中,你需要执行一些逻辑,这是非常常见的事情,所以AutoMapper给我们提供了BeforeMap和AfterMap两个函数。
|
1 2 3 |
Mapper.Initialize(x => x.CreateMap<Destination, Source>().BeforeMap( (src,dest)=>src.InfoUrl ="https://"+src.InfoUrl).AfterMap( (src,dest)=>src.name="真棒"+src.name)); |
其中呢,src是Destination对象,dest是Source,你呢就可以用这两个对象去获取里面的值,说白了这就是循环去找里面的值了。 五.条件映射
|
1 |
Mapper.Initialize(x => x.CreateMap<Destination, Source>().ForMember(dest => dest.InfoUrl,opt => opt.Condition(dest => dest.InfoUrl == "www.cnblogs.com/zaranet1")).ForMember(...(.ForMember(...)))); |
在条件映射中,通过ForMember函数,参数是一个委托类型Fun<>,其里面呢也是可以进行嵌套的,但一般来说一个就够用了。 六.AutoMapper配置 初始化配置是非常受欢迎的,每个领域都应该配置一次。
|
1 2 3 4 5 |
//初始化配置文件 Mapper.Initialize(cfg => { cfg.CreateMap<Aliens, Person>(); }); |
但是像这种情况呢,如果是多个映射,那么我们只能用Profile来配置,组织你的映射配置,并将配置放置到构造函数中(这种情况是5.x以上的版本),一个是以下的版本,已经被淘汰了。 5.0及以上版本:
|
1 2 3 4 5 6 7 |
public class AliensPersonProfile : Profile { public AliensPersonProfile() { CreateMap<Destination, Source>(); } } |
5.0以下版本(在早期版本中,使用配置方法而不是构造函数。 从版本5开始,Configure()已经过时。 它将在6.0中被删除。)
|
1 2 3 4 5 6 7 |
public class OrganizationProfile : Profile { protected override void Configure() { CreateMap<Foo, FooDto>(); } } |
然后在程序启动的时候初始化即可。
|
1 |
Mapper.Initialize(x=>x.AddProfile<AliensPersonProfile>()); |
七.AutoMapper的最佳实践 上文中已经说到了AutoMapper的简单映射,但是在实际项目中,我们应该有很多类进行映射,这么多的映射应该怎么组织,这是一个活生生的问题,这成为主映射器。 在主映射器中,组织了多个小映射器,Configuration为我们的静态配置入口类;Profiles文件夹为我们所有Profile类的文件夹。如果是MVC,我们需要在Global中调用,那我的这个是控制台的。
|
1 2 3 4 5 6 7 8 |
public static void Configure() { Mapper.Initialize(cfg => { cfg.AddProfile<DestinationSourceProfile>(); cfg.AddProfile(new StudentSourceProfile()); }); } |
其中添加子映射,可以用以上两种方式。
|
1 2 3 4 |
public void Configuration(IAppBuilder app) { AutoMapperConfiguration.Configure(); } |
八.指定映射字段 在实际业务环境中,你不可能说两个类的字段是一 一 对应的,这个时候我们就要对应它们的映射关系。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class CalendarEvent { public DateTime Date { get; set; } public string Title { get; set; } } public class CalendarEventForm { public DateTime EventDate { get; set; } public int EventHour { get; set; } public int EventMinute { get; set; } public string DisplayTitle { get; set; } } |
在这两个类中,CalendarEvent的Date将被拆分为CalendarEventForm的日期、时、分三个字段,Title也将对应DisplayTitle字段,那么相应的Profile定义如下:
|
1 2 3 4 5 6 7 8 9 10 11 |
public class CalendarEventProfile : Profile { public CalendarEventProfile() { CreateMap<CalendarEvent, CalendarEventForm>() .ForMember(dest => dest.EventDate, opt => opt.MapFrom(src => src.Date.Date)) .ForMember(dest => dest.EventHour, opt => opt.MapFrom(src => src.Date.Hour)) .ForMember(dest => dest.EventMinute, opt => opt.MapFrom(src => src.Date.Minute)) .ForMember(dest => dest.DisplayTitle, opt => opt.MapFrom(src => src.Title)); } } |
main方法通过依赖注入,开始映射过程,下图是代码和图。
|
1 2 3 4 5 6 7 8 9 10 11 |
static void Main(string[] args) { CalendarEvent calendar = new CalendarEvent() { Date = DateTime.Now, Title = "Demo Event" }; AutoMapperConfiguration.Configure(); CalendarEventForm calendarEventForm = Mapper.Map<CalendarEventForm>(calendar); Console.WriteLine(calendarEventForm); } |
那么最后呢,如果是反向的映射,一定回缺少属性,那么就你就可以obj.属性进行赋值。 附AutoHelper封装类
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
/// <summary> /// AutoMapper扩展帮助类 /// </summary> public static class AutoMapperHelper { /// <summary> /// 类型映射 /// </summary> public static T MapTo<T>(this object obj) { if (obj == null) return default(T); Mapper.CreateMap(obj.GetType(), typeof(T)); return Mapper.Map<T>(obj); } /// <summary> /// 集合列表类型映射 /// </summary> public static List<TDestination> MapToList<TDestination>(this IEnumerable source) { foreach (var first in source) { var type = first.GetType(); Mapper.CreateMap(type, typeof(TDestination)); break; } return Mapper.Map<List<TDestination>>(source); } /// <summary> /// 集合列表类型映射 /// </summary> public static List<TDestination> MapToList<TSource, TDestination>(this IEnumerable<TSource> source) { //IEnumerable<T> 类型需要创建元素的映射 Mapper.CreateMap<TSource, TDestination>(); return Mapper.Map<List<TDestination>>(source); } /// <summary> /// 类型映射 /// </summary> public static TDestination MapTo<TSource, TDestination>(this TSource source, TDestination destination) where TSource : class where TDestination : class { if (source == null) return destination; Mapper.CreateMap<TSource, TDestination>(); return Mapper.Map(source, destination); } /// <summary> /// DataReader映射 /// </summary> public static IEnumerable<T> DataReaderMapTo<T>(this IDataReader reader) { Mapper.Reset(); Mapper.CreateMap<IDataReader, IEnumerable<T>>(); return Mapper.Map<IDataReader, IEnumerable<T>>(reader); } } |
from:https://www.cnblogs.com/ZaraNet/p/10000311.html
View DetailsVS Code修改系统界面和编辑面板字体大小
描述 Linux下新安装的VS Code可能字体很小,包括系统字体(标题栏,工具栏、状态栏)和编辑面板的字体很小。 修改 Ctrl + Shitf + p,输入 settings,选择打开那个JSON的系统配置文件
|
1 2 3 4 |
{ "editor.fontSize": 15, "window.zoomLevel": 1.5 } |
修改这两个值即可,第一个是编辑面板的,第二个是系统界面的。 from:https://blog.csdn.net/chenbetter1996/article/details/85166528
View DetailsPowerDesigner导出word模版
模板下载1 模板下载2 解压至:C:\Program Files (x86)\Sybase\PowerDesigner 15\Resource Files\Report Templates 即可 感谢http://blog.csdn.net/ferry_passion/article/details/8948456的作者 from:https://www.cnblogs.com/live365wang/p/4968415.html
View DetailsReSharper2018破解详细方法
下载地址: 主程序官网下载链接:https://download.jetbrains.com/resharper/ReSharperUltimate.2018.3.3/JetBrains.ReSharperUltimate.2018.3.3.exe 2018.3.x破解补丁:https://files.cnblogs.com/files/simadi/Resharper2018.2Crack.7z 安装破解方法 1.先安装好Resharper; 2.下载完补丁后解压,以管理员身份运行Patch.cmd,如下图所示,即破解成功: 3.打开VS,打开ReSharper的注册窗口:ReSharper->Help->License Information… 4.剩余99999天,够你用200多年了吧! from:https://www.cnblogs.com/simadi/p/10412702.html
View Detailsis_uploaded_file总是返回false的问题
is_uploaded_file ile总是返回false,根据以下方法进行检查,全部检查通过。
|
1 2 3 4 5 6 |
1,是否通过http协议上传。 2,form中是否有 enctype="multipart/form-data"。 3,上传文件是否超出了规定的大小。 4,存放上传文件的文件夹是否存在,上传的文件夹是否具有写权限。 5,上传文件应该是使用move<span class="hljs-emphasis">_uploaded_</span>file()这个函数吧! 6,请确保$_FILES[<span class="hljs-string">"upload"</span>][<span class="hljs-symbol">'error'</span>] = 0; |
最后,找到一篇帖子, 将文件名用realpath函数过滤一下即可。
|
1 |
<span class="hljs-meta">is_uploaded_file(realpath($</span><span class="bash">file[<span class="hljs-string">'tmp_name'</span>]))</span> |
原文链接:http://www.xiumu.org/other/under-the-iis-is_uploaded_file-always-returns-false.shtml from:https://my.oschina.net/qii/blog/400692?p=1
View Detailsjava:bytes[]转long的三种方式
bytes[] 到数字类型的转换是个经常用到的代码,解决方式也不止一种,最近需要将bytes[]转为long,有机会深入了解了一下,此文做个总结。 java代码实现 如果不想借助任何已经有的类,完全可以自己实现这段代码,如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * 将字节数组转为long<br> * 如果input为null,或offset指定的剩余数组长度不足8字节则抛出异常 * @param input * @param offset 起始偏移量 * @param littleEndian 输入数组是否小端模式 * @return */ public static long longFrom8Bytes(byte[] input, int offset, boolean littleEndian){ long value=0; // 循环读取每个字节通过移位运算完成long的8个字节拼装 for(int count=0;count<8;++count){ int shift=(littleEndian?count:(7-count))<<3; value |=((long)0xff<< shift) & ((long)input[offset+count] << shift); } return value; } |
借助java.nio.ByteBuffer实现 java.nio.ByteBuffer 本身就有getLong,getInt,getFloat….方法,只要将byte[]转换为ByteBuffer就可以实现所有primitive类型的数据读取,参见javadoc。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * 利用 {@link java.nio.ByteBuffer}实现byte[]转long * @param input * @param offset * @param littleEndian 输入数组是否小端模式 * @return */ public static long bytesToLong(byte[] input, int offset, boolean littleEndian) { // 将byte[] 封装为 ByteBuffer ByteBuffer buffer = ByteBuffer.wrap(input,offset,8); if(littleEndian){ // ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN) // ByteBuffer 默认为大端(BIG_ENDIAN)模式 buffer.order(ByteOrder.LITTLE_ENDIAN); } return buffer.getLong(); } |
借助java.io.DataInputStream实现 java.io.DataInputStream 同样提供了readLong,readLong,readLong….方法,只要将byte[]转换为DataInputStream就可以实现所有primitive类型的数据读取,参见javadoc。 完整测试代码 下面的Junit 测试代码计算String 的MD5校验码(16 bytes),然后使用上述方式分别将16 bytes转换为2个long(大端模式)然后以16进制模式输出结果,以验证三种方式一致性。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
package net.gdface.facelog; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import org.junit.Test; public class TestSerialVersionUID { /** * 生成MD5校验码 * * @param source * @return */ static public byte[] getMD5(byte[] source) { if (null==source) return null; try { MessageDigest md = MessageDigest.getInstance("MD5"); return md.digest(source); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; } /** * 将16位byte[] 转换为32位的HEX格式的字符串String * * @param buffer * @return */ static public String toHex(byte buffer[]) { if (null==buffer) return null; StringBuffer sb = new StringBuffer(buffer.length * 2); for (int i = 0; i < buffer.length; i++) { sb.append(Character.forDigit((buffer[i] & 240) >> 4, 16)); sb.append(Character.forDigit(buffer[i] & 15, 16)); } return sb.toString(); } /** * 将字节数组转为long<br> * 如果input为null,或offset指定的剩余数组长度不足8字节则抛出异常 * @param input * @param offset 起始偏移量 * @param littleEndian 输入数组是否小端模式 * @return */ public static long longFrom8Bytes(byte[] input, int offset, boolean littleEndian){ if(offset <0 || offset+8>input.length) throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long",offset)); long value=0; for(int count=0;count<8;++count){ int shift=(littleEndian?count:(7-count))<<3; value |=((long)0xff<< shift) & ((long)input[offset+count] << shift); } return value; } /** * 利用 {@link java.nio.ByteBuffer}实现byte[]转long * @param input * @param offset * @param littleEndian 输入数组是否小端模式 * @return */ public static long bytesToLong(byte[] input, int offset, boolean littleEndian) { if(offset <0 || offset+8>input.length) throw new IllegalArgumentException(String.format("less than 8 bytes from index %d is insufficient for long",offset)); ByteBuffer buffer = ByteBuffer.wrap(input,offset,8); if(littleEndian){ // ByteBuffer.order(ByteOrder) 方法指定字节序,即大小端模式(BIG_ENDIAN/LITTLE_ENDIAN) // ByteBuffer 默认为大端(BIG_ENDIAN)模式 buffer.order(ByteOrder.LITTLE_ENDIAN); } return buffer.getLong(); } @Test public void test() throws IOException { String input="net.gdface.facelog.dborm.person.FlPersonBeanBase"; byte[] md5 = getMD5(input.getBytes()); System.out.printf("md5 [%s]\n",toHex(md5)); // 三种方式运算结果对比验证 DataInputStream dataInput = new DataInputStream(new ByteArrayInputStream(md5)); long l1 = dataInput.readLong(); long l2 = dataInput.readLong(); System.out.printf("l1=0x%x l2=0x%x,DataInputStream\n", l1,l2); long ln1 = bytesToLong(md5,0, false); long ln2 = bytesToLong(md5,8, false); System.out.printf("ln1=0x%x ln2=0x%x,ByteBuffer\n", ln1,ln2); long ll1 = longFrom8Bytes(md5,0, false); long ll2 = longFrom8Bytes(md5,8, false); System.out.printf("ll1=0x%x ll2=0x%x\n", ll1,ll2); } } |
输出结果 md5 [39627933ceeebf2740e1f822921f5837] l1=0x39627933ceeebf27 l2=0x40e1f822921f5837,DataInputStream ln1=0x39627933ceeebf27 ln2=0x40e1f822921f5837,,ByteBuffer ll1=0x39627933ceeebf27 ll2=0x40e1f822921f5837 参考资料 《Java 中 byte、byte 数组和 int、long 之间的转换》 from:https://blog.csdn.net/10km/article/details/77435659
View DetailsJava中四种线程安全的单例模式实现方式
第一种:饿汉模式(线程安全)
|
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Single2 { private static Single2 instance = new Single2(); private Single2(){ System.out.println("Single2: " + System.nanoTime()); } public static Single2 getInstance(){ return instance; } } |
第二种:懒汉模式 (如果方法没有synchronized,则线程不安全)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
public class Single3 { private static Single3 instance = null; private Single3(){ System.out.println("Single3: " + System.nanoTime()); } public static synchronized Single3 getInstance(){ if(instance == null){ instance = new Single3(); } return instance; } } |
第三种:懒汉模式改良版(线程安全,使用了double-check,即check-加锁-check,目的是为了减少同步的开销)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
public class Single4 { private volatile static Single4 instance = null; private Single4(){ System.out.println("Single4: " + System.nanoTime()); } public static Single4 getInstance(){ if(instance == null){ synchronized (Single4.class) { if(instance == null){ instance = new Single4(); } } } return instance; } } |
第四种:利用私有的内部工厂类(线程安全,内部类也可以换成内部接口,不过工厂类变量的作用域要改为public了。)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class Singleton { private Singleton(){ System.out.println("Singleton: " + System.nanoTime()); } public static Singleton getInstance(){ return SingletonFactory.singletonInstance; } private static class SingletonFactory{ private static Singleton singletonInstance = new Singleton(); } } |
from:https://my.oschina.net/yangchunlian/blog/1607947
View Details用 wait-notify 写一段代码来解决生产者-消费者问题
在同步块中调用 wait() 和 notify()方法,如果阻塞,通过循环来测试等待条件。请参考答案中的示例代码。 【生产者】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; public class Producer implements Runnable { private final Vector sharedQueue; private final int SIZE; public Producer(Vector sharedQueue, int size) { this.sharedQueue = sharedQueue; this.SIZE = size; } @Override public void run() { // 生产数据 for (int i = 0; i < 7; i++) { System.out.println("Produced:" + i); try { produce(i); } catch (InterruptedException ex) { Logger.getLogger(Producer.class.getName()).log(Level.SEVERE, null, ex); } } } private void produce(int i) throws InterruptedException { // wait if queue is full while (sharedQueue.size() == SIZE) { synchronized (sharedQueue) { System.out.println("Queue is full " + Thread.currentThread().getName() + " is waiting , size: " + sharedQueue.size()); sharedQueue.wait(); } } // producing element and notify consumers synchronized (sharedQueue) { sharedQueue.add(i); sharedQueue.notifyAll(); } } } |
【消费者】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; public class Consumer implements Runnable { private final Vector sharedQueue; private final int SIZE; public Consumer(Vector sharedQueue, int size) { this.sharedQueue = sharedQueue; this.SIZE = size; } @Override public void run() { // 消费数据 while (true) { try { System.out.println("Consumer: " + consume()); Thread.sleep(50); } catch (InterruptedException ex) { Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex); } } } private int consume() throws InterruptedException { // wait if queue is empty while (sharedQueue.isEmpty()) { synchronized (sharedQueue) { System.out.println("Queue is empty " + Thread.currentThread().getName() + " is waiting , size: " + sharedQueue.size()); sharedQueue.wait(); } } //otherwise consume element and notify waiting producer synchronized (sharedQueue) { sharedQueue.notifyAll(); return (Integer) sharedQueue.remove(0); } } } |
【测试函数】
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import java.util.Vector; public class ProducerConsumerSolution { public static void main(String[] args) { Vector sharedQueue = new Vector(); int size = 4; Thread prodThread = new Thread(new Producer(sharedQueue, size), "Producer"); Thread consThread = new Thread(new Consumer(sharedQueue, size), "Consumer"); prodThread.start(); consThread.start(); } } |
运行结果:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
Produced:0 Queue is empty Consumer is waiting , size: 0 Produced:1 Consumer: 0 Produced:2 Produced:3 Produced:4 Produced:5 Queue is full Producer is waiting , size: 4 Consumer: 1 Produced:6 Queue is full Producer is waiting , size: 4 Consumer: 2 Consumer: 3 Consumer: 4 Consumer: 5 Consumer: 6 Queue is empty Consumer is waiting , size: 0 |
from:https://www.cnblogs.com/xbq8080/p/10371214.html
View DetailsGrafana
1.概述--美观、强大的可视化监控指标展示工具 grafana 是一款采用 go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,是网络架构和应用分析中最流行的时序数据展示工具,目前已经支持绝大部分常用的时序数据库。最好的参考资料就是官网(http://docs.grafana.org/),虽然是英文,但是看多了就会啦。 1.1基本概念 Grafana支持许多不同的数据源。每个数据源都有一个特定的查询编辑器,该编辑器定制的特性和功能是公开的特定数据来源。 官方支持以下数据源:Graphite,Elasticsearch,InfluxDB,Prometheus,Cloudwatch,MySQL和OpenTSDB等。 每个数据源的查询语言和能力都是不同的。你可以把来自多个数据源的数据组合到一个仪表板,但每一个面板被绑定到一个特定的数据源,它就属于一个特定的组织。 支持的数据源 DashBoard:仪表盘,就像汽车仪表盘一样可以展示很多信息,包括车速,水箱温度等。Grafana的DashBoard就是以各种图形的方式来展示从Datasource拿到的数据。 Row:行,DashBoard的基本组成单元,一个DashBoard可以包含很多个row。一个row可以展示一种信息或者多种信息的组合,比如系统内存使用率,CPU五分钟及十分钟平均负载等。所以在一个DashBoard上可以集中展示很多内容。 Panel:面板,实际上就是row展示信息的方式,支持表格(table),列表(alert list),热图(Heatmap)等多种方式,具体可以去官网上查阅。 Query Editor:查询编辑器,用来指定获取哪一部分数据。类似于sql查询语句,比如你要在某个row里面展示test这张表的数据,那么Query Editor里面就可以写成select *from test。这只是一种比方,实际上每个DataSource获取数据的方式都不一样,所以写法也不一样(http://docs.grafana.org/features/datasources/),比如像zabbix,数据是以指定某个监控项的方式来获取的。 Organization:组织,org是一个很大的概念,每个用户可以拥有多个org,grafana有一个默认的main org。用户登录后可以在不同的org之间切换,前提是该用户拥有多个org。不同的org之间完全不一样,包括datasource,dashboard等都不一样。创建一个org就相当于开了一个全新的视图,所有的datasource,dashboard等都要再重新开始创建。 User:用户,这个概念应该很简单,不用多说。Grafana里面用户有三种角色admin,editor,viewer。admin权限最高,可以执行任何操作,包括创建用户,新增Datasource,创建DashBoard。editor角色不可以创建用户,不可以新增Datasource,可以创建DashBoard。viewer角色仅可以查看DashBoard。在2.1版本及之后新增了一种角色read only editor(只读编辑模式),这种模式允许用户修改DashBoard,但是不允许保存。每个user可以拥有多个organization。 dashboard界面最上面一行解释 界面顶部标题标注 上图显示了信息中心的顶部标题。 1侧面菜单切换:切换侧边菜单,允许您专注于仪表盘中显示的数据。侧面菜单提供对与仪表盘无关的功能(如用户,组织和数据源)的访问。 2信息中心下拉菜单:此下拉菜单显示您当前正在查看的信息中心,并允许您轻松切换到新的信息中心。从这里,您还可以创建新的信息中心,导入现有的信息中心和管理信息中心播放列表。 3星型仪表盘:对当前仪表盘执行星号(或取消星标)。加星标的信息中心在默认情况下会显示在您自己的主页信息中心上,并且是标记您感兴趣的信息中心的便捷方式。 4共享仪表盘:通过创建链接或创建其静态快照来共享当前仪表盘。在共享前确保信息中心已保存。 5保存仪表盘:当前仪表盘将与当前仪表盘名称一起保存。 6设置:管理仪表盘设置和功能,如模板和注释。 2.全面瓦解 对于grafana的部署,网上一搜一大把,这里不作累赘,可参考(grafana官网安装说明、grafana酷炫图表),继续以下内容。 2.1登录grafana 要运行Grafana,请打开浏览器并转到http://localhost:3000/,如果你尚未配置不同的端口,则3000是Grafana监听的默认http端口。默认用户名为admin,默认密码为admin。当你第一次登录时,系统会要求你更改密码,我们强烈建议你遵循Grafana的最佳做法并更改默认管理员密码,你可以稍后转到用户首选项并更改你的用户名。 登录界面,可看到版本号 2.2数据源配置 按照前面的数据源,这里讲解几个我们常使用的数据源的配置,包括es、opentsdb、influxdb和zabbix,也可以新增其他的数据源。 常用数据源示例 opentsdb数据源配置示例 其中关于Access这里具体解释下:Server (default) = 需要从Grafana后端/服务器访问,Browser = 需要从浏览器访问,对应上面的url。 es数据源配置示例 influxdb数据源配置示例 2.3仪表盘配置 在配置好所使用的数据源之后,即可新增配置自己的面板。面板也存在多种: 仪表盘 这里选取graph为例,如下图所示,新增或配置仪表盘。右上角的红框中表示:新建、标星、分享、保存、设置、查询模式、时间段、缩小(针对时间段进行放宽,即小时间段换成了大时间段)、刷新等 新增仪表盘或编辑已有仪表盘 Graph里面的选项有:General(常规选择)、Metrics(指标)、Axes(坐标轴)、Legend(图例)、 Display(显示样式)、Alert(告警)、Time range(时间范围) (1)General(常规选择:http://docs.grafana.org/features/panels/graph/) 常规选择 General允许定制面板的外观和菜单选项。 General Options Title:仪表盘上的面板标题 Description:仪表盘描述信息 Transparent :是否透明,选择之后会把该图的背景去掉,即透明状态 Repeat panel:是否重复panel,填写是重复的变量(参考后文3.2变量配置),即这个标题名中添加对应的变量,引用该变量需添加$,图标题即可随着自选的变量而变化。 钻取/详细信息链接 Drilldown / detail link(为当前panel增加超链接) Drilldown项允许在面板添加动态链接,可以链接到其他的dashboards或urls。 每个链接都有一个title,一个type和params。链接可以是dashboard,或是绝对链接。如果是dashboard链接,则dashboard值必须是仪表盘的名称。如果它是一个绝对链接,URL就是链接的URL。 params允许添加额外的URL参数的链接。格式是name=value,多种参数用&分隔。模板变量可以作为使用$ myVar作为值。 当连接到另一个Dashboard使用的模板变量,你可以使用var-myVar =value 填充模板变量所需的值从链接。 (2)Metrics(指标) metrics页签定义要呈现的系列数据和源。每个数据源提供不同的选择(参考官网)。这里以opentsdb数据源为例: 指标 Data Source:数据源,在前面配置好数据源之后,在这里直接选择对应的数据源 查询A、B:可以根据情况进行新增或删除 metric:指标名,输入部分指标名,会自动查询匹配,可以快速进行选择 […]
View Details