如何使用 C API 调用线程安全 rrd_update_r 循环数据库函数?

发布于 2024-11-24 02:36:10 字数 1090 浏览 2 评论 0原文

任何人都可以帮我找出如何从 http:// 调用rrdtool c API 的rrd_update_r 函数/oss.oetiker.ch/rrdtool/index.en.html

调用非线程安全版本的rrd_update非常容易,但是这个版本更棘手...

普通rrd_update:

  char *updateparams[] = {
        "rrdupdate",
        rrd_file,
        values,
        NULL
    };

    rrd_clear_error();
    result = rrd_update(3, updateparams); //argc is first arg

因为程序必须在多线程环境中运行,所以我因不使用线程安全函数而出现了几个错误! 但使用rrd_update_r并不那么容易,因为它也需要一个模板...

 int    rrd_update_r(const char *filename, const char *_template,
            int argc, const char **argv);

而且我真的不知道如何创建一个...

    char *updateparams[] = {
        "rrdupdate",
        rrd_file,
        values,
        NULL
    };


    rrd_clear_error();
   result = rrd_update_r(rrd_file, NULL,3, updateparams);

不起作用并在执行时产生以下错误...

error: /var/tmp/rrds/1.rrd: expected timestamp not found in data source from rrdupdate

希望有人可以提供帮助我!

谢谢和br, 罗埃吉

Can anybody help me to find out how to call rrd_update_r function of the rrdtool c API from http://oss.oetiker.ch/rrdtool/index.en.html?

It was quite easy to call the non-threadsafe version of rrd_update, but this one is more tricky...

normal rrd_update:

  char *updateparams[] = {
        "rrdupdate",
        rrd_file,
        values,
        NULL
    };

    rrd_clear_error();
    result = rrd_update(3, updateparams); //argc is first arg

Because the programm has to run in a multithreaded environment I got several errors by not using the threadsafe functions!
But it is not so easy to use rrd_update_r, because it requires a template too...

 int    rrd_update_r(const char *filename, const char *_template,
            int argc, const char **argv);

and I really have no idea how to create one...

    char *updateparams[] = {
        "rrdupdate",
        rrd_file,
        values,
        NULL
    };


    rrd_clear_error();
   result = rrd_update_r(rrd_file, NULL,3, updateparams);

does not work and produces the following error when executing it...

error: /var/tmp/rrds/1.rrd: expected timestamp not found in data source from rrdupdate

Hopefully someone can help me!

thx and br,
roegi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风来 2024-12-01 02:36:10

好吧,看看源代码...

看来 rrd_update_r 不想看到 "rrupdate" 参数。因此,请尝试仅将 rrd_filevalues 作为 2 元素 argv 传递。

实际上rrd_update的源代码并不难读;你可以在 src/rrd_update.c 中找到它。 rrd_update_r 似乎是 rrd_update 本身调用的低级函数。所以这可能并不能真正解决你的根本问题。

Well, looking at the source code...

It appears that rrd_update_r does not want to see the "rrupdate" argument. So try just passing rrd_file and values as a 2-element argv.

Actually the source for rrd_update is not hard to read; you can find it in src/rrd_update.c. And rrd_update_r appears to be a much lower-level function that rrd_update itself calls. So this may not actually fix your underlying problem.

风透绣罗衣 2024-12-01 02:36:10

现在它正在工作!
尼莫 - 谢谢你的帮助!
这不完全是您的解决方案,但它是正确方向的提示!

它适用于:

/*
rrd_file is a char * to "/var/tmp/1.rrd"
NULL says not to use a template
1 --> argc 
values is a char * to "N:value-1:value-2:.....:value-n"
*/

result = rrd_update_r(rrd_file, NULL, 1, (void *) &values); 

Now it is working!
Nemo - thx for your help!
It was not exactly your solution but it was a hint to the right direction!

It works with:

/*
rrd_file is a char * to "/var/tmp/1.rrd"
NULL says not to use a template
1 --> argc 
values is a char * to "N:value-1:value-2:.....:value-n"
*/

result = rrd_update_r(rrd_file, NULL, 1, (void *) &values); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文