{"id":997,"date":"2022-08-16T13:10:36","date_gmt":"2022-08-16T11:10:36","guid":{"rendered":"https:\/\/alessandromasciadri.com\/?p=997"},"modified":"2022-08-16T13:14:54","modified_gmt":"2022-08-16T11:14:54","slug":"monitoring-script-per-container-docker","status":"publish","type":"post","link":"https:\/\/alessandromasciadri.com\/monitoring-script-per-container-docker\/","title":{"rendered":"Monitoring script per container Docker"},"content":{"rendered":"\t\t<div data-akihiro-type=\"ama-post\" data-akihiro-id=\"997\" class=\"akihiro akihiro-997\" data-akihiro-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"akihiro-section akihiro-top-section akihiro-element akihiro-element-e85fb87 akihiro-section-boxed akihiro-section-height-default akihiro-section-height-default\" data-id=\"e85fb87\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"akihiro-container akihiro-column-gap-default\">\n\t\t\t\t\t<div class=\"akihiro-column akihiro-col-100 akihiro-top-column akihiro-element akihiro-element-a7b165c\" data-id=\"a7b165c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"akihiro-widget-wrap akihiro-element-populated\">\n\t\t\t\t\t\t<div class=\"akihiro-element akihiro-element-af6feae akihiro-widget akihiro-widget-text-editor\" data-id=\"af6feae\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Se siamo alla ricerca di un modo per eseguire il monitoring dei container Docker possiamo affidarci a poche righe scritte in bash. L&#8217;esempio seguente non \u00e8 dei pi\u00f9 raffinati, ma \u00e8 un&#8217;ottima base di partenza per successive evoluzioni.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-4f39cd8 akihiro-widget akihiro-widget-heading\" data-id=\"4f39cd8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t<h3 class=\"akihiro-heading-title akihiro-size-default\">Script bash per il monitoring di container Docker<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-da921de akihiro-widget akihiro-widget-text-editor\" data-id=\"da921de\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Il seguente codice pu\u00f2 essere copiato ed eseguito as it is. Ricordarsi solo di cambiare il nome del container alla riga 28.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"akihiro-element akihiro-element-db8f45b akihiro-widget akihiro-widget-code-highlight\" data-id=\"db8f45b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"akihiro-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-okaidia copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>#!\/bin\/bash\n\necho \"---------------------------------------------------------\"\necho \"---------------DOCKER CONTAINER MONITORING---------------\"\necho \"---------------------------------------------------------\"\n\necho\n\nRED='\\033[0;31m'\nGREEN='\\033[0;32m'\nNOCOLOR='\\033[0m'\n\n#BEGIN TEST DOCKER STATE\nif docker info > \/dev\/null 2>&1; then\n\techo -e \"Docker service ---> [${GREEN}RUNNING${NOCOLOR}]\"\nelse\n  echo -e \"Docker service ---> [${RED}STOPPED${NOCOLOR}]\"\n  echo\n  echo \"Tentativo di ripristino del servizio Docker\"\n  echo \"Il sistema verr\u00e0 riavviato in 15 secondi\"\n  sleep 15\n  sudo reboot\n  exit 1\nfi\n#END TEST DOCKER STATE\n\n#BEGIN TEST CONTAINER RUNNING STATE\ncontainer_name=\"my-container-name\"\nsentinel=0\nif [ \"$( docker container inspect -f '{{.State.Status}}' $container_name )\" == \"running\" ];\nthen\n\techo -e \"$container_name ---> [${GREEN}RUNNING${NOCOLOR}]\"\nelif [ \"$( docker container inspect -f '{{.State.Status}}' $container_name )\" == \"restarting\" ];\nthen\n\techo -e \"$container_name ---> [${RED}RESTARTING${NOCOLOR}]\"\nelif [ \"$( docker container inspect -f '{{.State.Status}}' $container_name )\" == \"dead\" ];\nthen\n\techo -e \"$container_name ---> [${RED}DEAD${NOCOLOR}]\"\nelif [ \"$( docker container inspect -f '{{.State.Status}}' $container_name )\" == \"exited\" ];\nthen\n\techo -e \"$container_name ---> [${RED}EXITED${NOCOLOR}]\"\nelse\n\techo -e \"$container_name ---> [${RED}SERIOUSLY DAMAGED${NOCOLOR}]\"\nfi\n#END TEST CONTAINER RUNNING STATE<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Se siamo alla ricerca di un modo per eseguire il monitoring dei container Docker possiamo affidarci a poche righe scritte in bash. L&#8217;esempio seguente non \u00e8 dei pi\u00f9 raffinati, ma \u00e8 un&#8217;ottima base di partenza per successive evoluzioni. Script bash per il monitoring di container Docker Il seguente codice pu\u00f2 essere copiato ed eseguito as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[27,20,19],"class_list":["post-997","post","type-post","status-publish","format-standard","hentry","category-sistemistica","tag-docker","tag-linux","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/997","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/comments?post=997"}],"version-history":[{"count":8,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/997\/revisions"}],"predecessor-version":[{"id":1005,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/posts\/997\/revisions\/1005"}],"wp:attachment":[{"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/media?parent=997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/categories?post=997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alessandromasciadri.com\/ama-json\/wp\/v2\/tags?post=997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}