Skip to content

Commit

Permalink
performancecounter: support yaml documents and tolerate collector err…
Browse files Browse the repository at this point in the history
…ors (#1809)

Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke authored Dec 9, 2024
1 parent a9698e2 commit eea5a50
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 89 deletions.
4 changes: 2 additions & 2 deletions .run/all.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<configuration default="false" name="all" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="run">
<module name="windows_exporter" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="--web.listen-address=127.0.0.1:9182 --log.level=info --collectors.enabled=ad,adcs,adfs,cache,container,cpu,cpu_info,cs,dfsr,dhcp,diskdrive,dns,exchange,filetime,fsrmquota,hyperv,iis,license,logical_disk,logon,memory,mscluster,msmq,mssql,net,netframework,nps,os,pagefile,performancecounter,physical_disk,printer,process,remote_fx,scheduled_task,service,smb,smbclient,smtp,system,tcp,terminal_services,thermalzone,time,udp,update,vmware --debug.enabled" />
<parameters value="--web.listen-address=127.0.0.1:9182 --log.level=info --collectors.enabled=ad,adcs,adfs,cache,container,cpu,cpu_info,cs,dfsr,dhcp,diskdrive,dns,exchange,filetime,fsrmquota,hyperv,iis,license,logical_disk,logon,memory,mscluster,msmq,mssql,net,netframework,nps,os,pagefile,performancecounter,physical_disk,printer,process,remote_fx,scheduled_task,service,smb,smbclient,smtp,system,tcp,terminal_services,thermalzone,time,udp,update,vmware,performancecounter --debug.enabled --collector.performancecounter.objects='[{ &quot;name&quot;: &quot;memory&quot;, &quot;object&quot;: &quot;Memory&quot;, &quot;counters&quot;: [{ &quot;name&quot;:&quot;Cache Faults/sc&quot;, &quot;type&quot;:&quot;counter&quot; }]}]'" />
<sudo value="true" />
<kind value="PACKAGE" />
<package value="github.com/prometheus-community/windows_exporter/cmd/windows_exporter" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/exporter.go" />
<method v="2" />
</configuration>
</component>
</component>
4 changes: 3 additions & 1 deletion cmd/windows_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ func run() int {
// Initialize collectors before loading
if err = collectors.Build(logger); err != nil {
for _, err := range utils.SplitError(err) {
logger.Warn("couldn't initialize collector",
logger.Error("couldn't initialize collector",
slog.Any("err", err),
)

return 1
}
}

Expand Down
9 changes: 8 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# example configuration file for windows_exporter

collectors:
enabled: cpu,cpu_info,exchange,iis,logical_disk,logon,memory,net,os,process,remote_fx,service,system,tcp,time,terminal_services,textfile
enabled: cpu,cpu_info,exchange,iis,logical_disk,logon,memory,net,os,performancecounter,process,remote_fx,service,system,tcp,time,terminal_services,textfile
collector:
service:
include: "windows_exporter"
performancecounter:
objects: |-
- name: memory
object: "Memory"
counters:
- name: "Cache Faults/sec"
type: "counter" # optional
log:
level: warn
47 changes: 43 additions & 4 deletions docs/collector.performancecounter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,28 @@ The performancecounter collector exposes any configured metric.

### `--collector.performancecounter.objects`

Objects is a list of objects to collect metrics from. The value takes the form of a JSON array of strings. YAML is also supported.
Objects is a list of objects to collect metrics from. The value takes the form of a JSON array of strings.
YAML is supported.

The collector supports only english named counter. Localized counter-names are not supported.
The collector supports only English-named counter. Localized counter-names aren’t supported.

> [!CAUTION]
> If you are using a configuration file, the value must be kept as a string.
>
> Use a `|-` to keep the value as a string.
#### Example

```yaml
collector:
performancecounter:
objects: |-
- name: memory
object: "Memory"
counters:
- name: "Cache Faults/sec"
type: "counter" # optional
```
#### Schema
Expand All @@ -25,7 +44,8 @@ YAML:
<summary>Click to expand YAML schema</summary>
```yaml
- object: "Processor Information"
- name: cpu # free text name
object: "Processor Information" # Performance counter object name
instances: ["*"]
instance_label: "core"
counters:
Expand All @@ -37,7 +57,8 @@ YAML:
metric: windows_performancecounter_processor_information_processor_time # optional
labels:
state: idle
- object: "Memory"
- name: memory
object: "Memory"
counters:
- name: "Cache Faults/sec"
type: "counter" # optional
Expand All @@ -51,6 +72,7 @@ YAML:
```json
[
{
"name": "cpu",
"object": "Processor Information",
"instances": [
"*"
Expand All @@ -74,6 +96,7 @@ YAML:
]
},
{
"name": "memory",
"object": "Memory",
"counters": [
{
Expand All @@ -86,6 +109,11 @@ YAML:
```
</details>

#### name

The name is used to identify the object in the logs and metrics.
Must unique across all objects.

#### object

ObjectName is the Object to query for, like Processor, DirectoryServices, LogicalDisk or similar.
Expand Down Expand Up @@ -186,6 +214,17 @@ windows_performancecounter_processor_information_processor_time{core="0,8",state
windows_performancecounter_processor_information_processor_time{core="0,9",state="active"} 1.0059484375e+11
windows_performancecounter_processor_information_processor_time{core="0,9",state="idle"} 10059.484375
```
> [!NOTE]
> If you are using a configuration file, the value must be keep as string.
Example:

```yaml
collector:
performancecounter:
objects: |
```
## Metrics
Expand Down
2 changes: 1 addition & 1 deletion internal/collector/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (c *Collector) collect(
slog.Any("err", err),
)
} else {
c.logger.Debug(fmt.Sprintf("mssql class collector %s for instance %s succeeded after %s.", collector, sqlInstance, duration))
c.logger.Debug(fmt.Sprintf("mssql class collector %s for instance %s succeeded after %s", collector, sqlInstance, duration))
}

ch <- prometheus.MustNewConstMetric(
Expand Down
Loading

0 comments on commit eea5a50

Please sign in to comment.