Skip to content

Commit

Permalink
Add server setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Jun 4, 2024
1 parent 02b27a4 commit a17e393
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
site/
*html
src/hosts/*png
22 changes: 16 additions & 6 deletions build.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
;;; package -- Build script for wmedrano.dev
;;; Commentary:
;;; Builds wmedrano.dev website by converting .org files into html.
;;; emacs -Q --script build.el
;;; Code:
(require 'ox-publish)

Expand All @@ -16,11 +17,11 @@ The static site is output into the site directory."
")
(org-html-link-up "../") ;; Unused. Required for home/up to render.
(org-publish-project-alist
`(("wmedrano-site" :components ("wmedrano-home" "wmedrano-posts"))
`(("wmedrano-site" :components ("wmedrano-home" "wmedrano-posts" "wmedrano-hosts"))
("wmedrano-home"
:base-directory "./src"
:publishing-directory "./src"
:publishing-function org-html-publish-to-html
:publishing-directory "./site"
:recursive nil
:exclude ".*"
:include ("index.org" "about.org")
Expand All @@ -30,19 +31,28 @@ The static site is output into the site directory."
)
("wmedrano-posts"
:base-directory "./src/posts"
:publishing-directory "./src/posts"
:publishing-function org-html-publish-to-html
:publishing-directory "./site/posts"
:recursive t
:auto-sitemap t
:section-numbers nil
:sitemap-title "Posts"
:sitemap-filename "index.org"
:html-link-home "../"
)))
)
("wmedrano-hosts"
:base-directory "./src/hosts"
:publishing-function org-html-publish-to-html
:publishing-directory "./src/hosts"
:recursive nil
:auto-sitemap t
:section-numbers t
:sitemap-title "Hosts"
:sitemap-filename "index.org"
:html-link-home "../")))
(org-html-head "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\"/>")
(org-html-validation-link nil))
(org-publish-project "wmedrano-site" t)
(copy-file "src/style.css" "site/style.css" t)))
(org-publish-project "wmedrano-site" t)))

(build-wmedrano-dev-site)

Expand Down
3 changes: 3 additions & 0 deletions src/hosts/index.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#+TITLE: Hosts

- [[file:oddtaxi.org][Odd Taxi]]
115 changes: 115 additions & 0 deletions src/hosts/oddtaxi.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#+TITLE: Odd Taxi
#+AUTHOR: Will S. Medrano

* Overview
:PROPERTIES:
:CUSTOM_ID: Overview-1nni0vb0x7k0
:END:

~oddtaxi~ is the main entry point to [[https://www.wmedrano.dev][wmedrano.dev]]. Requests from port
~80~ (http) and ~443~ (https) are intercepted by Caddy to either:

- Serve a static file.
- Reroute request to another job.

#+BEGIN_SRC dot :file oddtaxi.png
digraph oddtaxi {
node[shape=record];
blog -> caddy -> public_internet;
prometheus -> grafana -> caddy;
blog -> prometheus[style=dashed];
grafana -> prometheus[style=dashed];
prometheus -> prometheus[style=dashed];

blog[label="blog\n(static files)"];
prometheus[label="prometheus\n(metric collector)"];
grafana[label="grafana\n(prometheus frontend)"];
caddy[label="caddy\n(web server)"];
}
#+END_SRC

#+RESULTS:
[[file:oddtaxi.png]]

* Configs
:PROPERTIES:
:CUSTOM_ID: Configs-whg458d0x7k0
:END:

Caddy is the main entry point. It serves static files and redirects to
other ports.

** Caddy
:PROPERTIES:
:CUSTOM_ID: ConfigsCaddy-g8j458d0x7k0
:END:

#+BEGIN_SRC caddyfile :file /etc/caddy/Caddyfile :tangle yes
# Static files
wmedrano.dev {
root * /home/hiroshi/wmedrano.dev/src
file_server
}
www.wmedrano.dev {
root * /home/hiroshi/wmedrano.dev/src
file_server
}

# Grafana
status.wmedrano.dev {
reverse_proxy localhost:21895
}

# Serve Caddy prometheus metrics through localhost:21894.
:21894 {
metrics
}
#+END_SRC

** Prometheus
:PROPERTIES:
:CUSTOM_ID: ConfigsPrometheus-ywk458d0x7k0
:END:

Prometheus collects metrics from jobs that export a valid Prometheus
~/metrics~ endpoint. Prometheus itself has a basic UI for querying
time series of these metrics, but that job is better served by Grafana.

#+BEGIN_SRC yaml :file /etc/prometheus/prometheus.yml :tangle yes
global:
# Set the scrape interval to every 15 seconds. Default is every 1 minute.
scrape_interval: 15s
# Evaluate rules every 15 seconds. The default is every 1 minute.
evaluation_interval: 15s
external_labels:
monitor: 'oddtaxi'
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: node
static_configs:
- targets: ['localhost:9100']
- job_name: caddy
static_configs:
- targets: ['localhost:21894']
- job_name: grafana
static_configs:
- targets: ['localhost:21895']
#+END_SRC

** Grafana
:PROPERTIES:
:CUSTOM_ID: ConfigsGrafana-fwaaqbk0y7k0
:END:

Grafana is a GUI for Prometheus. It allows building dashboards based
on metrics collected from Prometheus.

#+BEGIN_SRC bash
sudo docker run -d -p 21895:3000 --name=grafana --restart unless-stopped grafana/grafana-enterprise
#+END_SRC
3 changes: 3 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ body {
padding: 1rem;
font-family: verdana, sans;
}
a {
text-decoration: none;
}

0 comments on commit a17e393

Please sign in to comment.