clientset操作Service、ServiceMonitor、Endpoints

删除指定的Endpoints:

1
2
3
4
5
6
7
8
9
10
11
12
var grace int64 = 0
var clientset *kubernetes.Clientset
clientset, err = kubernetes.NewForConfig(util.GetKubeConfig())
if err != nil {
util.Logger.Error(err)
return err
}
if err = clientset.CoreV1().Endpoints(namespace).Delete(strings.ToLower(clusterName), &metav1.DeleteOptions{GracePeriodSeconds: &grace}); err != nil {
if !apierrors.IsNotFound(err) {
return err
}
}

删除指定的Service:

阅读更多

jinzhu版的gorm操作汇总

1、零值字段也更新

1
2
3
4
5
6
7
8
9
10
// gorm特性,当用struct更新时,里面的零值是不会被更新的,需要转换为map,这样零值也可被更新
hostsMap := structs.Map(&hosts)
// 更新集群相关信息,忽略对id字段的更新
dbUpdate := tx.Model(&hosts).Where("ip = ?", hosts.Ip).Omit("id").Updates(hostsMap)
if err = dbUpdate.Error; err != nil {
return err
}
if dbUpdate.RowsAffected == 0 {
return errors.New(fmt.Sprintf("Node ip [%s] was not exists.", ip))
}

阅读更多

基于commons-compress实现目录的tar.gz压缩与解压,支持8GB大文件

一、前言

直接复制代码就可以用,实现了格式为tar.gz的压缩格式,也可以实现8GB以上的大文件的压缩与解压,主要是在解压的逻辑中添加了:

1
2
3
4
// 可压缩大于8GB的文件
tOut.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
// 可压缩长名称文件
tOut.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

具体可参考:

二、pom依赖

阅读更多

java正则表达式

一、实战

1、通过正则表达式,获取想要的内容

  • ^:正则表达式开头
  • \w+\w表示任意一个字母或数字或下划线,也就是A~Z、a~z、0~9、_ 中任意一个,+表达式至少出现1次,相当于{1,}
  • \.:表示单纯的小数点
  • ?:表达式匹配0次或1次,相当于{0,1}
  • \d:任意一个数字,0~9中的任意一个
  • *:表达式不出现或出现任意次,相当于{0,}

阅读更多

Prometheus Operator介绍

参考资料:

一、Prometheus Operator能做什么

要了解Prometheus Operator能做什么,其实就是要了解Prometheus Operator为我们提供了哪些自定义的Kubernetes资源,列出了Prometheus Operator目前提供的️4类资源:

  • Prometheus:声明式创建和管理Prometheus Server实例;
  • ServiceMonitor:负责声明式的管理监控配置;
  • PrometheusRule:负责声明式的管理告警配置;
  • Alertmanager:声明式的创建和管理Alertmanager实例。

简言之,Prometheus Operator能够帮助用户自动化的创建以及管理Prometheus Server以及其相应的配置

prometheus-operator chart包地址:https://github.com/coreos/prometheus-operator.git

阅读更多

Prometheus Operator版本梳理及部署

https://github.com/prometheus-community/helm-charts

prometheus operator源码:https://github.com/prometheus-operator/prometheus-operator

kube prometheus yaml部署文件:https://github.com/prometheus-operator/kube-prometheus/tree/main/manifests,prometheus-operator的相关yaml文件在`manifests/setup`中。

基于Kube-Prometheus的manifests yaml文件,自己做的chart包:http://www.mydlq.club/article/10/

阅读更多

AlertManager配置文件详解

参考资料:

阅读更多

Prometheus相关问题记录

一、Prometheus内存消耗很大,大约10G

发现Prometheus每次拉取Elasticsearch Exporter指标,耗费时间很多,大约5秒,采集其他服务的exporter指标才几十毫秒。

通过请求http es exporter metrcis,发现接口返回的内容很多…再继续观察,发现该Elasticsearch集群索引数量竟高达3100多,大概问题的根源找到了,就是由于集群索引数量太多,导致Prometheus采集的指标几倍的增长。

阅读更多

golang web项目组件库汇总

库名 版本 描述
viper v1.9.0 初始化项目配置
nacos-sdk-go v1.0.9 初始化nacos配置
zap v1.19.1 初始化日志配置
jinzhu gorm v1.9.16 初始化mysql配置
gin v1.7.4 初始化web路由配置
validator web 请求参数校验
gin-swagger、swag v1.3.3、v1.7.6
封装response请求体
项目目录结构

阅读更多

Ambari安装hive服务,数据库Connection Failed

一、问题描述

因为写 ambari 相关的文章比较多,所以有很多使用 ambari 的朋友加我好友,发现有很多初学者都会卡在一个地方,就是安装依赖 mysql 的服务会提示:MYSQL Connection: Error ,像安装 hive、oozie、ranger 等等服务都会遇到这个问题。

本文以安装 hive 服务为示例,给大家演示下如何解决 MYSQL Connection: Error 问题。

阅读更多