# Observability
Observability is typically done either with metrics containing time-based data points (telemetry), or with logging from the host, or both.

A good system should use both properly.  
## Metrics
For time-based metrics collection, we use a combination of host agents and Grafana to do the measurements and visualization.  
On each host that is measured, a local configuration declares what is exposed and shipped to the central metrics collection system.  
[Grafana Alloy](https://grafana.com/oss/alloy-opentelemetry-collector/) is installed on each host, and configured on a per-service level, meaning if the host serves webpages it will have an Alloy configuration to collect web server data.  
Relevant telemetry is derived from log entry data with [Grafana Loki](https://grafana.com/oss/loki/), meaning that log entries can be more fluid as not simply events, but also key-value pairs that represent a time-based data point of which can be measured.

#### Web Telemetry
For example, on each web server, we have `/etc/alloy/nginx.alloy`:
```
local.file_match "nginx" {
  path_targets = [{"__path__" = "/var/log/nginx/json_access.log"}]
  sync_period = "10s"
}

loki.source.file "nginx" {
  /*  targets = [
      {__path__ = "/tmp/foo.txt", "color" = "red"},
      {__path__ = "/tmp/bar.txt", "color" = "blue"},
      {__path__ = "/tmp/baz.txt", "color" = "green"},
  ] */
  /*  decompression {
    enabled             = true
    initial_delay       = "10s"
    format              = "gz"
  } */
  targets       = local.file_match.nginx.targets
  forward_to = [loki.relabel.nginx_labels.receiver]
  tail_from_end = true
}

loki.relabel "nginx_labels" {
  forward_to = [loki.write.nginx.receiver]
  rule {
    target_label = "service_name"
    replacement = "nginx"
  }
  rule {
    target_label = "instance"
    replacement = constants.hostname
  }
}

loki.write "nginx" {
  endpoint {
    url = "http://dashboard.cms.caltech.edu:3100/loki/api/v1/push"
  }
}
```
This does:
 - read NGINX logs already in the form of JSON, at `/var/log/nginx/json_access.log`
    - this presumes NGINX is writing logs in the JSON format
 - format the log entries for Grafana Loki
 - label entries from NGINX as coming from NGINX with the specific hostname
 - transmit each log entry to Loki running on http://dashboard.cms.caltech.edu

Grafana Loki will receive each formatted log entry and index metadata, categorizing data into key-value pairs, and making it available for further analysis.

This lets us trend the data over time, and produce graphs like this
{{Figure
|caption=Grafana Visual
|align=left
|width=55%
![](https://info-4.cms.caltech.edu/Sysadmin/Observability/Grafana%20Websites%20visual.png)
}}

Building visualizations and graphs isn't covered in this document, as it can get quite lengthy, but you can read all the documentation here:
https://grafana.com/grafana/dashboards/, or possibly even use a pre-built dashboard with some minor changes to get all the data to fit.

## Log Analysis
Grafana Loki can be used purely as a log analysis/search tool, but that is not generally its strength.  
For log searching, we use specific log analysis tools, [Wazuh](https://wazuh.com/platform/overview/) for security analysis, alerting, and active response.  For additional log searching, such as email troubleshooting, we use the free version of [Greylog](https://graylog.org/products/source-available/).

Each of these tools has its own web frontend, and mechanism of ingesting host system logs.

## NetApp Telemetry
NetApp created a handy measurement tool named [Harvest](https://netapp.github.io/harvest/26.11/) which lives near a NetApp device and collects metrics.  
Ours lives at `HARVEST-2.cms.caltech.edu`, and is a Proxmox LXC container, running Docker, running the NetApp Harvest Docker container.  
Yes, that's a lot, but this is a preferred method for running Docker containers in Proxmox.  
> [!Note]
> Proxmox can run either LXC containers, or Virtual Machines, but not really Docker containers.  
> Since NetApp harvest is not available as either LXC container or VM, we must employ a Docker container environment.  
See [[Virtualization|Sysadmin/Virtualization]]
The NetApp Harvest environment is self-contained, however it must execute inside a provided Docker environment, which typically demands root-level access unless a list of special things are done to bypass admin level privileges.  For this reason, we have a dedicated isolated environment specifically for running this Docker container, at `HARVEST-2`.  
On `HARVEST-2`, all the needed files for Docker and the Harvest app are located in `/opt/netapp-harvest`.  
Docker needs the `harvest-compose.yml` configuration file, and Harvest needs the `harvest.yml` configuration file.  
The data collection takes performance metrics, using the `netapp-harvest` user, and outputs to the Grafana dashboards for NetApp, with the most useful being  
*Home* → *Dashboards* → *NetApp* → *Harvest-main-cDOT* → *ONTAP:SVM*  
(You can favorite dashboards in Grafana, to make them easier to find later)  
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9