NVIDIA GPU loadable plugin
Source
func (p *nvmlPlugin) Export(key string, rawParams []string, pluginCtx plugin.ContextProvider) (any, error) {
/*
** Zabbix
** Copyright (C) 2001-2024 Zabbix SIA
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**/
package plugin
import (
"context"
"time"
"golang.zabbix.com/plugin/nvidia/internal/plugin/handlers"
"golang.zabbix.com/plugin/nvidia/internal/plugin/params"
"golang.zabbix.com/plugin/nvidia/pkg/nvml"
"golang.zabbix.com/sdk/errs"
"golang.zabbix.com/sdk/metric"
"golang.zabbix.com/sdk/plugin"
"golang.zabbix.com/sdk/plugin/container"
"golang.zabbix.com/sdk/zbxerr"
)
// Name of the plugin.
const Name = "NVIDIA"
var (
_ plugin.Configurator = (*nvmlPlugin)(nil)
_ plugin.Exporter = (*nvmlPlugin)(nil)
_ plugin.Runner = (*nvmlPlugin)(nil)
)
type nvmlMetric struct {
metric *metric.Metric
handler handlers.HandlerFunc
}
type nvmlPlugin struct {
plugin.Base
config *pluginConfig
metrics map[string]*nvmlMetric
nvmlRunner nvml.Runner
}
// Launch launches the NVIDIA plugin. Blocks until plugin execution has
// finished.
func Launch() error {
runner, err := nvml.NewNVMLRunner()
if err != nil {
return errs.Wrap(err, "failed to create new nvml runner")
}
p := &nvmlPlugin{