Prometheus基于java开发exporter样例以及pushgateway的应用

Prometheus学习系列(三十四)exporters和集成 有许多库和服务器可帮助从第三方系统导出现有指标作为Prometheus指标。 这对于无法直接使用Prometheus指标(例如,HAProxy或Linux系统统计信息)检测给定系统的情况非常有用。 一、第三方导出器 其中一些出口商作为普罗米修斯GitHub官方组织的一部分进行维护,这些出口商被标记为官方,其他出口商则由外部提供和维护。 我们鼓励创建更多出口商,但不能审查所有出口商的最佳做法。 通常... 阅读详情

目录

 

4种常用Metrics

Counter

Gauge

Histogram

Summary

基于SpringBoot写一个简单的exporter_demo

1.pom.xml配置如下

2.Application类注解

3.CounterDemo

4.GaugeDemo

5.HistogramDemo

6.SummaryDemo

7.关于pushgateway

参考文献


4种常用Metrics

Counter

连续增加不会减少的计数器,可以用于记录只增不减的类型,例如:网站访问人数,系统运行时间等。

对于Counter类型的指标,只包含一个inc()的方法,就是用于计数器+1.

一般而言,Counter类型的metric指标在冥冥中我们使用_total结束,如http_requests_total.

Gauge

可增可减的仪表盘,曲线图

对于这类可增可减的指标,用于反应应用的当前状态。

例如在监控主机时,主机当前空闲的内存大小,可用内存大小等等。

对于Gauge指标的对象则包含两个主要的方法inc()和dec(),用于增加和减少计数。

Histogram

主要用来统计数据的分布情况,这是一种特殊的metrics数据类型,代表的是一种近似的百分比估算数值,统计所有离散的指标数据在各个取值区段内的次数。例如:我们想统计一段时间内http请求响应小于0.005秒、小于0.01秒、小于0.025秒的数据分布情况。那么使用Histogram采集每一次http请求的时间,同时设置bucket。

Histogram会自动创建3个指标,分别为:
一、事件发生总次数: basename_count:
#实际含义: 当前一共发生了2次http请求
io_namespace_http_requests_latency_seconds_histogram_count{path="/",method="GET",code="200",} 2.0
二、所有事件产生值的大小的总和: basename_sum
#实际含义: 发生的2次http请求总的响应时间为13.107670803000001 秒
io_namespace_http_requests_latency_seconds_histogram_sum{path="/",method="GET",code="200",} 13.107670803000001
三、事件产生的值分布在bucket中的次数: basename_bucket{le="上包含"}
# 在总共2次请求当中。http请求响应时间 <=0.005 秒 的请求次数为0
io_namespace_http_requests_latency_seconds_histogram_bucket{path="/",method="GET",code="200",le="0.005",} 0.0
在总共2次请求当中。http请求响应时间 <=0.01 秒 的请求次数为0
io_namespace_http_requests_latency_seconds_histogram_bucket{path="/",method="GET",code="200",le="0.01",} 0.0
在总共2次请求当中。http请求响应时间 <=0.025 秒 的请求次数为0
io_namespace_http_requests_latency_seconds_histogram_bucket{path="/",method="GET",code="200",le="0.025",} 0.0

Summary

Summary和Histogram非常相似,都可以统计事件发生的次数或者大小,以及其分布情况,他们都提供了对时间的计数_count以及值的汇总_sum,也都提供了可以计算统计样本分布情况的功能,不同之处在于Histogram可以通过histogram_quantile函数在服务器计算分位数。而Sumamry的分位数则是直接在客户端进行定义的。因此对于分位数的计算,Summary在通过PromQL进行查询的时候有更好的性能表现,而Histogram则会消耗更多的资源,但是相对于客户端而言Histogram消耗的资源就更少。用哪个都行,根据实际场景自由调整即可。

基于SpringBoot写一个简单的exporter_demo

1.pom.xml配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.unicom</groupId>
	<artifactId>exporter-demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>exporter-demo</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.11.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>

        <!--普罗米修斯依赖-->
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_spring_boot</artifactId>
            <version>0.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_hotspot</artifactId>
            <version>0.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_servlet</artifactId>
            <version>0.4.0</version>
        </dependency>
		<dependency>
			<groupId>io.prometheus</groupId>
			<artifactId>simpleclient_pushgateway</artifactId>
			<version>0.4.0</version>
		</dependency>
        <!--springboot-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

4个prometheus的依赖包和两个pushgateway的依赖包。

2.Application类注解

@SpringBootApplication
@EnableScheduling
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class ExporterDemoApplication{

	public static void main(String[] args) {
		SpringApplication.run(ExporterDemoApplication.class, args);
	}
}

添加@EnableScheduling注解主要是添加了定时任务,用于动态模拟数据的变化,后面会看到应用的地方。

3.CounterDemo

定义一个Counter类型的metrics,一般而言,Counter类型的metrics指标在命名中我们使用_total结束。

@RestController
public class CounterDemo {
    /*
     *  使用Counter.build()创建Counter类型的监控指标,并且通过name()方法定义监控指标的名称network_traffic_input
     * ,通过labelNames()定义该指标包含的标签。最后通过register()将该指标注册到Collector的defaultRegistry中
     */
    static final Counter counterDemo = Counter.build()
            .name("counterChanger2").labelNames("wy","zxjr","ocs","xxjf","unit")
            .help("Counter 实例").register();
    //指标埋点,定时器会造成普罗米修斯与本地的数据时间戳不同步,尽量不要使用这种方式,实例中的定时器是为了数据演示
    @Scheduled(cron="0/5 * * * * ?")
    @RequestMapping("/changeCounter")
    public  void changeCounter(){
      counterDemo.labels("网元","在线接入","OCS","消息计费","seconds").inc();//指标值增加
  }
}

这里每5秒会自动执行changeCounter用于模拟数据的变化。

4.GaugeDemo

@RestController
public class GaugeDemo {
    /**指标注册
     * name设置指标名
     * labelNames设置各项指标名称
     * help设置指标描述
     */
    static final Gauge gaugeDemo = Gauge.build()
            .name("gaugeDemo")
            .labelNames("label1","label2","label3","label4","label5")
            .help("gauge 实例").register();

    //指标埋点
    @Scheduled(cron="0/5 * * * * ?")
    @RequestMapping("/changeGauge")
    public  void  changeGauge() {
        gaugeDemo.labels("1","2","3","4","5").inc(); //指标值加1
        gaugeDemo.labels("1","2","3","4","5").dec(); //指标值减一
        gaugeDemo.labels("1","2","3","4","5").set(19.00); //指标值直接赋值
    }
}

可以看到Gauge类型的metrics可以对数据进行增加、减小和直接赋值。这种类型在实际应用中比较多。

5.HistogramDemo

@RestController
public class HistogramDemo
{
    /**
     * 注册
     * 注册时buckets()设置区间值,如下设置了100、200、300三个区间值
     */
    static final Histogram histogramDemo = Histogram.build()
                                                    .labelNames("label1", "label2", "label3", "label4", "label5")
                                                    .name("histogramDemo")
                                                    .buckets(100, 200, 300)
                                                    .help("Histogram 实例")
                                                    .register();
    //指标埋点
    @Scheduled(cron = "0/5 * * * * ?") 
    public void changeHistogram()
    {
        /**
         * 本次执行的指标值
         * 如下设置为150,则每次执行,小于200区间以及小于300区间加1,小于100区间不变
         */
        histogramDemo.labels("1", "2", "3", "4", "5").observe(150);
    }
}

定义了三个区间,小于100,小于200,小于300,而changeHistogram中每次我们设置数据为150,所以最后画出来的曲线只有两条。

6.SummaryDemo

@RestController
public class SummaryDemo {
    //注册
    static final Summary summaryDemo = Summary.build()
            .quantile(0.5, 0.01)   // 添加50%分位数,允许有5%的误差,相当于求中位数
            .quantile(0.9, 0.01)   // 添加90%分位数,允许有1%的误差
            .name("summaryDemo").labelNames("label1","label2","label3","label4","label5")
            .help("Summary 实例").register();
    //指标埋点
    @Scheduled(cron="0/5 * * * * ?")
    public  void  changeSummary(){
        summaryDemo.labels("1","2","3","4","5").observe(1);
    }
}

在prometheus的Graph中通过查看summaryDemo、summaryDemo_count、summaryDemo_sum查看对应结果。

7.关于pushgateway

@Component
public class PrometheusConfig
{
    public static final Counter counterDemo = Counter.build()
                                                        .name("push_way_counter")
                                                        .labelNames("wy","zxjr","ocs","xxjf","unit","instance")
                                                        .help("Counter 实例")
                                                        .register();
    //测试发送
    public static void main(String[] args)
    {
        PushGateway prometheusPush = new PushGateway("localhost:9091");
        try
        {
            for(int i=0;i<50;i++){
                counterDemo.labels("网元","在线接入","OCS","消息计费","byte","localhsot:9091").inc();
                prometheusPush.push(counterDemo,"sp-getway");
                Thread.sleep(5000);
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

这里拿counter举一个简单的例子,其他三种度量也是一样的处理方式。

关于pushgateway中转数据,根据我自己实际的验证,我发现索然说数据每次都会先发送到pushgateway,但是prometheus去取的时候还是只取当前那一时间点的数据,并不会把历史的也拿过来,这让我很困惑,如果这样,他存的在意义是什么呢?不过也不确定是否因为我使用的不太对。

参考文献

【1】关于prometheus更详细的介绍

【2】更详细的介绍2

【3】关于metrics非常好的博文

【4】关于histogram_quantile的使用及Summary和Histogram对比

实战OpenTelemetry Trace:使用Java实现分布式跟踪 OpenTelemetry Trace是一种分布式跟踪技术,可以帮助开发者在复杂的应用程序中识别和解决问题。它允许开发者在跨越多个应用程序和服务的请求路径上跟踪请求,并提供有关这些请求的有用信息。OpenTelemetry Trace通过在请求路径上创建一系列跨度(Spans)来实现跟踪。每个跨度代表了请求路径上的一部分,可以包含一些有用的信息,例如跨度的起始时间和结束时间、跨度的标签等等。这些信息可以帮助开发者识别潜在的性能问题和故障。 阅读详情

相关推荐

从零开始了解Prometheus:核心组件与工作原理解析

Prometheus,一个强大的开源监控系统,因其高效的数据采集和查询能力而备受青睐。它的架构设计精巧,包含多个关键组件,每个组件都在整个系统中扮演着重要角色。本文将详细介绍Prometheus的主要组件,帮助初学者更好地理解其工作原理和应用场景。

HitTheHay的博客 2875

推送指标到pushgateway

prometheus采集方式: 1.prometheus pull方式采集服务指标 2.服务push指标到pushgateway服务,prometheus再去pull pushgateway服务指标官网地址: 例: 方式二:官网sdk: java\python\go 等以java为例子官网地址: 例: pom.xml java......

大唐响马的博客 2070

第 13 章 监控系统 | 实战案例 - Pushgateway 实战

了解 Pushgateway 系统,学会安装、配置,便于后续 job 推送指标。

甘蓝的专栏 530

Java项目通过pushgateway主动推送消息到Prometheus2.35

java调用pushgateway实现

3605

10、Prometheus 监控:指标推送、Exporter 与查询语言深度解析

本文深入解析了 Prometheus 的指标推送机制,重点介绍了 Pushgateway 在批处理作业监控中的应用及其部署配置方法。同时探讨了 JMX Exporter 和 HAProxy Exporter 等常用 Exporter 的使用场景与优缺点,帮助用户在非原生支持 Prometheus 的系统中实现指标采集。此外,文章还搭建了 PromQL 测试环境,讲解了其基础选择器的语法与工作原理,并提供了不同监控场景下的工具选择建议,全面提升了 Prometheus 在实际生产环境中的可操作性与灵活性。

nice1的博客 82

3台虚拟机部署Doris详细文档(含校验步骤)

摘要:本文详细介绍了Apache Doris在3台虚拟机上的集群部署方案。采用1主FE+1从FE+1观察者FE+3BE的混合部署模式,确保元数据高可用性。硬件配置建议测试环境4核16GB内存,生产环境8核64GB内存。部署步骤包括系统环境配置(关闭防火墙、内核参数优化)、FE/BE节点配置启动、集群初始化验证等。重点配置了IP白名单(172.30.0.115)和数据目录(/data/doris)。通过MySQL客户端和WebUI可监控集群状态,实现千万级数据的实时分析能力,后续可通过增加BE节点线性扩展。

weixin_41026747的博客 940

Prometheus部署Prometheus Server、Pushgateway、Node exporter、AlertManager

1.2 修改配置文件prometheus.yml 修改scrape_configs配置项后的内容如下: Prometheus可以在运行时动态加载配置的。启动时需要添加:。配置说明:global:控制Prometheus Server的全局配置rule_files:规则配置文件scrape_configs:配置采集目标相关。Prometheus可以通过HTTP(http://bigdata001:9090/metrics)采集自身的运行信息进行监控 启动时可以添加参数,修改Prometheus的端口等启动Pu

Bulut0907 1049

手把手教你用微信小程序实现智能硬件音视频通话(含Linux/RTOS适配)

本文详细介绍了如何利用微信小程序硬件框架(WMPF)和音视频SDK,在智能硬件(包括Linux与RTOS设备)上实现音视频通话功能。文章从架构设计、设备端SDK集成、小程序VOIP插件开发到跨平台调试与性能优化,提供了全链路实战指南,帮助开发者打通微信小程序与嵌入式设备间的实时音视频通信。

ooo22的博客 346

Prometheus 监控部署教程

Prometheus代理 : 负责采集和暂存数据,然后将数据转发给最终的Prometheus服务器service discovery 帮助自动发现存活的被监控主机**Prometheus Server:**负责定时去目标抓取 metrics数据,每个被抓取对象需要开放一个http服务接口;pull下来的数据经过整理后写入到本地的时序数据库(TSDB)中。

gsdgdg00的博客 2234

Vscode搭配Keil Assistant插件,头文件红色波浪线终极修复指南

本文详细解析了Vscode搭配Keil Assistant插件时出现头文件红色波浪线问题的根源,即ARMCC与ARMCLANG编译器的兼容性问题,并提供了三种实用解决方案:复制文件夹、创建符号链接和手动配置includePath,帮助开发者彻底修复错误,恢复代码跳转和自动补全功能。

q1w3e5r7t9y的博客 364

2024.12.29 【RNA-seq】Rawdata数据缺失问题与解决方案

Fastq格式是一种用于存储高通量测序数据的文件格式,包含序列和相应的质量信息。第一行以开头,后接序列标识符;第二行是测序的DNA序列;第三行以开头,可能会跟随序列标识符;第四行是对应的质量值,以ASCII字符表示。Rawdata的数据完整性通常情况下是没有问题的,但我们仍然需要对下机数据进行验证,确保后续分析的正常进行,好的分析习惯可以提高整体的分析效率,避免很多不必要的麻烦。

1120

Pushgateway的安装与使用

我们在使用Prometheus进行监控应用时,常常需要一些设备的指标进行监控,我们常用的方式为一些exporter进行监控。但是一些应用并没有exporter,这时我们就需要使用Pushgateway进行拉取数据,最后推送到Prometheus上。

m0_71239320的博客 2748

Windows Docker Desktop部署MaxKB详细教程

MaxKB(Max Knowledge Base)是一款基于大语言模型(LLM)和检索增强生成(RAG)技术的开源知识库问答系统,旨在帮助企业、教育机构及研究组织高效管理知识并提供智能问答服务。

猿小白的博客 1383

【prometheus】Pushgateway安装和使用

Pushgateway是prometheus的一个组件,prometheus server默认是通过exporter主动获取数据(默认采取pull拉取数据),pushgateway则是通过被动方式推送数据到prometheus server,用户可以写一些自定义的监控脚本把需要监控的数据发送给pushgateway, 然后pushgateway再把数据发送给Prometheus server。

2611_94945666的博客 173

[ 人力资源面试篇 ] HR 面试题分析详解大集合,看完直怼面试官(二)

那么在这个系列的文章中,我们聊到 HR 面谈什么?并且总结了五十个常见的人力资源面试题,在这里分享给大家。

qq_51577576的博客 1385

STM32实战开发(65):STM32摄像头图像采集开发教程

我们将会详细介绍如何使用STM32进行摄像头控制、图像数据采集以及如何将采集到的图像数据传输到其他设备进行处理。通过这篇博客,您将能够掌握STM32与摄像头模块的图像采集技术,应用于各种图像处理场景。为了确保STM32能够正确接收图像数据,我们需要配置STM32的GPIO引脚,并通过外部中断捕获这些信号。为了实现更高效的图像采集,可以通过DMA进行数据传输,将图像数据直接从GPIO引脚存储到内存中。通过DMA传输,我们可以将采集到的图像数据直接存储在内存中的一个缓冲区,然后进行后续的图像处理。

2201_76125393的博客 2544

【Prometheus 入门与进阶实践】02、Prometheus 基础概念(下)

Prometheus 基础概念介绍

GG Bond 的博客 1622

基于FPGA的7x7矩阵求逆verilog开发

up目录一、理论基础二、核心程序三、测试结果 矩阵求逆,即求矩阵的逆矩阵。矩阵是线性代数的主要内容,很多实际问题用矩阵的思想去解既简单又快捷。逆矩阵又是矩阵理论的很重要的内容,逆矩阵的求法自然也就成为线性代数研究的主要内容之一。设A是数域上的一个n阶方阵,若在相同数域上存在另一个n阶矩B,使得: AB=BA=E。 则我们称B是A的逆矩阵,而A则被称为可逆矩阵。其中,E为单位矩阵。典型的矩阵求逆方法有:利用定义求逆矩阵、初等变换法、伴随阵法、恒等变形法等。 逆矩阵的求法有多种,其中重要

FPGA/MATLAB学习教程/源码/项目合作开发 3903

java组件_java应用监控之prometheus核心组件

上一篇我们对prometheus做了一个简单的介绍,介绍了prometheus的优势以及和其他监控系统的对比,今天分享一下prometheus的核心组件。1、prometheus总体结构prometheus主要包含以下组件:prometheus server负责收集任务的管理、日志的存储、以及PromQL的支持。Alertmanager负责告警,可以灵活的设置告警规则。pushgateway,...

weixin_39787594的博客 349

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Prometheus应用监控

监控

xhpscdx的专栏 2253

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

性能监控之初识 Prometheus

文章目录一、概述二、监控的目标三、Prometheus 的优势四、Prometheus 的基本架构五、组件内容六、安装Prometheus Server1、从二进制包安装2、使用容器安装3、使用 Kubernetes Operator 安装3、小结 一、概述 Prometheus 是一套开源的监控、报警、时间序列数据库的组合,起始是由 SoundCloud 公司开发的,源于谷歌 borgmon。从 2016 年加入CNCF,2016 年 6 月正式发布 1.0 版本,2017 年底发布了基于全新存储层的 2

7DGroup,让技术更有价值! 1431

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Prometheus+Grafana+Telegraf+Consul+Alertmanager+Blackbox_exporter+Pushgateway运维监控平台组件介绍及RPM包构建(一)

本篇文章主要从当下主流监控prometheus+grafana出发,结合实际项目经验,从组件rpm包构建、安装部署、文件配置、告警采集、告警配置、告警发送、监控规则配置等多角度出发,构造出一个完全体的监控平台。上图为运维监控平台大纲,后续文章都会以该大纲为基础进行逐一实现该监控平台主要基于prometheus、alertmanager、blackbox_exporter、telegraf、consul等开源组件构建而成满足日常运维巡检、业务层面监控、服务器层面监控、应用层监控、容器化监控等功能。

菜鸟运维升级之路 1812

《Prometheus 官网》阅读笔记 简介篇

《Prometheus 官网》阅读笔记 简介篇

道友 644

Prometheus在SinoRepl监控的应用-SinoDB

1、Prometheus服务,可以直接通过目标拉取数据,或者间接地通过中间网关拉取数据。它在本地存储抓取的所有数据,并通过一定规则进行清理和整理数据,并把得到的结果存储到新的时间序列中,PromQL和其他API可视化地展示收集的数据。 2、Pushgateway是一个独立的服务,Pushgateway位于应用程序发送指标和Prometheus服务器之间。Pushgateway接收指标,然后将其作为目标被Prometheus服务器拉取。可以将其看作代理服务, 它接收度量,而不是探测它们。 3、A...

Sinoregal的博客 708

部署搭建 Prometheus 和 Grafana教程

本文介绍了在Ubuntu 22.04上使用Docker Compose部署Prometheus和Grafana监控系统的完整教程。主要内容包括:1) 安装Docker和Docker Compose;2) 配置Prometheus监控节点导出器(node-exporter)和容器监控工具(cAdvisor);3) 编写Docker Compose文件定义四个服务;4) 启动服务并验证访问;5) 在Grafana中添加Prometheus数据源并导入社区仪表盘模板;6) 额外提示如何设置Grafana中文界面。

天高云淡,望断南飞雁。不到长城非好汉,屈指行程二万。 六盘山上高峰,红旗漫卷西风。今日长缨在手,何时缚住苍龙 210

idea2020旗舰版没有java enterprise_java应用监控之prometheus核心组件

上一篇我们对prometheus做了一个简单的介绍,介绍了prometheus的优势以及和其他监控系统的对比,今天分享一下prometheus的核心组件。1、prometheus总体结构prometheus主要包含以下组件:prometheus server负责收集任务的管理、日志的存储、以及PromQL的支持。Alertmanager负责告警,可以灵活的设置告警规则。pushgateway,因为...

weixin_32098599的博客 151
上一篇: 虚拟机安装CentOS7网络突然失效的问题记录
下一篇: vue-cli引入bootstrap时候图标不显示
凉茶冰
博客等级 码龄17年 148粉丝 119原创
评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值