четверг, 26 ноября 2015 г.

Removing Old Elasticsearch Indexes on Widows with Jenkins

Here is simple solution, how you can free disk space on test/production servers, by removing old elasticsearch indexes through Jenkins job.


  1. Create new item.

  2. Fill all necessary date like job name and description and create build trigger. Here it is setup for running every night at 1:00
  3. In Build section select Windows PowerShell in "Add Build Step" and type following code, assuming you have index, that should be cleaned up, called "logstash-log-{date}". Substitute values ${HOST} and ${DAYS_TO_ROLL} with your host name and days that you want your indexes to be kept. For example, putting value "-10" in ${DAYS_TO_ROLL} will remove all indexes longer, than 10 days.
  4. $STAMP=(Get-Date).AddDays(${DAYS_TO_ROLL}).toString('yyyy.MM.dd')
    $LOGS_URL="http://${HOST}:9200/logstash-log-$STAMP"
    
    Write-Host "Going to delete: $LOGS_URL"
    Invoke-WebRequest $LOGS_URL -method DELETE
    



This will send DELETE request to elasticsearch http interface (port 9200) and delete indexes for selected day. As this script will run every night, you will always have history only for the last, for example, 10 days.

Комментариев нет:

Отправить комментарий