新增86日志定时清理非当月索引脚本
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
|||||||
|
package com.fangjia.script.temp.shenjian.batch
|
||||||
|
|
||||||
|
import com.fangjia.script.BaseBatch
|
||||||
|
import com.fangjia.script.BatchOwner
|
||||||
|
import com.fangjia.script.Watcher
|
||||||
|
import org.apache.http.client.utils.DateUtils
|
||||||
|
|
||||||
|
import java.util.regex.Matcher
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只保留86机器最近一个月索引
|
||||||
|
*/
|
||||||
|
@BatchOwner(Watcher.ShenJian)
|
||||||
|
class RemoveOldIndexOfEs86 extends BaseBatch {
|
||||||
|
|
||||||
|
static void main(String[] args) {
|
||||||
|
runBatch(new RemoveOldIndexOfEs86(), args)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void process(Object args) {
|
||||||
|
String url = "http://192.168.0.86:9200/_cat/indices"
|
||||||
|
|
||||||
|
// 必须分开写,不能有空格
|
||||||
|
String[] cmds = ["curl", "-XGET", url, "--user", "elastic:goojia123456"]
|
||||||
|
List<List<String>> indices = execCurl(cmds)
|
||||||
|
Pattern yearMonthPattern = Pattern.compile("\\d{6}")
|
||||||
|
Pattern yearMonthPattern1 = Pattern.compile("\\d{4}\\.\\d{2}")
|
||||||
|
List<String> indexNeedDel = new ArrayList<>()
|
||||||
|
for (List<String> index : indices) {
|
||||||
|
String name = index.get(2)
|
||||||
|
// 忽略系统索引
|
||||||
|
if (name.startsWith(".")) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// 匹配含有年月的索引
|
||||||
|
Matcher matcher = yearMonthPattern.matcher(name)
|
||||||
|
if (matcher.find()) {
|
||||||
|
String date = matcher.group()
|
||||||
|
if (dateBeforeCurrMonth(date)) {
|
||||||
|
indexNeedDel.add(name)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
matcher = yearMonthPattern1.matcher(name)
|
||||||
|
if (matcher.find()) {
|
||||||
|
String date = matcher.group()
|
||||||
|
if (dateBeforeCurrMonth(date)) {
|
||||||
|
indexNeedDel.add(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String index : indexNeedDel) {
|
||||||
|
println "删除索引" + index
|
||||||
|
String urlPrefix = "http://192.168.0.86:9200/"
|
||||||
|
cmds = ["curl", "-XDELETE", urlPrefix + index, "--user", "elastic:goojia123456"]
|
||||||
|
execCurl(cmds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<List<String>> execCurl(String[] cmds) {
|
||||||
|
ProcessBuilder process = new ProcessBuilder(cmds)
|
||||||
|
Process p
|
||||||
|
try {
|
||||||
|
List<String> result = new ArrayList<>()
|
||||||
|
p = process.start()
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))
|
||||||
|
String line = null
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
result.add(line.split("{1} +"))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
def boolean dateBeforeCurrMonth(String date) {
|
||||||
|
String dateCurr = DateUtils.formatDate(new Date(), "yyyyMM");
|
||||||
|
if (date.contains(dateCurr)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
dateCurr = DateUtils.formatDate(new Date(), "yyyy.MM");
|
||||||
|
if (date.contains(dateCurr)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -22,7 +22,7 @@ import java.util.concurrent.Executors
|
|||||||
class SeaweedAroundCommittee {
|
class SeaweedAroundCommittee {
|
||||||
|
|
||||||
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
||||||
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
|
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
|
||||||
static ExecutorService executorService = Executors.newFixedThreadPool(30)
|
static ExecutorService executorService = Executors.newFixedThreadPool(30)
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.concurrent.Executors
|
|||||||
class SeaweedAroundPoi extends BaseBatch {
|
class SeaweedAroundPoi extends BaseBatch {
|
||||||
|
|
||||||
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
||||||
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
|
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
|
||||||
static ExecutorService executorService = Executors.newFixedThreadPool(30)
|
static ExecutorService executorService = Executors.newFixedThreadPool(30)
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.concurrent.Executors
|
|||||||
class SeaweedAroundPoiSingal {
|
class SeaweedAroundPoiSingal {
|
||||||
|
|
||||||
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
|
||||||
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
|
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
def types = listAllType()
|
def types = listAllType()
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ import org.apache.commons.collections.CollectionUtils
|
|||||||
*/
|
*/
|
||||||
class YinlianLngLatAndAround {
|
class YinlianLngLatAndAround {
|
||||||
|
|
||||||
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
|
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
|
||||||
|
|
||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
this.getAround()
|
this.getAround()
|
||||||
|
|||||||
Reference in New Issue
Block a user