{"id":20113563,"url":"https://github.com/cloudacademy/apache-prometheus-exporter","last_synced_at":"2025-03-02T18:45:13.069Z","repository":{"id":77791346,"uuid":"321798668","full_name":"cloudacademy/Apache-Prometheus-Exporter","owner":"cloudacademy","description":"This repo accompanies the Cloud Academy course on configuring a Prometheus exporter for an Apache webserver.","archived":false,"fork":false,"pushed_at":"2021-01-06T15:57:44.000Z","size":35,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T06:08:24.042Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloudacademy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-15T21:55:54.000Z","updated_at":"2025-01-06T20:15:51.000Z","dependencies_parsed_at":"2023-03-12T02:04:44.276Z","dependency_job_id":null,"html_url":"https://github.com/cloudacademy/Apache-Prometheus-Exporter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2FApache-Prometheus-Exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2FApache-Prometheus-Exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2FApache-Prometheus-Exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudacademy%2FApache-Prometheus-Exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudacademy","download_url":"https://codeload.github.com/cloudacademy/Apache-Prometheus-Exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241557118,"owners_count":19981877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T18:25:01.587Z","updated_at":"2025-03-02T18:45:13.048Z","avatar_url":"https://github.com/cloudacademy.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pre-Requisites\n\n- Kubectl set up \n- An active cluster to run Kubectl commands against\n\n## Versions this Repo was Ran on\n\nSingle Node Cluster\n- Kubectl Version 1.20\n- Minikube Version 1.16.0\n- Docker 20.10\n- Latest Prometheus Image\n- Latest Apache-Exporter Image\n- Version 1 Apache Image from Cloud Academy [Included in the deployment.yaml]\n## Docker Image\n\nA custom Docker image was created for this course, if you'd like to create it navigate to the docker folder and run:\n\n```\nsudo docker build . \n```\n\nAll docker images are provided for this course from CloudAcademy in the YAML files\n\n## Getting Started\n\nTo kick things off clone this repo and navigate to the directory:\n```\ngit clone https://github.com/cloudacademy/Apache-Prometheus-Exporter.git\ncd Apache-Prometheus-Exporter\n```\nAfter that we are going to create the services for our deployment:\n```\nkubectl create -f environment.yaml\n```\nSet the context:\n```\nkubectl config set-context --current --namespace prometheus\n```\nThe selectors from the environment.yaml will associate the deployment with the appropriate services and expose our microservices approriately.\n```\nkubectl create -f deployment.yaml\n```\nVerify we can see the deployment:\n```\nkubectl get po -w\n```\n(To stop watching the Pod creation, simply press Ctl-C)\n\nYou should see a deployment with three containers created no more than 20 seconds after the above command is ran.\nAfter we can see the pods, run the following command to get the IP of the deployment:\n```\nkubectl get po -o wide\n```\nPlace the IP provided there in the config.yaml file for prometheus to scrape against (If these are the only pods, it will likely be the 172.17.0.3 IP Address if you have no other pods running on a Minikube Cluster):\n```\n      global:\n        scrape_interval: 15s\n      scrape_configs:\n        - job_name: 'apache'\n          scrape_interval: 5s\n          static_configs:\n          - targets: ['{PLACE_THE_IP_ADDRESS_HERE}:9117']\n```\nCreate the configMap, delete the old deployment, and create the new deployment (Note: Wait for the old deployment to be removed before creating the new one, else the IP Address will be wrong in the configMap):\n\n```\nkubectl create -f config.yaml\nkubectl delete -f deploymentv1.yaml\n{Wait for deploymentv1 to be destroyed, it can take up to one minute}\nkubectl create -f deploymentv2.yaml\n```\n\n## After Prometheus is Started\n\n### Accessing our Prometheus Dashboard\n\nNow that our environment is setup with a proper Apache server, exporter, and a Prometheus server, we can access them to see their data.\n\nThe following command will output the Prometheus server URL (and open it for you if you have a browser open)\n```\nminikube service prom-service -n prometheus\n```\n\nNavigate to the URL provided and in the PromQL expression bar, begin typing 'apache' and you will receive a list of metrics to choose from.\nThere's also another way we can quickly check that the Apache exporter is working as well: through a simple curl to the Prometheus Server\n```\ncurl http://{URL_OF_PREVIOUS_COMMAND}/api/v1/label/job/values\n```\n\n### What if we wanted to see the metrics at the Apache Exporter itself? Instead of the Prometheus Server?\n\nLet's run a kubernetes pod with a curl container to curl the /metrics endpoint for the Apache webserver. This pod will run, curl the provided URL (replace the IP address below with your deployment/pod IP), then return the output to our terminal. The reason we have to run this within the cluster, is because we are not exposing the Apache exporter publicly, only through a ClusterIP. Lastly, we are piping the output to the more command in order to sift through the metrics easier.\n```\nkubectl run curl --image curlimages/curl -it --rm --restart=Never -- http://172.17.0.6:9117/metrics | more\n```\n\nPerfect! We now see our Apache exporter metrics outside of our Prometheus Server. \n\n### Generating some Metrics\n\nApache has a stress testing tool that we can use call 'ab' to test some connections to the server. Let's run that pod now with the similar commands previously used. This command will run 1000 requests with a concurrency of 20 (requests ran simultaenously). Ensure you replace the IP Address below with your Minikube IP and NodePort (minikube service apache -n prometheus):\n```\nk run ab --image jordi/ab --rm -it --restart=Never -- -n 1000 -c 20 http://192.168.99.109:30051/\n```\n\nNavigate back to the Prometheus Dashboard and check the apache metrics 'apache_cpuload' and notice the spike in traffic\n\n## Conclusions\n\nNow that you've got a working Prometheus Deployment complete with an Apache Webserver and Apache Exporter - Explore the environment! \n\nAnd when you're all done - Clean up the environment:\n\n```\nkubectl delete -f environment.yaml -f config.yaml -f deployment2.yaml\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudacademy%2Fapache-prometheus-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudacademy%2Fapache-prometheus-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudacademy%2Fapache-prometheus-exporter/lists"}